/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 """ 00002 `sourcevector.py` can be used standalone to see the aggregate presention, usage:: 00003 00004 [blyth@belle7 base]$ ~/rst/bin/python sourcevector.py 00005 INFO:__main__:SV 1 (0,) 2011-02-01 00:00:00 partial notfull (00:00:00 ++) ==> 00006 INFO:__main__: 00007 +-------------------+-------------------+---------------------+---------------------+---------------+ 00008 | att [1817] | avg | max | min | std | 00009 +===================+===================+=====================+=====================+===============+ 00010 | DBNS_SAB_Temp_PT1 | 908.000000 | 1816.00 | 0.00 | 524.52264 | 00011 +-------------------+-------------------+---------------------+---------------------+---------------+ 00012 | DBNS_SAB_Temp_PT2 | 24.494221 | 29.00 | 20.00 | 2.870934 | 00013 +-------------------+-------------------+---------------------+---------------------+---------------+ 00014 | DBNS_SAB_Temp_PT3 | 34.494221 | 39.00 | 30.00 | 2.870934 | 00015 +-------------------+-------------------+---------------------+---------------------+---------------+ 00016 | DBNS_SAB_Temp_PT4 | 44.494221 | 49.00 | 40.00 | 2.870934 | 00017 +-------------------+-------------------+---------------------+---------------------+---------------+ 00018 | DBNS_SAB_Temp_PT5 | 54.494221 | 59.00 | 50.00 | 2.870934 | 00019 +-------------------+-------------------+---------------------+---------------------+---------------+ 00020 | date_time | 2.01102010232e+13 | 2011-02-01 05:02:40 | 2011-02-01 00:00:00 | 14419.7231251 | 00021 +-------------------+-------------------+---------------------+---------------------+---------------+ 00022 | id | 908.0000 | 1816 | 0 | 524.5226 | 00023 +-------------------+-------------------+---------------------+---------------------+---------------+ 00024 00025 00026 """ 00027 import logging, re 00028 from pprint import pformat 00029 00030 log = logging.getLogger(__name__) 00031 from DybPython.vlut import TabularData 00032 00033 class Aggregate(dict): 00034 def __str__(self): 00035 return str(PresentAggregate(self)) 00036 00037 class PresentAggregate(list): 00038 ptn = re.compile("^(?P<att>\S*)_(?P<agf>\S*)$") 00039 def __init__(self, aggd ): 00040 """ 00041 Rearrange flat dict with key names att_agf 00042 into list-of-dict to facilitate tabular presentation 00043 """ 00044 attd = {} 00045 meta = {} 00046 agfs = set() 00047 for k,v in aggd.items(): 00048 m = self.ptn.match(k) 00049 if m: 00050 d = m.groupdict() 00051 att, agf = d['att'], d['agf'] 00052 if not att in attd: 00053 attd[att] = {} 00054 attd[att][agf] = v 00055 agfs.add(agf) 00056 else: 00057 meta[k] = v 00058 00059 latt = "att [%s]" % meta['count'] ## HARDCODED attname 00060 self.latt = latt 00061 self.funcs = sorted(list(agfs)) 00062 00063 for att in sorted(attd): 00064 d = dict(attd[att]) 00065 d.update( {latt:att} ) 00066 self.append( d ) 00067 00068 def __str__(self): 00069 td = TabularData(self) 00070 return td.as_rst(cols=[self.latt] + self.funcs ) 00071 00072 00073 if __name__ == '__main__': 00074 pass 00075 00076