/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 | Static Public Attributes | Properties
Scraper::base::sa::SABase Class Reference

List of all members.

Public Member Functions

def cflods
 list of dicts, useful for TabularData presentation
def grpfns
def aggfns
def __str__
def delta_dict

Static Public Attributes

tuple last = classmethod(lambda kls:kls.db.qd(kls).first())
tuple first = classmethod(lambda kls:kls.db.qa(kls).first())
tuple count = classmethod(lambda kls:kls.db.q(kls).count())
tuple q = classmethod(lambda kls:kls.db.q(kls))
tuple qa = classmethod(lambda kls:kls.db.qa(kls))
tuple qd = classmethod(lambda kls:kls.db.qd(kls))
tuple qafter = classmethod(lambda kls,cut:kls.db.qafter(kls,cut))
tuple qbefore = classmethod(lambda kls,cut:kls.db.qbefore(kls,cut))
tuple attribs = classmethod(lambda kls:filter(lambda k:isinstance(getattr(kls,k), InstrumentedAttribute ),dir(kls)))
tuple cflods = classmethod( cflods )
tuple grpfns = classmethod(grpfns)
tuple aggfns = classmethod(aggfns)

Properties

 asdict = property(lambda self:dict(zip(self.attribs(),map(lambda k:getattr(self,k),self.attribs()))))
 lod = property(lambda self:map(lambda k:dict(att=k,val=getattr(self,k)), self.attribs()))
 lods = property(lambda self:map(lambda k:dict(att=k,val=str(getattr(self,k))), self.attribs()))

Detailed Description

Shortcut classmethods on the dynamic classes
suspect these shortcuts should be deprecated, as although interactivly convenient they add an unneeded layer 

Definition at line 98 of file sa.py.


Member Function Documentation

def Scraper::base::sa::SABase::cflods (   cls,
  insts,
  labels 
)

list of dicts, useful for TabularData presentation

return list of dicts with keys for attribute names and values for each instance

Definition at line 118 of file sa.py.

00119                                     :
00120         """
00121         return list of dicts with keys for attribute names and values for each instance
00122         """
00123         l = [] 
00124         assert len(insts) == len(labels)
00125         if len(insts) == 0:
00126             return l 
00127         for k in insts[0].attribs():
00128             d = dict(att=k)
00129             for i in range(len(insts)):
00130                 d.update( {str(labels[i]):str(getattr(insts[i],k)) } )
00131             l.append(d)
        return l 
def Scraper::base::sa::SABase::grpfns (   kls,
  by = 'date,
  hour,
  att = 'date_time' 
)
:param kls: SA dynamic class
:param by: comma delimited string of SA function names which take single attribute arguments 
:param att: name of SA dybnamic class attribute to be single argument of functions

:return: list of SA group_by functions

For example the defaults yield a list of functions::

    func.date(kls.date_time), func.hour(kls.date_time)    

which can be used in query group_by functions to provide multiple hourly aggregates
for multiple entries in a single query.

Definition at line 135 of file sa.py.

00136                                                       :
00137         """
00138         :param kls: SA dynamic class
00139         :param by: comma delimited string of SA function names which take single attribute arguments 
00140         :param att: name of SA dybnamic class attribute to be single argument of functions
00141 
00142         :return: list of SA group_by functions
00143 
00144         For example the defaults yield a list of functions::
00145 
00146             func.date(kls.date_time), func.hour(kls.date_time)    
00147 
00148         which can be used in query group_by functions to provide multiple hourly aggregates
00149         for multiple entries in a single query.
00150 
00151         """
00152         att = getattr( kls , att ) 
00153         grp = []
00154         for fn in by.split(","):
00155             f = getattr(func,fn)
00156             grp.append( f(att) )     
        return grp
def Scraper::base::sa::SABase::aggfns (   kls,
  funcs = 'avg,
  min,
  max,
  std,
  skips = 'date_time,
  id,
  count = 'count',
  _minmax = None,
  atts = None 
)
:param kls: SA dynamic class
:param fns: comma delimited string of aggregate function names 
:param skips: comma delimited string of kls attributes to exclude from aggregation  
:param count: name of count attribute providing the number of entries aggregated or None to inhibit
:param _minmax: default `None` otherwise name of attribute for which underscored min max values are provided
:param atts: default `None` means all attributes otherwise a comma delimited list of attributes to cross with the funcs

:return: list of SA generic functions crossing kls attributes with aggregate functions 

The default `_minmax=None`, when an attribute is provided eg `_minmax='date_time'` 
additional aggregate functions are appended that cause the range of the attribute to be
included in the aggregate query dict with keys like `_date_time_min` `_date_time_max`.
This is needed for group_by querying which reqires the time range to be embedded into 
the aggregate query dict for contextrange definition

Definition at line 160 of file sa.py.

00161                                                                                                                  :
00162         """
00163         :param kls: SA dynamic class
00164         :param fns: comma delimited string of aggregate function names 
00165         :param skips: comma delimited string of kls attributes to exclude from aggregation  
00166         :param count: name of count attribute providing the number of entries aggregated or None to inhibit
00167         :param _minmax: default `None` otherwise name of attribute for which underscored min max values are provided
00168         :param atts: default `None` means all attributes otherwise a comma delimited list of attributes to cross with the funcs
00169 
00170         :return: list of SA generic functions crossing kls attributes with aggregate functions 
00171 
00172         The default `_minmax=None`, when an attribute is provided eg `_minmax='date_time'` 
00173         additional aggregate functions are appended that cause the range of the attribute to be
00174         included in the aggregate query dict with keys like `_date_time_min` `_date_time_max`.
00175         This is needed for group_by querying which reqires the time range to be embedded into 
00176         the aggregate query dict for contextrange definition
00177 
00178         """
00179         fns = funcs.split(",")
00180         skips = skips.split(",")
00181         atts_ = lambda kls:filter(lambda k:isinstance(getattr(kls,k), InstrumentedAttribute ),dir(kls))     
00182         if atts:
00183             atts = atts.split(",")
00184         else:
00185             atts = filter(lambda k:k not in skips,atts_(kls))
00186         agf = []
00187         if count:
00188             agf.append( func.count().label(count) )
00189         for atn in atts:
00190             att = getattr(kls,atn)
00191             for fn in fns:
00192                 f = getattr(func,fn)
00193                 agf.append( f(att).label('%s_%s' % ( atn, fn )) )
00194 
00195         if _minmax:
00196             atn = _minmax 
00197             att = getattr( kls, atn )
00198             for fn in ('min','max',):
00199                 f = getattr(func,fn)
00200                 agf.append( f(att).label('_%s_%s' % ( atn, fn )) )
00201 
        return agf
def Scraper::base::sa::SABase::__str__ (   self)

Definition at line 205 of file sa.py.

00206                      :
00207         td = TabularData(self.lods)
00208         return self.__class__.__name__ + "\n" + str(td)

def Scraper::base::sa::SABase::delta_dict (   self,
  other 
)
Generic delta-ing 

Definition at line 209 of file sa.py.

00210                                :
00211         """
00212         Generic delta-ing 
00213         """
00214         dd = {}
00215         for k in self.attribs():
00216              vself  = getattr( self, k  )
00217              vother = getattr( other, k )
00218              dd[k] = vself - vother           
00219         return dd


Member Data Documentation

tuple Scraper::base::sa::SABase::last = classmethod(lambda kls:kls.db.qd(kls).first()) [static]

Definition at line 103 of file sa.py.

tuple Scraper::base::sa::SABase::first = classmethod(lambda kls:kls.db.qa(kls).first()) [static]

Definition at line 104 of file sa.py.

tuple Scraper::base::sa::SABase::count = classmethod(lambda kls:kls.db.q(kls).count()) [static]

Definition at line 105 of file sa.py.

tuple Scraper::base::sa::SABase::q = classmethod(lambda kls:kls.db.q(kls)) [static]

Definition at line 106 of file sa.py.

tuple Scraper::base::sa::SABase::qa = classmethod(lambda kls:kls.db.qa(kls)) [static]

Definition at line 107 of file sa.py.

tuple Scraper::base::sa::SABase::qd = classmethod(lambda kls:kls.db.qd(kls)) [static]

Definition at line 108 of file sa.py.

tuple Scraper::base::sa::SABase::qafter = classmethod(lambda kls,cut:kls.db.qafter(kls,cut)) [static]

Definition at line 109 of file sa.py.

tuple Scraper::base::sa::SABase::qbefore = classmethod(lambda kls,cut:kls.db.qbefore(kls,cut)) [static]

Definition at line 110 of file sa.py.

tuple Scraper::base::sa::SABase::attribs = classmethod(lambda kls:filter(lambda k:isinstance(getattr(kls,k), InstrumentedAttribute ),dir(kls))) [static]

Definition at line 111 of file sa.py.

tuple Scraper::base::sa::SABase::cflods = classmethod( cflods ) [static]

Definition at line 132 of file sa.py.

tuple Scraper::base::sa::SABase::grpfns = classmethod(grpfns) [static]

Definition at line 157 of file sa.py.

tuple Scraper::base::sa::SABase::aggfns = classmethod(aggfns) [static]

Definition at line 202 of file sa.py.


Property Documentation

Scraper::base::sa::SABase::asdict = property(lambda self:dict(zip(self.attribs(),map(lambda k:getattr(self,k),self.attribs())))) [static]

Definition at line 113 of file sa.py.

Scraper::base::sa::SABase::lod = property(lambda self:map(lambda k:dict(att=k,val=getattr(self,k)), self.attribs())) [static]

Definition at line 115 of file sa.py.

Scraper::base::sa::SABase::lods = property(lambda self:map(lambda k:dict(att=k,val=str(getattr(self,k))), self.attribs())) [static]

Definition at line 116 of file sa.py.


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