本文整理汇总了Python中dateutil.rrule.DAILY属性的典型用法代码示例。如果您正苦于以下问题:Python rrule.DAILY属性的具体用法?Python rrule.DAILY怎么用?Python rrule.DAILY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类dateutil.rrule
的用法示例。
在下文中一共展示了rrule.DAILY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRRuleAll
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [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)
示例2: date_range
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [as 别名]
def date_range(start_date, end_date, step=5):
"""Create a range generator for dates.
Given a start date and end date make an generator that returns the next date
in the range with the given interval.
"""
if isinstance(start_date, str):
start_date = parser.parse(start_date)
if isinstance(end_date, str):
end_date = parser.parse(end_date)
dates = rrule(freq=DAILY, dtstart=start_date, until=end_date, interval=step)
for date in dates:
yield date.date()
if end_date not in dates:
yield end_date.date()
示例3: ubuntu_url
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [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_)
示例4: day_blocks
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [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
示例5: _getWhen
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [as 别名]
def _getWhen(self, offset, numDays=1):
retval = ""
if self.freq == DAILY:
retval = self.__getDailyWhen()
elif self.freq == WEEKLY:
retval = self.__getWeeklyWhen(offset)
elif self.freq == MONTHLY:
retval = self.__getMonthlyWhen(offset)
elif self.freq == YEARLY:
retval = self.__getYearlyWhen(offset)
if numDays >= 2:
retval += " "+_("for {n} days").format(n=numDays)
if self.until:
until = self.until + dt.timedelta(days=offset)
retval += " "+_("(until {when})").format(when=dateShortFormat(until))
return retval
示例6: get_workdays
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [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()
示例7: generate_cdm_data_for_course
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [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
示例8: days_back_list
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [as 别名]
def days_back_list(days_back):
end_date = prev_day(datetime.datetime.now())
start_date = days_from(end_date, abs(days_back) * -1)
return [day for day in rrule(DAILY, dtstart=start_date, until=end_date)]
示例9: seed_course_daily_metrics_for_course
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [as 别名]
def seed_course_daily_metrics_for_course(course_id):
end_date = LAST_DAY
start_date = days_from(end_date, -DAYS_BACK)
for dt in rrule(DAILY, dtstart=start_date, until=end_date):
if VERBOSE:
print('populating day {} for course {}'.format(dt, course_id))
cdm, created = pipeline_cdm.CourseDailyMetricsLoader(course_id).load(
date_for=dt, force_update=True)
示例10: seed_site_daily_metrics
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [as 别名]
def seed_site_daily_metrics(data=None):
"""
Run seed_course_daily_metrics first
Then, for each date for which we have a CDM record
"""
end_date = LAST_DAY
start_date = days_from(end_date, -DAYS_BACK)
for dt in rrule(DAILY, dtstart=start_date, until=end_date):
pipeline_sdm.SiteDailyMetricsLoader().load(
site=get_site(),
date_for=dt, force_update=True)
示例11: generate_sdm_series
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [as 别名]
def generate_sdm_series(site, first_day, last_day):
return [SiteDailyMetricsFactory(site=site, date_for=dt)
for dt in rrule(DAILY, dtstart=first_day, until=last_day)]
示例12: create_student_module_test_data
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [as 别名]
def create_student_module_test_data(start_date, end_date):
'''
NOTE: There are many combinations of unique students, courses, and student
state. We're going to start with a relatively simple set
1. A single course
2. A single set per student (learner)
3. a small number of students to reduce test run time
If we create a record per day then we can work off of a unique datapoint
per day
'''
student_modules = []
user = UserFactory()
course_overview = CourseOverviewFactory()
for dt in rrule(DAILY, dtstart=start_date, until=end_date):
student_modules.append(StudentModuleFactory(
student=user,
course_id=course_overview.id,
created=dt,
modified=dt,
))
# we'll return everything we create
return dict(
user=user,
course_overview=course_overview,
student_modules=student_modules,
)
示例13: create_site_daily_metrics_data
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [as 别名]
def create_site_daily_metrics_data(site, start_date, end_date):
'''
NOTE: We can generalize this and the `create_course_daily_metrics_data`
function with considering that the course mertrics creation method can
assign a course id. When we become site-aware, then the site metrics will
also need to be able to assign a site identifier
'''
def incr_func(key):
return dict(
cumulative_active_user_count=2,
todays_active_user_count=2,
total_user_count=5,
course_count=1,
total_enrollment_count=3,
).get(key, 0)
# Initial values
data = dict(
cumulative_active_user_count=50,
todays_active_user_count=10,
total_user_count=5,
course_count=5,
total_enrollment_count=100,
)
metrics = []
for dt in rrule(DAILY, dtstart=start_date, until=end_date):
metrics.append(SiteDailyMetricsFactory(
date_for=dt,
site=site,
**data))
data.update(
{key: val + incr_func(key) for key, val in data.iteritems()})
return metrics
示例14: create_course_daily_metrics_data
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [as 别名]
def create_course_daily_metrics_data(site, start_date, end_date, course_id=None):
'''
Creates a daily sequence of CourseDailyMetrics objects
If course_id is provided as a parameter, then all CourseDailyMetrics objects
will have that course_id. This is useful for testing time series for a
specific course. Otherwise FactoryBoy assigns the course id in the
``tests.factories`` module
'''
# Initial values
data = dict(
enrollment_count=2,
active_learners_today=1,
average_progress=0.5,
average_days_to_complete=10,
num_learners_completed=3
)
# keys and the values to increment by
incr_data = dict(
enrollment_count=3,
active_learners_today=2,
average_progress=0,
average_days_to_complete=0,
num_learners_completed=1
)
if course_id:
data['course_id'] = course_id
metrics = []
for dt in rrule(DAILY, dtstart=start_date, until=end_date):
metrics.append(CourseDailyMetricsFactory(
date_for=dt,
site=site,
**data))
# This only updates the keys that are present in the incr_data dict
data.update(
{key: data[key] + incr_data[key] for key in incr_data.keys()})
return metrics
示例15: create_users_joined_over_time
# 需要导入模块: from dateutil import rrule [as 别名]
# 或者: from dateutil.rrule import DAILY [as 别名]
def create_users_joined_over_time(site, is_multisite, start_date, end_date):
"""
Creates users. Each user joins on a succesive date between the dates
pass as arguments
"""
users = []
for dt in rrule(DAILY, dtstart=start_date, until=end_date):
user = UserFactory(date_joined=dt)
if is_multisite:
orgs = get_organizations_for_site(site)
assert orgs.count() == 1
UserOrganizationMappingFactory(user=user, organization=orgs[0])
users.append(user)
return users