Beispiel #1
0
def filterPeriodsByDate(start):
    "Returns the periods within a given month and year."
    _, day = calendar.monthrange(start.year, start.month)
    stop  = datetime(start.year, start.month, day, 23, 59, 59)
    ustart = TimeAgent.est2utc(start)
    ustop  = TimeAgent.est2utc(stop)
    return [p for p in getPeriods() \
            if (p.start >= ustart or p.end() > ustart) and p.start < ustop]
Beispiel #2
0
def filterPeriodsByDate(start):
    "Returns the periods within a given month and year."
    _, day = calendar.monthrange(start.year, start.month)
    stop   = datetime(start.year, start.month, day, 23, 59, 59)
    ustart = TimeAgent.est2utc(start)
    ustop  = TimeAgent.est2utc(stop)

    periods = []
    for p in ALL_PERIODS:
        if (p.start >= ustart or p.end() > ustart) and p.start < ustop:
            start, stop = normalizePeriodStartStop(p, start)
            periods.append([p, start, stop])

    return periods
Beispiel #3
0
def filterPeriodsByDate(start):
    "Returns the periods (plus lost time) within a given month and year."
    _, day = calendar.monthrange(start.year, start.month)
    stop   = datetime(start.year, start.month, day, 23, 59, 59)
    ustart = TimeAgent.est2utc(start)
    ustop  = TimeAgent.est2utc(stop)

    periods = []
    for p in getPeriods():
        if (p.start >= ustart or p.end() > ustart) and p.start < ustop:
            start, stop = normalizePeriodStartStop(p, start)
            # normalize lost time too!
            lostTime = (diffHrs(start, stop)/p.duration) * p.accounting.lost_time()
            periods.append([p, start, stop, lostTime]) 

    return periods
Beispiel #4
0
 def getStates(self, periodVersions):
    "What is the state history: a list of (dates, current state of period)?"
    states = []
    currentState = None
    for v in periodVersions:
        state = v.field_dict.get("state", None)
        if state is not None:
            currentState = state
        # the revision library saves things in ET - but we deal in UT    
        if not self.test:
            dt = TimeAgent.est2utc(v.revision.date_created)    
        else:
            # why make setting up the tests anymore complicated?
            dt = v.revision.date_created
        state = (dt, currentState)   
        if state not in states:
            states.append(state)
    return states        
Beispiel #5
0
def summary(request, *args, **kws):
    """
    Serves up a page that allows Operations to run reconcilation reports. There
    are two basic reports - schedule and project. Even though it is specifically
    for Operations, any logged in user may view it.
    """
    now        = datetime.now()
    psummary = []

    if request.method == 'POST':
        summary = request.POST.get('summary', 'schedule')

        project = project_search(request.POST.get('project', ''))
        if isinstance(project, list) and len(project) == 1:
            project = project[0].pcode
        else:
            project = ''

        month = request.POST.get('month', None)
        year  = request.POST.get('year', None)
        year  = int(year) if year else None
        if month and year:
            start = datetime(int(year)
                           , [m for m in calendar.month_name].index(month)
                           , 1)
        else: # Default to this month
            start = datetime(now.year, now.month, 1)
            month = calendar.month_name[start.month]
            year  = start.year
    else: # Default to this month
        summary    = 'schedule'
        project    = ''
        start      = datetime(now.year, now.month, 1)
        month      = calendar.month_name[start.month]
        year       = start.year

    end = datetime(start.year
                 , start.month
                 , calendar.monthrange(start.year, start.month)[1]) + \
          timedelta(days = 1)

    # View is in ET, database is in UTC. Only use scheduled periods.
    periods = Period.in_time_range(TimeAgent.est2utc(start)
                                 , TimeAgent.est2utc(end))
    if project:
        periods = [p for p in periods if p.isScheduled() and p.session.project.pcode == project]

    # Handle either schedule or project summaries.
    if summary == "schedule":
        schedule = get_gbt_schedule_events(start, end, "ET", True)
        url      = 'users/schedule_summary.html'
        projects = []
        receivers = {}
        days     = {}
        hours    = {}
        summary  = {}
    else:
        url      = 'users/project_summary.html'
        projects = list(set([p.session.project for p in periods]))
        projects.sort(lambda x, y: cmp(x.pcode, y.pcode))

        receivers = {}
        for p in periods:
            rxs = receivers.get(p.session.project.pcode, [])
            rxs.extend([r.abbreviation for r in p.receivers.all()])
            receivers[p.session.project.pcode] = rxs

        schedule = {}
        days     = dict([(p.pcode, []) for p in projects])
        hours    = dict([(p.pcode, 0) for p in projects])
        summary  = dict([(c, 0) for c in Sesshun.getCategories()])
        for p in periods:
            pstart = TimeAgent.utc2est(p.start)
            pend   = TimeAgent.utc2est(p.end())

            # Find the days this period ran within the month.
            day = pstart.day if pstart >= start else pend.day
            days[p.session.project.pcode].append(str(day))
            if day != pend.day: # For multi-day periods
                days[p.session.project.pcode].append(str(pend.day))

            # Find the duration of this period within the month.
            duration = min(pend, end) - max(pstart, start)
            hrs = duration.seconds / 3600. + duration.days * 24.
            hours[p.session.project.pcode] += hrs

            # Tally hours for various categories important to Operations.
            summary[p.session.getCategory()] += hrs

            # If just for one project, create a more detailed summary.
            if project:
                psummary.append((pstart, hrs, p.receiver_list))

    return render_to_response(
               url
             , {'calendar' : schedule
              , 'projects' : [(p
                             , sorted(list(set(receivers[p.pcode])))
                             , sorted(list(set(days[p.pcode]))
                                    , lambda x, y: cmp(int(x), int(y)))
                             , hours[p.pcode]) for p in projects]
              , 'start'    : start
              , 'months'   : calendar.month_name
              , 'month'    : month
              , 'years'    : [y for y in xrange(2009, now.year + 2, 1)]
              , 'year'     : year
              , 'summary'  : [(t, summary[t]) for t in sorted(summary)]
              , 'project'  : project
              , 'psummary' : psummary
              , 'is_logged_in': request.user.is_authenticated()})