/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 | Properties | Private Member Functions
Scraper::base::datetimebin::DatetimeBins Class Reference

List of all members.

Public Member Functions

def __init__
def __repr__
def __len__
def __getitem__
def aedge
def days_hours_minutes
def dump

Public Attributes

 start
 end
 period
 anumbin
 nobin
 prebin
 postbin
 numbin
 astart
 aend
 sstart
 send

Properties

 range = property(lambda self:[self[0][0],self[-1][1]] if len(self) else None )

Private Member Functions

def _align

Detailed Description

Definition at line 10 of file datetimebin.py.


Constructor & Destructor Documentation

def Scraper::base::datetimebin::DatetimeBins::__init__ (   self,
  start,
  end,
  period,
  subperiod 
)
:param start: starting datetime
:param end:   ending datetime
:param period: timedelta instance
:param subperiod: timedelta instance

Only simple periods are supported which can be expressed as 
an integer number of hours, minutes **OR** days.

#. `timedelta(hours=1)`
#. `timedelta(hours=3)`
#. `timedelta(minutes=1)`
#. `timedelta(minutes=30)`
#. `timedelta(days=1)`

To avoid partial sub-bins the start time `A` is aligned up to `A*` 
and end time `B` is aligned down to `B*`. But that would loose too many 
bins needlessly, so the start of the first bin and end of the last bin
use the sub range rounded `Asub*` and `Bsub*`

Time increasing down the page::

      ======================
                      A      (start)
      ----------------------  Asub*  (sstart:subperiod rndup)  ---   e(0)
                                                        |
      ----------------------                                    |  0 
                                                        |
      ======================  A*     (astart:period rndup)     ---   e(1)
                                                        |
      ----------------------                                    |
                                                        |  1  
      ----------------------                                    |
                                                        |
      ======================                                   ---   e(2)
                                                        |
      ----------------------                                    |
                                                        |  2
      ----------------------                                    |
                                                        |
      ======================  B*    (aend:period rounddown)    ---   e(3)
                                                        |  3  
      ----------------------  Bsub* (send:subperiod rounddown) ---   e(4)      4 bins 5 edges 
                      B     (end)
      ----------------------

      ======================


Definition at line 11 of file datetimebin.py.

00012                                                          :
00013         """
00014         :param start: starting datetime
00015         :param end:   ending datetime
00016         :param period: timedelta instance
00017         :param subperiod: timedelta instance
00018 
00019         Only simple periods are supported which can be expressed as 
00020         an integer number of hours, minutes **OR** days.
00021 
00022         #. `timedelta(hours=1)`
00023         #. `timedelta(hours=3)`
00024         #. `timedelta(minutes=1)`
00025         #. `timedelta(minutes=30)`
00026         #. `timedelta(days=1)`
00027 
00028         To avoid partial sub-bins the start time `A` is aligned up to `A*` 
00029         and end time `B` is aligned down to `B*`. But that would loose too many 
00030         bins needlessly, so the start of the first bin and end of the last bin
00031         use the sub range rounded `Asub*` and `Bsub*`
00032 
00033         Time increasing down the page::
00034 
00035               ======================
00036                                       A      (start)
00037               ----------------------  Asub*  (sstart:subperiod rndup)  ---   e(0)
00038                                                                         |
00039               ----------------------                                    |  0 
00040                                                                         |
00041               ======================  A*     (astart:period rndup)     ---   e(1)
00042                                                                         |
00043               ----------------------                                    |
00044                                                                         |  1  
00045               ----------------------                                    |
00046                                                                         |
00047               ======================                                   ---   e(2)
00048                                                                         |
00049               ----------------------                                    |
00050                                                                         |  2
00051               ----------------------                                    |
00052                                                                         |
00053               ======================  B*    (aend:period rounddown)    ---   e(3)
00054                                                                         |  3  
00055               ----------------------  Bsub* (send:subperiod rounddown) ---   e(4)      4 bins 5 edges 
00056                                       B     (end)
00057               ----------------------
00058 
00059               ======================
00060 
00061 
00062         """
00063         self.start = start
00064         self.end   = end
00065         self.period = period
00066 
00067         nobin = start == end or ( start == None ) or ( end == None )
00068 
00069         if nobin:
00070             astart = aend = sstart = send = None
00071         else: 
00072             astart = self._align(start, period, rup=1 )   # roundup
00073             aend   = self._align(end,   period, rup=0 )   # rounddown
00074             sstart = self._align(start, subperiod, rup=1 )   # roundup
00075             send   = self._align(end,   subperiod, rup=0 )   # rounddown
00076             log.debug( "start %s end %s "  % ( start.ctime(), end.ctime() ))
00077             log.debug("sstart %s send %s " % ( sstart.ctime(), send.ctime() )) 
00078             log.debug("astart %s aend %s " % ( astart.ctime(), aend.ctime() )) 
00079             assert sstart <= astart , "start bin out of order " 
00080             assert send   >= aend ,     "end bin out of order " 
00081     
00082         if nobin or sstart == send:
00083             anumbin = 0
00084             snumbin = 0
00085             numbin = 0
00086             prebin = False
00087             postbin = False
00088         else:
00089             anumbin = int((aend-astart).total_seconds()/period.total_seconds()) 
00090             snumbin = int((send-sstart).total_seconds()/period.total_seconds()) 
00091             numbin = anumbin
00092             prebin  = sstart != astart 
00093             postbin = send != aend
00094 
00095         self.anumbin = anumbin 
00096         self.nobin = nobin
00097         self.prebin = prebin
00098         self.postbin = postbin 
00099 
00100         if prebin:numbin += 1
00101         if postbin:numbin += 1
00102 
00103         log.debug(" anumbin %s nobin %s prebin %s postbin %s  numbin %s " % ( anumbin, nobin, prebin, postbin, numbin ))
00104 
00105         self.numbin = numbin 
00106         self.astart = astart
00107         self.aend   = aend
00108         self.sstart = sstart
00109         self.send   = send
00110 


Member Function Documentation

def Scraper::base::datetimebin::DatetimeBins::__repr__ (   self)

Definition at line 111 of file datetimebin.py.

00112                       :
00113     
00114         ct_ = lambda _:_.ctime() if _ else "-"
00115         return "\n".join( [
00116                      "binned range %s " % map(ct_, self.range if self.range else [] ) ,
00117                      "numbin %s "       % self.numbin ,
00118                      " start %s "       % ct_(self.start) ,
00119                      "sstart %s (up)"   % ct_(self.sstart) ,
00120                      "astart %s (up)"   % ct_(self.astart) ,
00121                      "  aend %s (down)" % ct_(self.aend) ,
00122                      "  send %s (down)" % ct_(self.send) ,
00123                      "   end %s "       % ct_(self.end) ,
00124                       ])
00125 

def Scraper::base::datetimebin::DatetimeBins::__len__ (   self)

Definition at line 127 of file datetimebin.py.

00128                      :
        return self.numbin
def Scraper::base::datetimebin::DatetimeBins::__getitem__ (   self,
  i 
)
:param i: index of bin 0:N-1, if negative count from N 
:return: list with two edge values 

Definition at line 129 of file datetimebin.py.

00130                              :
00131         """
00132         :param i: index of bin 0:N-1, if negative count from N 
00133         :return: list with two edge values 
00134         """
00135         if i < 0:
00136             j = self.numbin + i 
00137         else:
00138             j = i 
00139 
00140         if self.prebin and j == 0:
00141             return [self.sstart,self.astart]
00142         if self.postbin and j == self.numbin - 1:
00143             return [self.aend,self.send]
00144         if j >= self.numbin or j < 0:
00145             raise IndexError  
00146 
00147         a = j - 1 if self.prebin else j
00148         return [self.aedge(a), self.aedge(a+1) ] 

def Scraper::base::datetimebin::DatetimeBins::aedge (   self,
  a 
)

Definition at line 149 of file datetimebin.py.

00150                       :
00151         return self.astart + a*self.period   

def Scraper::base::datetimebin::DatetimeBins::days_hours_minutes (   self,
  period 
)
:param period: timedelta instance

Express the period in days, hours and minutes 
where only one of those is non-zero. eg:

#. `timedelta(days=1)`      
#. `timedelta(hours=8)`
#. `timedelta(minutes=1)`
#. `timedelta(minutes=5)`

Not permissable:

#. timedelta(days=1,hours=1,seconds=1,minutes=1)  

Definition at line 154 of file datetimebin.py.

00154                                           : 
00155         """
00156         :param period: timedelta instance
00157 
00158         Express the period in days, hours and minutes 
00159         where only one of those is non-zero. eg:
00160 
00161         #. `timedelta(days=1)`      
00162         #. `timedelta(hours=8)`
00163         #. `timedelta(minutes=1)`
00164         #. `timedelta(minutes=5)`
00165 
00166         Not permissable:
00167 
00168         #. timedelta(days=1,hours=1,seconds=1,minutes=1)  
00169 
00170         """
00171         days, seconds, microseconds = period.days, period.seconds, period.microseconds
00172         log.debug(" days %s , seconds %s , microseconds %s " % (days,seconds,microseconds) ) 
00173         assert seconds % 60 == 0, seconds
00174         # hours and minutes derived from the persisted days, seconds
00175         hours = seconds / 3600
00176         if hours:
00177             minutes = 0
00178         else:
00179             minutes = seconds / 60 
00180         log.debug(" minutes %s , hours %s " % (minutes, hours) )
00181         assert len(filter(None,(days,hours,minutes))) == 1, "only one of days,hours,minutes expected non-zero "
00182         return days, hours, minutes
00183 
def Scraper::base::datetimebin::DatetimeBins::_align (   self,
  t,
  period,
  rup = 1 
) [private]
:param t:  datetime instance
:param period: timedelta instance
:param rup: 0 to rounddown, 1 to roundup 

Definition at line 184 of file datetimebin.py.

00185                                        :
00186         """
00187         :param t:  datetime instance
00188         :param period: timedelta instance
00189         :param rup: 0 to rounddown, 1 to roundup 
00190         """
00191         if not t:return None  #gigo
00192         days, hours, minutes = self.days_hours_minutes( period ) 
00193         log.debug("_aligned days %s hours %s minutes %s " % (days, hours, minutes)) 
00194         log.debug("_aligned t %s " % (t))
00195         if days:
00196             a = rdate_(t, rup)
00197         elif hours:
00198             a = rhour_(t, rup)
00199         elif minutes:
00200             a = rminute_(t, rup)
00201         else:
00202             assert 0, (days,hours,minutes)
00203         return a

def Scraper::base::datetimebin::DatetimeBins::dump (   self,
  tail = False 
)

Definition at line 204 of file datetimebin.py.

00205                               :
00206          dmpr_ = lambda i:" [%-3s] %s %s " % ( i, map(lambda _:_.ctime(), self[i]), self[i][1]-self[i][0] )
00207          for i,r in enumerate(self):
00208              assert self[i] == r
00209              log.info(dmpr_(i))
00210          if tail:
00211              for i in (-1,-2,-3,-len(self)):
00212                  try: 
00213                      log.info(dmpr_(i))
00214                  except IndexError:
00215                      pass


Member Data Documentation

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.

Definition at line 60 of file datetimebin.py.


Property Documentation

Scraper::base::datetimebin::DatetimeBins::range = property(lambda self:[self[0][0],self[-1][1]] if len(self) else None ) [static]

Definition at line 152 of file datetimebin.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