Пример #1
0
 def getHrsInDayTime(self, start, end):
     "Split up given time range by PTCS day and night time hours."
     dur = TimeAgent.dtDiffHrs(start, end)
     startDate = date(start.year, start.month, start.day)
     #rise, set = self.sun.getRiseSet(date1)
     # cast a wide net: compute the rise and set times for any days
     # that might be covered by the given time range
     days = (end - start).days + 2
     dayTimes = []
     for day in range(days):
         dt = startDate + timedelta(days = day)
         dayTimes.append(self.sun.getPTCSRiseSet(dt))
     # where does our given time range intersect with day time?    
     ints = AnalogSet.intersects([dayTimes, [(start, end)]])
     if len(ints) > 0:
         # some day time
         day = 0.0
         for intersection in ints:
             td = intersection[1] - intersection[0]
             day += TimeAgent.timedelta2frachours(td)
         # the rest must be night time    
         night = abs(dur - day) 
     else:
         # our range is all night time.
         day = 0.0
         night = dur 
     return (day, night)
Пример #2
0
def getDowntime(periods, month):
    "This does not use getTime because lost time must be handled carefully"
                                     
    ps =  filterPeriods(periods, 'p.session.project.is_science()')
    ps.sort(key = lambda x: x.start)
    total = 0.0
    for p in ps:
        start, stop = normalizePeriodStartStop(p, month)
        hrs = TimeAgent.timedelta2frachours(stop - start)
        # We must normalize the lost time as well
        lostTime = (hrs/p.duration) * p.accounting.lost_time()
        total += lostTime
    return total 
Пример #3
0
def getTime(periods, month):
    periods.sort(key = lambda x: x.start)
    return sum([TimeAgent.timedelta2frachours(stop - start) \
                 for start, stop in [normalizePeriodStartStop(p, month) \
                                     for p in periods]])
Пример #4
0
def diffHrs(begin, end):
    return TimeAgent.timedelta2frachours(end - begin)