当前位置: 首页>>代码示例>>Python>>正文


Python utilities.TimeAgent类代码示例

本文整理汇总了Python中nell.utilities.TimeAgent的典型用法代码示例。如果您正苦于以下问题:Python TimeAgent类的具体用法?Python TimeAgent怎么用?Python TimeAgent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TimeAgent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: solar_avoidance_degrees

 def solar_avoidance_degrees(self):
     """
     Returns 0.0 if there is no solar avoidance, otherwise returns
     this obs param in degrees.
     """
     sa = self.get_solar_avoidance()
     return 0.0 if sa is None else TimeAgent.rad2deg(sa)
开发者ID:,项目名称:,代码行数:7,代码来源:

示例2: _get_future_maintenance_dates3

def _get_future_maintenance_dates3():
    today = TimeAgent.truncateDt(datetime.now())
    mp = Period.objects\
        .filter(session__observing_type__type = "maintenance")\
        .latest("start")

    last_date = mp.start
    week = today - timedelta(today.weekday()) # get the date of the Monday of this week.
    dates = {}

    # now loop, one week at a time, until that last date, gathering
    # all the maintenance periods.  Each group will be represented as
    # a day of the week: 'A' = 0 (Monday), 'B' = 1 (Tuesday), etc.
    # These dates are then entered into the list of possible future
    # dates.
    
    while week < last_date:
        groups = Maintenance_Activity_Group.get_maintenance_activity_groups(week)

        for i in groups:
            d = str(i.get_start().date())
            
            if not dates.has_key(d):
                dates[d] = []
                
            dates[d].append(str(i.rank))
            
        week += timedelta(7)

    return dates
开发者ID:mmccarty,项目名称:nell,代码行数:30,代码来源:resource_cal.py

示例3: end

    def end(self):
        end = self.contained.period.end()
        end = TimeAgent.utc2est(end) if self.TZ == 'ET' else end
        end = datetime(end.year, end.month, end.day, 0, 0) + timedelta(days = 1)\
            if self.end_cutoff else end

        return end
开发者ID:,项目名称:,代码行数:7,代码来源:

示例4: get_due_date

        def get_due_date(template):
            if template.repeat_interval == 30:
                due_dates = get_monthly_due_dates(template)

                for i in range(0, 7):
                    dday = self.week + timedelta(days = i)
                    
                    if dday in due_dates:
                        return dday
                    
            if template.repeat_interval == 7:
                week = TimeAgent.truncateDt(self.week)
                start_date = TimeAgent.truncateDt(template.get_start())
                diff = timedelta(days = (week - start_date).days % \
                                     template.repeat_interval)
                return week + timedelta(7) - diff
            return None
开发者ID:mmccarty,项目名称:nell,代码行数:17,代码来源:Maintenance_Activity_Group.py

示例5: good_fit

        def good_fit(template, mag):
            # Checks to see if this template wouldn't work better
            # elsewhere.  If so, returns False.  If not, returns True.

            # first, take care of simple cases: repeat = 1, or no
            # published mags this week, the template is due, and this
            # is the highest U:

            if template.repeat_interval == 1:
                return False if better_fit(t, other_groups_today) else True

            if len(published_groups_this_week) == 0 \
                    and is_highest_U(mag):
                return True

            if is_P(self):
                # Here we generate a dictionary to weigh the possible dates that a 
                # repeat event can be substantiated in. The lower the number the better. 
                # A slight preference is given to the date that comes before the due date
                # over one that comes after, but that's really just for tie-breaking purposes.
                #dm = {-4: 40, -3: 30, -2: 20, -1: 10, 0: 0, 1: 15, 2: 25, 3: 35, 4: 45}
                dayLen = 30
                dm = [(i,10*abs(i)) for i in range(-dayLen,1)]
                dm.extend([(i,(10*i)+5) for i in range(1,dayLen)])
                dm = dict(dm)

                today = TimeAgent.truncateDt(self.period.start)
                p = [mag.period for mag in published_groups_this_week]
                due_date = get_due_date(template)
                diff = (today - due_date).days

                if diff:
                    # doesn't fall on this date.  Is this the closest
                    # period though?
                    for j in p:
                        if j != self.period:  # check only other periods
                            mod = (TimeAgent.truncateDt(j.start) - due_date).days

                            # Test to see if it's a better fit in
                            # another period.  and if so, don't
                            # use here.
                            if dm[mod] < dm[diff]:
                                return False
                return True
            return False
开发者ID:,项目名称:,代码行数:45,代码来源:

示例6: test_getSchedulingRange

    def test_getSchedulingRange(self):

        # scheduling range is 0:00 of timezone of first day
        # to the last day at 8:00 EST

        # test it in winter time
        dt = datetime(2010, 1, 1)
        days = 2
        expStart = datetime(2010, 1, 1, 0)
        expEnd   = datetime(2010, 1, 3, 13)
        expDur = TimeAgent.dtDiffMins(expStart, expEnd)

        start, dur = ScheduleTools().getSchedulingRange(dt, 'UTC', days)
        self.assertEquals(expStart, start)
        self.assertEquals(expDur, dur)

        # make sure it works in ET too
        expStart = datetime(2010, 1, 1, 5)
        expEnd   = datetime(2010, 1, 3, 13)
        expDur = TimeAgent.dtDiffMins(expStart, expEnd)

        start, dur = ScheduleTools().getSchedulingRange(dt, 'ET', days)
        self.assertEquals(expStart, start)

        # test it in summer time
        dt = datetime(2010, 6, 10)
        days = 3
        expStart = datetime(2010, 6, 10, 0)
        expEnd   = datetime(2010, 6, 13, 12)
        expDur = TimeAgent.dtDiffMins(expStart, expEnd)

        start, dur = ScheduleTools().getSchedulingRange(dt, 'UTC', days)
        self.assertEquals(expStart, start)
        self.assertEquals(expDur, dur)

        # make sure it works in ET too
        expStart = datetime(2010, 6, 10, 4)
        expEnd   = datetime(2010, 6, 13, 12)
        expDur = TimeAgent.dtDiffMins(expStart, expEnd)

        start, dur = ScheduleTools().getSchedulingRange(dt, 'ET', days)
        self.assertEquals(expStart, start)
        self.assertEquals(expDur, dur)
开发者ID:mmccarty,项目名称:nell,代码行数:43,代码来源:TestScheduleTools.py

示例7: start

    def start(self):
        start = self.contained.period.start

        if self.TZ == 'ET':
            start = TimeAgent.utc2est(start)

        if self.start_cutoff:
            start = datetime(start.year, start.month, start.day) + timedelta(days = 1)

        return start
开发者ID:,项目名称:,代码行数:10,代码来源:

示例8: get_end

    def get_end(self, tzname = None):
        """
        If this is a fixed maintenance period then return the period's
        end, if not return the end of the week.
        """

        if self.period:
            end = self.period.end()
            return TimeAgent.utc2est(end) if tzname == 'ET' else end
        else:
            return self.get_week() + timedelta(7)
开发者ID:mmccarty,项目名称:nell,代码行数:11,代码来源:Maintenance_Activity_Group.py

示例9: get_start

 def get_start(self, tzname = None):
     """
     If this is a fixed maintenance period there will have been a
     period assigned.  If so, return this period's start.  If not,
     return the start-of-week date.
     """
     if self.period:
         start = self.period.start
         return TimeAgent.utc2est(start) if tzname == 'ET' else start
     else:
         return self.get_week()
开发者ID:mmccarty,项目名称:nell,代码行数:11,代码来源:Maintenance_Activity_Group.py

示例10: set_base_fields

    def set_base_fields(self, fdata):
        fsestype = fdata.get("type", "open")
        fobstype = fdata.get("science", "testing")
        proj_code = fdata.get("pcode", "GBT09A-001")

        try:
            p  = Project.objects.get(pcode = proj_code)
        except Project.DoesNotExist:
            p = Project.objects.all()[0]

        self.sesshun.project          = p
        self.sesshun.session_type     = Session_Type.objects.get(type = fsestype)
        self.sesshun.observing_type   = Observing_Type.objects.get(type = fobstype)
        self.sesshun.original_id      = \
            self.get_field(fdata, "orig_ID", None, lambda x: int(float(x)))
        self.sesshun.name             = fdata.get("name", None)
        self.sesshun.frequency        = fdata.get("freq", None)
        self.sesshun.max_duration     = TimeAgent.rndHr2Qtr(float(fdata.get("req_max", 12.0)))
        self.sesshun.min_duration     = TimeAgent.rndHr2Qtr(float(fdata.get("req_min",  3.0)))
        self.sesshun.time_between     = fdata.get("between", None)
开发者ID:mmccarty,项目名称:nell,代码行数:20,代码来源:SessionHttpAdapter.py

示例11: jsondict

 def jsondict(self, tz):
     start = self.period.start if tz == 'UTC' else TimeAgent.utc2est(self.period.start)
     end   = self.period.end() if tz == 'UTC' else TimeAgent.utc2est(self.period.end())
     w = self.period.window
     # stakeholder want's 'T' or '' for this
     sponsored = self.period.session.project.is_sponsored()
     sponsored = '' if not sponsored else 'T'
     js =   {"id"           : self.period.id
           , "session"      : SessionHttpAdapter(self.period.session).jsondict()
           , "session_name" : self.period.session.name
           , "handle"       : self.period.toHandle()
           , "stype"        : self.period.session.session_type.type[0].swapcase()
           , "end_date"     : d2str(end)
           , "end_time"     : t2str(end)
           , "date"         : d2str(start)
           , "time"         : t2str(start)
           , "lst"          : str(TimeAgent.dt2tlst(self.period.start))
           , "duration"     : self.period.duration
           , "sscore"       : self.period.score       # scheduling score
           , "cscore"       : -1.0                    # current score
           , "forecast"     : dt2str(self.period.forecast)
           , "backup"       : self.period.backup
           , "moc_ack"      : self.period.moc_ack if self.period.moc_ack is not None else False
           , "state"        : self.period.state.abbreviation if self.period.state is not None else ""
           , "windowed"     : True if w is not None else False
           , "wdefault"     : self.period.is_windowed_default() \
                                  if w is not None else None
           , "wstart"       : d2str(w.start_date()) if w is not None else None
           , "wend"         : d2str(w.last_date()) if w is not None else None
           , "sponsored"    : sponsored
           , "sponsor"      : self.period.session.project.sponsor_text()
           , "receivers"    : self.period.get_rcvrs_json()
             }
     # include the accounting but keep the dict flat
     if self.period.accounting is not None:
         accounting_js = self.period.accounting.jsondict()
         # make sure the final jsondict has only one 'id'
         accounting_id = accounting_js.pop('id')
         accounting_js.update({'accounting_id' : accounting_id})
         js.update(accounting_js)
     return js
开发者ID:,项目名称:,代码行数:41,代码来源:

示例12: clone

    def clone(self, group = None):
        """
        Creates a clone of the template, assigning the 'group' field
        to the parameter 'group' if this parameter is provided.  The
        object will not be identical: there will be a different id,
        for instance.
        """

        ma = Maintenance_Activity();
        ma.save()
        # will be overwritten if template and group provided.
        ma.group = group if group else self.group
        # subject to a more recent one being found (see below)
        template = self

        # If this is a repeat template:
        if self.repeat_interval:
            ma.repeat_interval = 0
            ma.repeat_end = None
            ma.repeat_template = self.repeat_template \
                if self.repeat_template else self

            if group:
                template = self.get_template(group)

                # all maintenance activities are based on local time,
                # i.e. start 8:00 AM means that regardless of whether
                # DST is active or not.  To do this, we get ET version
                # of group and template start so that it can be saved
                # as the appropriate UTC time to account for DST.
                t_start = template.get_start('ET')
                g_start = TimeAgent.utc2est(group.get_start())

                start = datetime(g_start.year, g_start.month, g_start.day,
                                 t_start.hour, t_start.minute)

            # if this is a template, include the original creation
            # date for the repeat activity.
            ma.modifications.add(template.modifications.all()[0])
        else:
            # we want the group's date, and the original's time in ET
            if group:
                start = datetime(group.get_start().date().year, group.get_start().date().month,
                                 group.get_start().date().day, self.get_start('ET').hour,
                                 self.get_start('ET').minute)
            else:
                start = self.get_start('ET')

        ma.copy_data(template)
        ma.set_start(start if start else template.start, 'ET' if start else None)
        ma.save()
        return ma
开发者ID:mmccarty,项目名称:nell,代码行数:52,代码来源:Maintenance_Activity.py

示例13: GenerateBlackoutReport

def GenerateBlackoutReport():
    outfile = open("./DssBlackoutReport.txt", 'w')
    now     = datetime.utcnow()
    later   = now + timedelta(days = 7)

    outfile.write("Project     | Start (UTC) |  End (UTC)  |  Start (ET) |  End (ET)\n")
    outfile.write("-------------------------------------------------------------------\n")

    sorted_projects = sorted(Project.objects.filter(complete = False)
                           , lambda x, y: cmp(x.pcode, y.pcode))
    for p in sorted_projects:
        blackouts = p.get_blackout_times(now, later)
        if blackouts:
            for start, end in blackouts:
                outfile.write("%s | %s | %s | %s | %s\n" % \
                    (p.pcode.ljust(11)
                   , start.strftime("%m-%d %H:%M")
                   , end.strftime("%m-%d %H:%M")
                   , TimeAgent.utc2est(start).strftime("%m-%d %H:%M")
                   , TimeAgent.utc2est(end).strftime("%m-%d %H:%M")))

    outfile.close()
开发者ID:mmccarty,项目名称:nell,代码行数:22,代码来源:BlackoutReport.py

示例14: getBlackedOutSchedulableTime

    def getBlackedOutSchedulableTime(self, start, end):
        """
        Of the hours in the given range that are schedulable,
        how many have been blacked out?
        Returns tuple of hours (scheduble but ignoring blackouts
                              , scheduable but blacked out)
        Returns tuple of (scheduable but ignoring blackouts total
                        , scheduable but blacked out total
                        , [2-tuple of scheduable-but-ignoring-blackouts range)]
                        , [[2-tuple of scheduable-but-blacked-out-range]])
        """
        nss1 = self.get_time_not_schedulable(start, end, blackouts=False)

        nss = self.trim_events(nss1, start, end)

        # now convert the non-schedulable time ranges to the
        # time that IS schedulable:
        schedulable = self.compliment_events(nss, start, end)

        # how much time is that?
        hrsSchedulable = sum([TimeAgent.timedelta2minutes(s[1] - s[0]) / 60.0 for s in schedulable])

        # now, for each chunk of schedulable time, how much is
        # blacked out?
        hrsBlackedOut = 0.0
        bss = []
        # print "schedulable loop:"
        for s in schedulable:
            bs = self.project.get_blackout_times(s[0], s[1])
            # but these blackout times might not match to the schedulable
            # end points, so we may need to truncate them
            bs = self.trim_events(bs, s[0], s[1])
            if len(bs) != 0:
                bss.append(bs)
            bsTime = sum([TimeAgent.timedelta2minutes(b[1] - b[0]) / 60.0 for b in bs])
            hrsBlackedOut += bsTime

        # return a summary of what we've found
        return (hrsSchedulable, hrsBlackedOut, schedulable, bss)
开发者ID:,项目名称:,代码行数:39,代码来源:

示例15: get_monthly_due_dates

        def get_monthly_due_dates(template):
            start_date = template._start.date()
            end = template.repeat_end
            dates = []
            midnight = time(0, 0, 0)
            months = 0
            ddate = start_date

            while ddate < end:
                dates.append(datetime.combine(ddate, midnight))
                months = months + 1
                ddate = TimeAgent.add_months(start_date, months)
            return dates
开发者ID:mmccarty,项目名称:nell,代码行数:13,代码来源:Maintenance_Activity_Group.py


注:本文中的nell.utilities.TimeAgent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。