本文整理汇总了Python中r2.lib.utils.to_date函数的典型用法代码示例。如果您正苦于以下问题:Python to_date函数的具体用法?Python to_date怎么用?Python to_date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了to_date函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_campaign_table
def make_campaign_table(self):
campaigns = PromoCampaign._by_link(self.thing._id)
total_budget = 0
total_spent = 0
total_paid_impressions = 0
total_impressions = 0
total_clicks = 0
self.campaign_table = []
for camp in campaigns:
if not is_launched_campaign(camp):
continue
is_live = camp.is_live_now()
self.has_early_campaign |= is_early_campaign(camp)
self.has_live_campaign |= is_live
history = get_billable_traffic(camp)
impressions, clicks = 0, 0
for date, (imp, click) in history:
impressions += imp
clicks += click
start = to_date(camp.start_date).strftime('%Y-%m-%d')
end = to_date(camp.end_date).strftime('%Y-%m-%d')
target = camp.target.pretty_name
location = camp.location_str
spent = promote.get_spent_amount(camp)
is_active = self.campaign and self.campaign._id36 == camp._id36
url = '/traffic/%s/%s' % (self.thing._id36, camp._id36)
is_total = False
row = self.make_campaign_table_row(camp._id36, start, end, target,
location, camp.bid, spent,
camp.impressions,
impressions, clicks, is_live,
is_active, url, is_total)
self.campaign_table.append(row)
total_budget += camp.bid
total_spent += spent
total_paid_impressions += camp.impressions
total_impressions += impressions
total_clicks += clicks
# total row
start = '---'
end = '---'
target = '---'
location = '---'
is_live = False
is_active = not self.campaign
url = '/traffic/%s' % self.thing._id36
is_total = True
row = self.make_campaign_table_row(_('total'), start, end, target,
location, total_budget, total_spent,
total_paid_impressions, total_impressions,
total_clicks, is_live, is_active, url,
is_total)
self.campaign_table.append(row)
示例2: add
def add(cls,
thing,
idx,
sr,
start_date,
end_date,
total_weight,
finished=False):
start_date = to_date(start_date)
end_date = to_date(end_date)
# anything set by the user will be uniform weighting
duration = max((end_date - start_date).days, 1)
weight = total_weight / duration
d = start_date
while d < end_date:
cls._new(
thing,
idx,
sr,
d,
thing.author_id,
weight,
weight,
finished=finished)
d += datetime.timedelta(1)
示例3: get_scheduled_impressions
def get_scheduled_impressions(sr_name, start_date, end_date):
# FIXME: mock function for development
start_date = to_date(start_date)
end_date = to_date(end_date)
ndays = (end_date - start_date).days
scheduled = OrderedDict()
for i in range(ndays):
date = (start_date + timedelta(i))
scheduled[date] = random.randint(0, 100) # FIXME: fakedata
return scheduled
示例4: get_available_impressions
def get_available_impressions(sr_name, start_date, end_date, fuzzed=False):
# FIXME: mock function for development
start_date = to_date(start_date)
end_date = to_date(end_date)
available = inventory.get_predicted_by_date(sr_name, start_date, end_date)
scheduled = get_scheduled_impressions(sr_name, start_date, end_date)
for date in scheduled:
available[date] = int(available[date] - (available[date] * scheduled[date] / 100.)) # DELETEME
#available[date] = max(0, available[date] - scheduled[date]) # UNCOMMENTME
if fuzzed:
available[date] = fuzz_impressions(available[date])
return available
示例5: get_campaigns
def get_campaigns(cls, start, end=None, author_id=None):
start = to_date(start)
q = cls.query()
if end:
end = to_date(end)
q = q.filter(and_(cls.date >= start, cls.date < end))
else:
q = q.filter(cls.date == start)
if author_id:
q = q.filter(cls.account_id == author_id)
return list(q)