• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utilities.TimeAgent类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: _get_fixed_maint_events

def _get_fixed_maint_events(mags, day, timezone):
    """
    _get_fixed_maint_events(mags, day, timezone)

    Takes a set of maintenance activity groups and returns the one for
    'day' if there is a fixed one for 'day'.
    """

    evs = []
    day = TimeAgent.truncateDt(day)
    tomorrow = day + timedelta(1)

    for mag in mags:
        if mag.period:  # fixed if period is set
            if (
                TimeAgent.truncateDt(mag.get_start(timezone)) == day
                or TimeAgent.truncateDt(mag.get_end(timezone)) == day
            ):
                ev = CalEventFixedMaintenance(
                    mag, mag.get_start(timezone) < day, mag.get_end(timezone) >= tomorrow, True, timezone
                )
                evs.append(ev)
    return evs
开发者ID:,项目名称:,代码行数:23,代码来源:


示例17: read

    def read(self, request, *args, **kws):
        if len(args) == 1:
            tz,          = args
            startPeriods = request.GET.get("startPeriods", datetime.now().strftime("%Y-%m-%d"))
            daysPeriods  = request.GET.get("daysPeriods",  '14')

            dt           = TimeAgent.str2dt(startPeriods)
            start        = dt if tz == 'UTC' else TimeAgent.est2utc(dt)
            duration     = int(daysPeriods) * 24 * 60
            periods      = Period.get_periods(start, duration)
            pjson = [DssPeriodHttpAdapter(p).jsondict(tz) for p in periods]
            return HttpResponse(
                json.dumps(dict(total   = len(periods)
                              , periods = pjson
                              , success = 'ok'))
              , content_type = "application/json")
        else:
            tz, id = args
            p      = Period.objects.get(id = id)
            return HttpResponse(
                json.dumps(dict(DssPeriodHttpAdapter(p).jsondict(tz)
                              , success = 'ok'))
              , content_type = "application/json")
开发者ID:mmccarty,项目名称:nell,代码行数:23,代码来源:DssPeriodResource.py


示例18: get_start

    def get_start(self, tzname = None):
        if self.group:
            date = self.group.get_start().date()

            if self._start.hour < self.group.get_start().hour and \
                    self._start.hour < self.group.get_end().hour:
                date = date + timedelta(1)
            
            start = datetime(date.year, date.month, date.day,
                             self._start.hour, self._start.minute)
        else:
            start = self._start

        return TimeAgent.utc2est(start) if tzname == 'ET' else start
开发者ID:mmccarty,项目名称:nell,代码行数:14,代码来源:Maintenance_Activity.py


示例19: 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):
                dm = {-4: 40, -3: 30, -2: 20, -1: 10, 0: 0, 1: 15, 2: 25, 3: 35, 4: 45}
                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:mmccarty,项目名称:nell,代码行数:36,代码来源:Maintenance_Activity_Group.py


示例20: receivers_schedule

def receivers_schedule(request, *args, **kws):
    """
    For a given period, specified by a start date and duration, show
    all the receiver changes. Receiver changes are aligned with maintenance
    days.
    """

    # interpret the inputs
    startdate = request.GET.get("startdate", None)
    startdate = datetime.strptime(startdate, "%Y-%m-%d %H:%M:%S") if startdate else None

    duration = request.GET.get("duration", None)
    duration = int(duration) if duration else duration

    # use the input to get the basic rx schedule
    schedule = Receiver_Schedule.extract_schedule(startdate, duration)
    jsonschd = Receiver_Schedule.jsondict(schedule)

    # some clients also need the diff schedule
    diff = Receiver_Schedule.diff_schedule(schedule)
    jsondiff = Receiver_Schedule.jsondict_diff(diff).get("diff_schedule", None)

    # get the dates for maintenace that cover from the start of this
    # rcvr schedule.
    maintenance = [
        TimeAgent.dt2str(p.start)
        for p in Period.objects.filter(session__observing_type__type="maintenance", start__gte=startdate).order_by(
            "start"
        )
    ]

    # which receivers are temporarily unavailable?
    unavailable = [r.jsondict() for r in Receiver.objects.filter(available=False).order_by("freq_low")]

    # clients want to also know all the latest rcvrs
    rcvrs = [r.jsondict() for r in Receiver.objects.all().order_by("freq_low") if r.abbreviation != "NS"]
    return HttpResponse(
        json.dumps(
            {
                "schedule": jsonschd,
                "diff": jsondiff,
                "maintenance": maintenance,
                "unavailable": unavailable,
                "receivers": rcvrs,
            }
        ),
        mimetype="text/plain",
    )
开发者ID:,项目名称:,代码行数:48,代码来源:



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python nemoa.log函数代码示例发布时间:2022-05-27
下一篇:
Python neighbours.images2neibs函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap