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


Python rrule.rrule方法代码示例

本文整理汇总了Python中dateutil.rrule.rrule方法的典型用法代码示例。如果您正苦于以下问题:Python rrule.rrule方法的具体用法?Python rrule.rrule怎么用?Python rrule.rrule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dateutil.rrule的用法示例。


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

示例1: previous_months_iterator

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def previous_months_iterator(month_for, months_back):
    '''Iterator returns a year,month tuple for n months including the month_for

    month_for is either a date, datetime, or tuple with year and month
    months back is the number of months to iterate

    includes the month_for
    '''

    if isinstance(month_for, tuple):
        # TODO make sure we've got just two values in the tuple
        month_for = datetime.date(year=month_for[0], month=month_for[1], day=1)
    if isinstance(month_for, (datetime.datetime, datetime.date)):
        start_month = month_for - relativedelta(months=months_back)

    for dt in rrule(freq=MONTHLY, dtstart=start_month, until=month_for):
        last_day_of_month = days_in_month(month_for=dt)
        yield (dt.year, dt.month, last_day_of_month) 
开发者ID:appsembler,项目名称:figures,代码行数:20,代码来源:helpers.py

示例2: backfill_monthly_metrics_for_site

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def backfill_monthly_metrics_for_site(site, overwrite=False):
    """Backfill all historical site metrics for the specified site
    """
    site_sm = get_student_modules_for_site(site)
    if not site_sm:
        return None

    first_created = site_sm.order_by('created').first().created

    start_month = datetime(year=first_created.year,
                           month=first_created.month,
                           day=1,
                           tzinfo=utc)
    last_month = datetime.utcnow().replace(tzinfo=utc) - relativedelta(months=1)
    backfilled = []
    for dt in rrule(freq=MONTHLY, dtstart=start_month, until=last_month):
        obj, created = fill_month(site=site,
                                  month_for=dt,
                                  student_modules=site_sm,
                                  overwrite=overwrite)
        backfilled.append(dict(obj=obj, created=created, dt=dt))

    return backfilled 
开发者ID:appsembler,项目名称:figures,代码行数:25,代码来源:backfill.py

示例3: gen_oneminute_dataset

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def gen_oneminute_dataset(n_row, n_col, dense):
    timestamps = []
    active_minutes_daily = 120
    for day in range(0, n_row // 120):
        timestamps.extend(list(rrule(MINUTELY, count=active_minutes_daily, dtstart=dt(2005, 1, 1) + td(days=day))))

    timestamps.extend(list(rrule(
        MINUTELY,
        count=n_row % active_minutes_daily,
        dtstart=dt(random.randrange(2006, 2016), 1, 1)),
    ))

    return pd.DataFrame(
        index=timestamps,
        data=gen_one_minute_rows(n_row, dense)
    ) 
开发者ID:man-group,项目名称:arctic,代码行数:18,代码来源:fwd_benchmarks.py

示例4: testRRuleAll

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def testRRuleAll(self):
        from dateutil.rrule import rrule
        from dateutil.rrule import rruleset
        from dateutil.rrule import rrulestr
        from dateutil.rrule import YEARLY, MONTHLY, WEEKLY, DAILY
        from dateutil.rrule import HOURLY, MINUTELY, SECONDLY
        from dateutil.rrule import MO, TU, WE, TH, FR, SA, SU

        rr_all = (rrule, rruleset, rrulestr,
                  YEARLY, MONTHLY, WEEKLY, DAILY,
                  HOURLY, MINUTELY, SECONDLY,
                  MO, TU, WE, TH, FR, SA, SU)

        for var in rr_all:
            self.assertIsNot(var, None)

        # In the public interface but not in all
        from dateutil.rrule import weekday
        self.assertIsNot(weekday, None) 
开发者ID:MediaBrowser,项目名称:plugin.video.emby,代码行数:21,代码来源:test_imports.py

示例5: date_range_pair

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def date_range_pair(start_date, end_date, step=5):
    """Create a range generator for dates.

    Given a start date and end date make an generator that returns a start
    and end date over the interval.

    """
    if isinstance(start_date, str):
        start_date = parser.parse(start_date)
    if isinstance(end_date, str):
        end_date = parser.parse(end_date)
    dates = list(rrule(freq=DAILY, dtstart=start_date, until=end_date, interval=step))
    # Special case with only 1 period
    if len(dates) == 1:
        yield start_date.date(), end_date.date()
    for date in dates:
        if date == start_date:
            continue
        yield start_date.date(), date.date()
        start_date = date + timedelta(days=1)
    if len(dates) != 1 and end_date not in dates:
        yield start_date.date(), end_date.date() 
开发者ID:project-koku,项目名称:koku,代码行数:24,代码来源:common.py

示例6: test_activity_series_create_activates_group

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def test_activity_series_create_activates_group(self):
        url = '/api/activity-series/'
        recurrence = rrule.rrule(
            freq=rrule.WEEKLY,
            byweekday=[0, 1]  # Monday and Tuesday
        )
        start_date = self.group.timezone.localize(datetime.now().replace(hour=20, minute=0))
        activity_series_data = {
            'max_participants': 5,
            'place': self.place.id,
            'rule': str(recurrence),
            'start_date': start_date
        }
        self.group.status = GroupStatus.INACTIVE.value
        self.group.save()
        self.client.force_login(user=self.member)
        self.client.post(url, activity_series_data, format='json')
        self.group.refresh_from_db()
        self.assertEqual(self.group.status, GroupStatus.ACTIVE.value) 
开发者ID:yunity,项目名称:karrot-backend,代码行数:21,代码来源:test_activity_series_api.py

示例7: ubuntu_url

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def ubuntu_url(start_date, end_date):
    """
    Args:
        start_date (date object): Starting date from which logs need to be fetched 
        end_date (date object) : Last date for which logs need to be fetched
    Returns:
        Yields channel name, current_date, and url at which log for returned
        channel and current_date is present.
    """
    
    for current_date in rrule(freq=DAILY, dtstart=start_date, until=end_date):
        url = UBUNTU_ENDPOINT.format(current_date.year,month=current_date.month, day=current_date.day)
        
        r = send_request(url)
        soup = BeautifulSoup(r)
        links = soup.findAll(href=re.compile(".txt"))
        
        for link in links:
            channel = link.string
            channel_ = channel[1:]
            
            yield channel, current_date, UBUNTU_CHANNEL_ENDPOINT.format(current_date.year, month=current_date.month, day=current_date.day, channel=channel_) 
开发者ID:prasadtalasila,项目名称:IRCLogParser,代码行数:24,代码来源:log_download.py

示例8: f_daterange

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def f_daterange(freq, tz='UTC', *args, **kwargs):
    """
    Use ``dateutil.rrule`` to create a range of dates. The frequency must be a
    string in the following list: YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY,
    MINUTELY or SECONDLY.

    See `dateutil rrule`_ documentation for more detail.

    .. _dateutil rrule: https://dateutil.readthedocs.org/en/latest/rrule.html

    :param freq: One of the ``dateutil.rrule`` frequencies
    :type freq: str
    :param tz: One of the ``pytz`` timezones, defaults to UTC
    :type tz: str
    :param args: start date <datetime>, interval between each frequency <int>,
        max number of recurrences <int>, end date <datetime>
    :param kwargs: ``dtstart``, ``interval``, ``count``, ``until``
    :return: range of dates
    :rtype: list
    """
    tz = pytz.timezone(tz)
    freq = getattr(rrule, freq.upper())  # get frequency enumeration from rrule
    return [tz.localize(dt) for dt in rrule.rrule(freq, *args, **kwargs)] 
开发者ID:BreakingBytes,项目名称:simkit,代码行数:25,代码来源:utils.py

示例9: get_early_closes

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def get_early_closes(start, end):
    # TSX closed at 1:00 PM on december 24th.

    start = canonicalize_datetime(start)
    end = canonicalize_datetime(end)

    early_close_rules = []

    early_close_rules.append(quarta_cinzas)

    early_close_ruleset = rrule.rruleset()

    for rule in early_close_rules:
        early_close_ruleset.rrule(rule)
    early_closes = early_close_ruleset.between(start, end, inc=True)

    early_closes.sort()
    return pd.DatetimeIndex(early_closes) 
开发者ID:zhanghan1990,项目名称:zipline-chinese,代码行数:20,代码来源:tradingcalendar_bmf.py

示例10: year_blocks

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def year_blocks(start, end):
    """
    Create pairs of start and end with max a year in between, to deal with usage restrictions on the API

    Parameters
    ----------
    start : dt.datetime | pd.Timestamp
    end : dt.datetime | pd.Timestamp

    Returns
    -------
    ((pd.Timestamp, pd.Timestamp))
    """
    rule = rrule.YEARLY

    res = []
    for day in rrule.rrule(rule, dtstart=start, until=end):
        res.append(pd.Timestamp(day))
    res.append(end)
    res = sorted(set(res))
    res = pairwise(res)
    return res 
开发者ID:EnergieID,项目名称:entsoe-py,代码行数:24,代码来源:misc.py

示例11: month_blocks

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def month_blocks(start, end):
    """
    Create pairs of start and end with max a month in between, to deal with usage restrictions on the API

    Parameters
    ----------
    start : dt.datetime | pd.Timestamp
    end : dt.datetime | pd.Timestamp

    Returns
    -------
    ((pd.Timestamp, pd.Timestamp))
    """
    rule = rrule.MONTHLY

    res = []
    for day in rrule.rrule(rule, dtstart=start, until=end):
        res.append(pd.Timestamp(day))
    res.append(end)
    res = sorted(set(res))
    res = pairwise(res)
    return res 
开发者ID:EnergieID,项目名称:entsoe-py,代码行数:24,代码来源:misc.py

示例12: day_blocks

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def day_blocks(start, end):
    """
    Create pairs of start and end with max a day in between, to deal with usage restrictions on the API

    Parameters
    ----------
    start : dt.datetime | pd.Timestamp
    end : dt.datetime | pd.Timestamp

    Returns
    -------
    ((pd.Timestamp, pd.Timestamp))
    """
    rule = rrule.DAILY

    res = []
    for day in rrule.rrule(rule, dtstart=start, until=end):
        res.append(pd.Timestamp(day))
    res.append(end)
    res = sorted(set(res))
    res = pairwise(res)
    return res 
开发者ID:EnergieID,项目名称:entsoe-py,代码行数:24,代码来源:misc.py

示例13: _get_last_start_date_within_range

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def _get_last_start_date_within_range(self, range_start, range_end,
                                          interval_type, interval_count,
                                          bymonth=None, byweekday=None, bymonthday=None):
        # we try to obtain a start date aligned to the given rules
        aligned_start_date = self._get_aligned_start_date_after_date(
            reference_date=range_start,
            interval_type=interval_type,
            bymonth=bymonth,
            bymonthday=bymonthday,
            byweekday=byweekday,
        )

        relative_start_date = range_start if aligned_start_date > range_end else aligned_start_date

        dates = list(
            rrule.rrule(interval_type,
                        dtstart=relative_start_date,
                        interval=interval_count,
                        until=range_end)
        )

        return aligned_start_date if not dates else dates[-1].date() 
开发者ID:silverapp,项目名称:silver,代码行数:24,代码来源:subscriptions.py

示例14: get_workdays

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def get_workdays(self, start_date, end_date):
        WORKDAYS = xrange(0, 5)
        r = rrule(DAILY, dtstart=start_date, until=end_date, byweekday=WORKDAYS)
        return r.count() 
开发者ID:fpsw,项目名称:Servo,代码行数:6,代码来源:calendar.py

示例15: generate_cdm_data_for_course

# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import rrule [as 别名]
def generate_cdm_data_for_course(course_id):
    """
    Just getting it working first, then we'll make the values more reasonable

    like value = sorted([lower_bound, x, upper_bound])[1]

    """
    cdm_data = []
    yesterday = {}
    end_date = prev_day(datetime.datetime.now())
    start_date = days_from(end_date, -180)

    for dt in rrule(DAILY, dtstart=start_date, until=end_date):
        enrollment_count = yesterday.get('enrollment_count', 0) + randint(0, 10)
        average_progress = gen_avg_progress(yesterday.get('average_progress', 0))
        average_days_to_complete = randint(10, 30)
        num_learners_completed = gen_num_learners_completed(yesterday)

        rec = dict(
            course_id=course_id,
            date_for=dt.strftime('%Y-%m-%d'),
            enrollment_count=enrollment_count,
            active_learners_today=randint(0, enrollment_count / 2),
            average_progress=average_progress,
            average_days_to_complete=average_days_to_complete,
            num_learners_completed=num_learners_completed,
        )
        cdm_data.append(rec)
        yesterday = rec
    return cdm_data 
开发者ID:appsembler,项目名称:figures,代码行数:32,代码来源:course_daily_metrics.py


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