/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Private Member Functions
Scraper::rpchv::RpcHvScraper Class Reference
Inheritance diagram for Scraper::rpchv::RpcHvScraper:
Inheritance graph
[legend]
Collaboration diagram for Scraper::rpchv::RpcHvScraper:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def changed
def propagate
def seed

Private Member Functions

def _detectordict
def _getsite

Detailed Description

Definition at line 41 of file rpchv.py.


Member Function Documentation

def Scraper::rpchv::RpcHvScraper::changed (   self,
  sv 
)
:param sv: source vector instance :py:class:`Scraper.base.sourcevector.SourceVector` 

Decide if sufficient change to propagate based on differences between the first and last elements of `SourceVector` instance argument

Definition at line 43 of file rpchv.py.

00044                            :
00045         """
00046         :param sv: source vector instance :py:class:`Scraper.base.sourcevector.SourceVector` 
00047 
00048         Decide if sufficient change to propagate based on differences between the first and last elements of `SourceVector` instance argument
00049         """
00050 
00051         p = self._detectordict( sv[0] )
00052         c = self._detectordict( sv[-1] )
00053         site = p.pop('site')
00054         det = p.pop('det')['det']
00055         for label in sorted(p.keys()):
00056             pv = p[label]
00057             cv = c[label]
00058             if abs(pv['voltage']-cv['voltage']) > self.threshold:
00059                 return True
00060         return False

def Scraper::rpchv::RpcHvScraper::propagate (   self,
  sv 
)
:param sv: source vector instance :py:class:`Scraper.base.sourcevector.SourceVector` 

Yield write ready DybDbi target dicts to base class, note that a single source vector
instance is yielding multiple target dicts. The keys of the target dict must match
the specified attributes of the ``DybDbi`` target class. 

Here the output is based entirely on the last element of the source vector. A smarter
implementation might average the first and last to smooth variations.
The python ``yield`` command makes it possible to iterate over a what is returned by 
a function/method.

ETW Aug 2012: write voltage from sv[0], NOT sv[-1]

Definition at line 61 of file rpchv.py.

00062                             :
00063         """
00064         :param sv: source vector instance :py:class:`Scraper.base.sourcevector.SourceVector` 
00065 
00066         Yield write ready DybDbi target dicts to base class, note that a single source vector
00067         instance is yielding multiple target dicts. The keys of the target dict must match
00068         the specified attributes of the ``DybDbi`` target class. 
00069 
00070         Here the output is based entirely on the last element of the source vector. A smarter
00071         implementation might average the first and last to smooth variations.
00072         The python ``yield`` command makes it possible to iterate over a what is returned by 
00073         a function/method.
00074 
00075         ETW Aug 2012: write voltage from sv[0], NOT sv[-1]
00076         """
00077 
00078         dd = self._detectordict(sv[0])
00079         n = 0
00080         site = dd.pop('site')
00081         siteval = site['site'] 
00082         det = dd.pop('det')
00083         detval = det['det']
00084         ksite = self._getsite(siteval)
00085         detnum = 7
00086         for (label,sign),v in sorted(dd.items()):
00087             if (sign > 0):
00088                 vp = dd[label,1]
00089                 vn = dd[label,-1]
00090                 vpos = vp['voltage']
00091                 vneg = vn['voltage']
00092                 d = dict(LocationId=label,VoltagePos=vpos,VoltageNeg=vneg)
00093                 log.info("Writing out LocationId={}, VoltagePos={}, VoltageNeg={}".format(label,vpos,vneg))
00094                 n += 1
00095                 yield d
00096                 log.debug("yielded %s target dicts for  %s " % ( n, sv ))
00097 

def Scraper::rpchv::RpcHvScraper::seed (   self,
  sc 
)
Used for seeding target DB when testing into empty tables

:param sc: source class, potentially different seeds will be needed 
   for each source that feeds into a single target

Definition at line 98 of file rpchv.py.

00099                       :
00100         """
00101         Used for seeding target DB when testing into empty tables
00102 
00103         :param sc: source class, potentially different seeds will be needed 
00104                    for each source that feeds into a single target
00105         """
00106 
00107         scstr = str(sc)
00108         
00109         if scstr.find("DBNS_RPC") > 0:
00110             return dict(LocationId="F00",VoltagePos=0,VoltageNeg=0)
00111         if scstr.find("LANS_RPC") > 0:
00112             return dict(LocationId="F00",VoltagePos=0,VoltageNeg=0)
00113         if scstr.find("FARS_RPC") > 0:
00114             return dict(LocationId="F00",VoltagePos=0,VoltageNeg=0)

def Scraper::rpchv::RpcHvScraper::_detectordict (   self,
  inst 
) [private]
:param inst: SQLAlchemy source instance

Examines source instance, extracting detector name, DCS detector id, and values into a dict.

Definition at line 115 of file rpchv.py.

00116                                 :
00117         """
00118         :param inst: SQLAlchemy source instance
00119 
00120         Examines source instance, extracting detector name, DCS detector id, and values into a dict.
00121         """
00122 
00123         dd={}
00124         inststr = str(inst)
00125         sitestr = inststr[1:4]
00126         detstr = inststr[6:9]
00127         dd['site'] = {'site':sitestr}
00128         dd['det'] = {'det':detstr}
00129 
00130         for k,v in inst.asdict.items():
00131             if k in 'id date_time'.split():
00132                 continue
00133             if v is None:
00134                 v = -999
00135             sign = k.find("P")
00136             if (sign > 0):
00137                 kp = 1
00138             else:
00139                 kp = -1
00140             if (k[5] == 'F'):
00141                 kshort = k[5:6]+k[7:9]
00142             else:
00143                 kshort = 'T'+k[8:10]
00144             kk = (kshort,kp)
00145             qty,kk = ('voltage',kk)
00146             if dd.has_key(kk):
00147                 dd[kk].update({qty:v})
00148             else:
00149                 dd[kk] = {qty:v}
00150         return dd

def Scraper::rpchv::RpcHvScraper::_getsite (   self,
  site 
) [private]
Returns ksite number given string input

Definition at line 151 of file rpchv.py.

00152                            :
00153         """
00154         Returns ksite number given string input
00155         """
00156 
00157         if site == 'DBN':
00158             return SiteFromString("DayaBay")
00159         elif site == 'LAN':
00160             return SiteFromString("LingAo")
00161         elif site == 'FAR':
00162             return SiteFromString("Far")
00163         else:
00164             msg = "Do not recognize site...must be DBNS, LANS, or FARS"
00165             log.fatal(msg)
00166             raise Exception(msg)
00167             return -1


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:50:03 for Scraper by doxygen 1.7.4