本文整理汇总了Python中isoweek.Week.weeks_of_year方法的典型用法代码示例。如果您正苦于以下问题:Python Week.weeks_of_year方法的具体用法?Python Week.weeks_of_year怎么用?Python Week.weeks_of_year使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类isoweek.Week
的用法示例。
在下文中一共展示了Week.weeks_of_year方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate_weekly_sales
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import weeks_of_year [as 别名]
def calculate_weekly_sales(item_collection_ids, user_tz, year):
"""
Calculates sales per week for items in the given set of item_collection_ids in a given year,
in the user's timezone.
"""
ordered_week_sales = OrderedDict()
for year_week in Week.weeks_of_year(year):
ordered_week_sales[year_week.week] = 0
start_at = isoweek_datetime(year, 1, user_tz)
end_at = isoweek_datetime(year + 1, 1, user_tz)
week_sales = db.session.query('sales_week', 'sum').from_statement(db.text('''
SELECT EXTRACT(WEEK FROM ordered_at AT TIME ZONE 'UTC' AT TIME ZONE :timezone)
AS sales_week, SUM(final_amount) AS sum
FROM line_item INNER JOIN item on line_item.item_id = item.id
WHERE status IN :statuses AND item_collection_id IN :item_collection_ids
AND ordered_at AT TIME ZONE 'UTC' AT TIME ZONE :timezone >= :start_at
AND ordered_at AT TIME ZONE 'UTC' AT TIME ZONE :timezone < :end_at
GROUP BY sales_week ORDER BY sales_week;
''')).params(timezone=user_tz, statuses=tuple([LINE_ITEM_STATUS.CONFIRMED, LINE_ITEM_STATUS.CANCELLED]),
start_at=start_at, end_at=end_at, item_collection_ids=tuple(item_collection_ids)).all()
for week_sale in week_sales:
ordered_week_sales[int(week_sale.sales_week)] = week_sale.sum
return ordered_week_sales
示例2: __init__
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import weeks_of_year [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
start = self.fields['start']
cw = Week.thisweek()
choices = [str(w + cw.week) for w in Week.weeks_of_year(cw.year)]
start.choices = zip(choices, choices)
start.initial = cw+1
示例3: __init__
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import weeks_of_year [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
cw = Week.withdate(Week.thisweek().sunday() + relativedelta(days=9))
start = self.fields['start']
start_choices = [str(w + cw.week - 1) for w in Week.weeks_of_year(cw.year)]
start_date_choices = ['%s (%s %s)' % ((w + cw.week - 1).day(settings.DELIVERY_DAY_OF_WEEK).strftime('%d-%m-%Y'), _('Week'), (w + cw.week - 1).week) for w in Week.weeks_of_year(cw.year)]
start.choices = zip(start_choices, start_date_choices)
start.initial = cw
for field in ['size', 'frequency', 'duration', 'start']:
self.fields[field].widget.attrs['class'] = 'slidebar-select'
for field in ['criterias', 'receive_only_once']:
self.fields[field].widget.attrs['class'] = 'checkbox-select'
for field in ['carrier']:
self.fields[field].widget.attrs['class'] = 'radio-select'
示例4: _
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import weeks_of_year [as 别名]
from mailbox import models as mm
FREQUENCY_CHOICES = (
(1, _('Once a week')),
(2, _('Every two weeks')),
(3, _('Every three weeks')),
(4, _('Once a month (4 weeks)')),
(8, _('Every two months (8 weeks)')),
(13, _('Once a quarter (13 weeks)')),
(26, _('Every 6 months (26 weeks)')),
)
FREQUENCY_DEFAULT = 2
__weeks = []
for y in range(settings.START_YEAR, Week.thisweek().year+2): __weeks += Week.weeks_of_year(y)
WEEKS_CHOICES = [(str(w), '%s (%s %s)' % (w.day(settings.DELIVERY_DAY_OF_WEEK).strftime('%d-%m-%Y'), _('Week'), w.week)) for w in __weeks]
class Thematic(models.Model):
name = models.CharField(_('name'), max_length=100)
body = models.TextField(_('body'), blank=True)
size = models.ForeignKey('Size', verbose_name=_('size'), null=True, blank=True)
locked_size = models.BooleanField(_('locked size'), default=False)
carrier = models.ForeignKey('Carrier', verbose_name=_('carrier'), null=True, blank=True)
locked_carrier = models.BooleanField(_('locked carrier'), default=False)
receive_only_once = models.BooleanField(_('receive only once'), default=False)
locked_receive_only_once = models.BooleanField(_('locked receive only once'), default=False)
frequency = models.PositiveIntegerField(_('frequency'), max_length=2, choices=FREQUENCY_CHOICES, help_text=_('Delivery made sure Tuesday'), null=True, blank=True)
locked_frequency = models.BooleanField(_('locked frequency'), default=False)
start_duration = models.CharField(_('start duration'), max_length=7, choices=WEEKS_CHOICES,
help_text=_('Here is the beginnig week of the duration.'),
示例5: test_constructors
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import weeks_of_year [as 别名]
def test_constructors(self):
w = Week(2011,1)
self.assertTrue(w)
self.assertEqual(str(w), "2011W01")
w = Week(2011,0)
self.assertEqual(str(w), "2010W52")
w = Week(2011,-1)
self.assertEqual(str(w), "2010W51")
w = Week(2011,52)
self.assertEqual(str(w), "2011W52")
w = Week(2011,53)
self.assertEqual(str(w), "2012W01")
w = Week(2011,54)
self.assertEqual(str(w), "2012W02")
w = Week(2009,51)
self.assertEqual(str(w), "2009W51")
w = Week(2009,52)
self.assertEqual(str(w), "2009W52")
w = Week(2009,53)
self.assertEqual(str(w), "2009W53")
w = Week(2009,54)
self.assertEqual(str(w), "2010W01")
w = Week.thisweek()
self.assertTrue(w)
w = Week.fromordinal(1)
self.assertEqual(str(w), "0001W01")
w = Week.fromordinal(2)
self.assertEqual(str(w), "0001W02")
w = Week.fromordinal(521723)
self.assertEqual(str(w), "9999W52")
w = Week.fromstring("2011W01")
self.assertEqual(str(w), "2011W01")
w = Week.fromstring("2011-W01")
self.assertEqual(str(w), "2011W01")
from datetime import date
w = Week.withdate(date(2011, 5, 17))
self.assertEqual(str(w), "2011W20")
weeks = list(Week.weeks_of_year(2009))
self.assertEqual(len(weeks), 53)
self.assertEqual(weeks[0], Week(2009,1))
self.assertEqual(weeks[-1], Week(2009,53))
weeks = list(Week.weeks_of_year(2011))
self.assertEqual(len(weeks), 52)
self.assertEqual(weeks[0], Week(2011,1))
self.assertEqual(weeks[-1], Week(2011,52))
self.assertEqual(Week.last_week_of_year(2009), Week(2009, 53))
self.assertEqual(Week.last_week_of_year(2010), Week(2010, 52))
self.assertEqual(Week.last_week_of_year(2011), Week(2011, 52))
self.assertEqual(Week.last_week_of_year(9999), Week(9999, 52))
self.assertRaises(ValueError, lambda: Week(0, 0))
self.assertRaises(ValueError, lambda: Week.fromstring("0000W00"))
self.assertRaises(ValueError, lambda: Week.fromstring("foo"))
self.assertRaises(ValueError, lambda: Week.fromordinal(-1))
self.assertRaises(ValueError, lambda: Week.fromordinal(0))
self.assertRaises(ValueError, lambda: Week.fromordinal(521724))
self.assertRaises(ValueError, lambda: Week.last_week_of_year(0))
self.assertRaises(ValueError, lambda: Week.last_week_of_year(10000))