def test_interval(self): di = DI().parse('2012-01-01-2012-02-01') self.assertEqual(di.dates(), [ datetime.date(2012, 1, 1) + datetime.timedelta(i) for i in xrange(31) ]) self.assertRaises(NotImplementedError, di.next) self.assertRaises(NotImplementedError, di.prev)
def test_year(self): di = DI().parse('2012') self.assertEqual(di.dates(), [ datetime.date(2012, 1, 1) + datetime.timedelta(i) for i in range(366) ]) self.assertEqual(di.next().dates(), [ datetime.date(2013, 1, 1) + datetime.timedelta(i) for i in range(365) ]) self.assertEqual(di.prev().dates(), [ datetime.date(2011, 1, 1) + datetime.timedelta(i) for i in range(365) ]) self.assertEqual(str(di), '2012')
def test_month(self): di = DI().parse('2012-01') self.assertEqual(di.dates(), [ datetime.date(2012, 1, 1) + datetime.timedelta(i) for i in range(31) ]) self.assertEqual(di.next().dates(), [ datetime.date(2012, 2, 1) + datetime.timedelta(i) for i in range(29) ]) self.assertEqual(di.prev().dates(), [ datetime.date(2011, 12, 1) + datetime.timedelta(i) for i in range(31) ]) self.assertEqual(str(di), '2012-01')
def __init__(self, *args, **kwargs): super(UserVideoViewingByDateTask, self).__init__(*args, **kwargs) overwrite_from_date = self.interval.date_b - datetime.timedelta( days=self.overwrite_n_days) self.overwrite_interval = DateIntervalParameter().parse('{}-{}'.format( overwrite_from_date, self.interval.date_b))
def requires_hadoop(self): # We want to pass in the historical data as well as the output of CourseEnrollmentEventsTask to the hadoop job. # CourseEnrollmentEventsTask returns the marker as output, so we need custom logic to pass the output # of CourseEnrollmentEventsTask as actual hadoop input to this job. path_selection_interval = DateIntervalParameter().parse('{}-{}'.format( self.interval.date_a, self.overwrite_from_date, )) path_selection_task = PathSelectionByDateIntervalTask( source=[self.course_enrollment_events_root], interval=path_selection_interval, pattern=[CourseEnrollmentEventsTask.FILEPATH_PATTERN], expand_interval=datetime.timedelta(0), date_pattern='%Y-%m-%d', ) requirements = { 'path_selection_task': path_selection_task, } if self.overwrite_n_days > 0: requirements['downstream_input_tasks'] = self.requires_local( ).downstream_input_tasks() return requirements
def test_use_interval(self): interval = DateIntervalParameter().parse('2013-01-01') interval_start = None LastCountryOfUser( interval=interval, interval_start=interval_start, )
def test_week(self): # >>> datetime.date(2012, 1, 1).isocalendar() # (2011, 52, 7) # >>> datetime.date(2012, 12, 31).isocalendar() # (2013, 1, 1) di = DI().parse('2011-W52') self.assertEqual(di.dates(), [ datetime.date(2011, 12, 26) + datetime.timedelta(i) for i in range(7) ]) self.assertEqual(di.next().dates(), [ datetime.date(2012, 1, 2) + datetime.timedelta(i) for i in range(7) ]) self.assertEqual(str(di), '2011-W52') di = DI().parse('2013-W01') self.assertEqual(di.dates(), [ datetime.date(2012, 12, 31) + datetime.timedelta(i) for i in range(7) ]) self.assertEqual(di.prev().dates(), [ datetime.date(2012, 12, 24) + datetime.timedelta(i) for i in range(7) ]) self.assertEqual(str(di), '2013-W01')
def requires_local(self): if self.overwrite_n_days == 0: return [] overwrite_interval = DateIntervalParameter().parse('{}-{}'.format( self.overwrite_from_date, self.interval.date_b)) return CourseEnrollmentEventsTask( interval=overwrite_interval, source=self.source, pattern=self.pattern, n_reduce_tasks=self.n_reduce_tasks, warehouse_path=self.warehouse_path, overwrite=True, )
def test_week(self): # >>> datetime.date(2012, 1, 1).isocalendar() # (2011, 52, 7) # >>> datetime.date(2012, 12, 31).isocalendar() # (2013, 1, 1) di = DI().parse('2011-W52') self.assertEqual(di.dates(), [datetime.date(2011, 12, 26) + datetime.timedelta(i) for i in range(7)]) self.assertEqual(di.next().dates(), [datetime.date(2012, 1, 2) + datetime.timedelta(i) for i in range(7)]) self.assertEqual(str(di), '2011-W52') di = DI().parse('2013-W01') self.assertEqual(di.dates(), [datetime.date(2012, 12, 31) + datetime.timedelta(i) for i in range(7)]) self.assertEqual(di.prev().dates(), [datetime.date(2012, 12, 24) + datetime.timedelta(i) for i in range(7)]) self.assertEqual(str(di), '2013-W01')
def test_date(self): di = DI().parse('2012-01-01') self.assertEqual(di.dates(), [datetime.date(2012, 1, 1)]) self.assertEqual(di.next().dates(), [datetime.date(2012, 1, 2)]) self.assertEqual(di.prev().dates(), [datetime.date(2011, 12, 31)]) self.assertEqual(str(di), '2012-01-01')
def test_hours(self): d = DI().parse('2015') self.assertEqual(len(list(d.hours())), 24 * 365)
def test_interval(self): di = DI().parse('2012-01-01-2012-02-01') self.assertEqual(di.dates(), [datetime.date(2012, 1, 1) + datetime.timedelta(i) for i in range(31)]) self.assertRaises(NotImplementedError, di.next) self.assertRaises(NotImplementedError, di.prev) self.assertEquals(di.to_string(), '2012-01-01-2012-02-01')
def test_year(self): di = DI().parse('2012') self.assertEqual(di.dates(), [datetime.date(2012, 1, 1) + datetime.timedelta(i) for i in range(366)]) self.assertEqual(di.next().dates(), [datetime.date(2013, 1, 1) + datetime.timedelta(i) for i in range(365)]) self.assertEqual(di.prev().dates(), [datetime.date(2011, 1, 1) + datetime.timedelta(i) for i in range(365)]) self.assertEqual(str(di), '2012')
def test_month(self): di = DI().parse('2012-01') self.assertEqual(di.dates(), [datetime.date(2012, 1, 1) + datetime.timedelta(i) for i in range(31)]) self.assertEqual(di.next().dates(), [datetime.date(2012, 2, 1) + datetime.timedelta(i) for i in range(29)]) self.assertEqual(di.prev().dates(), [datetime.date(2011, 12, 1) + datetime.timedelta(i) for i in range(31)]) self.assertEqual(str(di), '2012-01')
def test_hours(self): d = DI().parse('2015') self.assertEquals(len(list(d.hours())), 24 * 365)