/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 | Public Attributes
DybDbi::propagate_grouping::VldGroups Class Reference

List of all members.

Public Member Functions

def __init__
def summary
def __repr__
def find_tranche_index
def next_tranche
def kludge_insertdates

Public Attributes

 db
 allseqnos

Detailed Description

Via a mysql "group by" query obtain a list of all `SeqnoTranche` instances for
a DBI Vld table.

**NB when propagating a grouping from one table to another it is imperative that 
the two tables are SEQNO aligned**

Definition at line 98 of file propagate_grouping.py.


Constructor & Destructor Documentation

def DybDbi::propagate_grouping::VldGroups::__init__ (   self,
  db,
  tn = 'Demo',
  group_by = 'INSERTDATE' 
)
:param tn: DBI table name eg CableMap
:param group_by: Vld column to group by 

This assumes the grouping can be established via the value of a Vld column

TODO: check works with function groupings like : SEQNO DIV 100 

Definition at line 107 of file propagate_grouping.py.

00108                                                              :
00109         """
00110         :param tn: DBI table name eg CableMap
00111         :param group_by: Vld column to group by 
00112 
00113         This assumes the grouping can be established via the value of a Vld column
00114 
00115         TODO: check works with function groupings like : SEQNO DIV 100 
00116 
00117         """
00118         self.db = db 
00119         allseqnos = []
00120         sql = "select count(*) as N,min(SEQNO) as MI, max(SEQNO) as MX, %(group_by)s from %(tn)sVld group by %(group_by)s" % locals() 
00121         log.info("VldGroups : %s " % sql )  
00122         for idx, r in enumerate(db(sql)):
00123             n,mi,mx = map(lambda k:int(r[k]), ("N","MI","MX"))
00124             st = SeqnoTranche(db, n,mi,mx,idx,group_by=r[group_by])
00125             self.append(st)
00126             allseqnos.extend( st.seqnos )
00127         self.allseqnos = allseqnos


Member Function Documentation

def DybDbi::propagate_grouping::VldGroups::summary (   self)

Definition at line 128 of file propagate_grouping.py.

00129                      :
00130         return repr(self) + "\n".join(map(repr,self))

def DybDbi::propagate_grouping::VldGroups::__repr__ (   self)

Definition at line 131 of file propagate_grouping.py.

00132                       :
00133         return "%s %s \n" % (self.__class__.__name__,len(self)) 

def DybDbi::propagate_grouping::VldGroups::find_tranche_index (   self,
  seqno 
)
Identify the tranche index corresponding to the passed SEQNO

NB this assumes the SEQNO being checked comes from an aligned table to 
that used to construct the tranches.
If that is not the case, then use an aligning translation first.

:param seqno:  from source or target table, **ASSUMING ALIGNED**

Definition at line 134 of file propagate_grouping.py.

00135                                         :
00136         """
00137         Identify the tranche index corresponding to the passed SEQNO
00138 
00139         NB this assumes the SEQNO being checked comes from an aligned table to 
00140         that used to construct the tranches.
00141         If that is not the case, then use an aligning translation first.
00142 
00143         :param seqno:  from source or target table, **ASSUMING ALIGNED**
00144 
00145         """
00146         for i,st in enumerate(self):
00147             assert st.index == i, "tranche indices out of step "
00148             if st.contains(seqno):
00149                 return i
00150         return None

def DybDbi::propagate_grouping::VldGroups::next_tranche (   self,
  ttn,
  translate_seqno_ = lambda _:_ 
)
:param ttn: target table name
:param translate_seqno: lambda function that translates target table seqno into source table seqno 

Definition at line 151 of file propagate_grouping.py.

00151                                                           :_ ):
00152         """
00153         :param ttn: target table name
00154         :param translate_seqno: lambda function that translates target table seqno into source table seqno 
00155 
00156         """ 
00157         lseqno = self.db("select coalesce(max(SEQNO),0) as LSEQ from %(ttn)sVld " % locals() )[0]['LSEQ']
00158         tseqno = translate_seqno_(lseqno)
00159         lidx = self.find_tranche_index(tseqno)
00160         log.info("lseqno %s tseqno %s lidx %s " % (lseqno, tseqno, lidx) )
00161         pass
00162         if lidx == None:
00163             st = self[0]
00164         elif lidx + 1 < len(self):
00165             st = self[lidx+1]
00166         elif lidx + 1 == len(self):   # indices from 0 to len(vg) - 1
00167             st = None
00168         else:
00169             raise Exception("unexpected state lidx %s lseqno %s tseqno %s " % ( lidx, lseqno,tseqno ))
00170         return st, lseqno, tseqno 
00171 
00172 
def DybDbi::propagate_grouping::VldGroups::kludge_insertdates (   self,
  tn = 'Demo' 
)
Kludge insertdates for all `SeqnoTranche` instances 

:param tn: table name, eg CalibPmtFineGain

Definition at line 173 of file propagate_grouping.py.

00174                                            :
00175         """
00176         Kludge insertdates for all `SeqnoTranche` instances 
00177 
00178         :param tn: table name, eg CalibPmtFineGain
00179         """
00180         assert self.db.sect == 'tmp_offline_db', "the kludging of INSERTDATEs is for testing only, for real DB SOP must be used "
00181         t = datetime.utcnow()
00182         dt = timedelta(minutes=1)
00183         for i,st in enumerate(self):
00184             log.info("%-2s %s " % ( i,st ))
00185             st.kludge_insertdates( tn , t + i*dt )
00186 
00187 


Member Data Documentation

Definition at line 115 of file propagate_grouping.py.

Definition at line 115 of file propagate_grouping.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:57:24 for DybDbi by doxygen 1.7.4