def test_group_by_weekday(self): """ Test groups entries by weekdays. """ self.assertEqual( utils.group_by_weekday(utils.get_data()[10]), [[], [30047], [24465], [23705], [], [], []], ) self.assertEqual( utils.group_by_weekday(utils.get_data()[11]), [[24123], [16564], [25321], [22969, 22999], [6426], [], []], )
def test_group_by_weekday(self): """ Test grouping presence entries by weekday. """ data = utils.get_data() correct_data = [[], [30047], [24465], [23705], [], [], []] self.assertEqual(utils.group_by_weekday(data[10]), correct_data)
def test_group_by_weekday(self): """ Test group by weekend. """ excepted_result = [[], [0], [17088], [10800], [], [], []] days = { datetime.date(2013, 9, 10): { 'end': datetime.time(0, 0, 0), 'start': datetime.time(0, 0, 0), }, datetime.date(2013, 9, 11): { 'end': datetime.time(17, 6, 28), 'start': datetime.time(12, 21, 40), }, datetime.date(2013, 9, 12): { 'end': datetime.time(23, 59, 59), 'start': datetime.time(20, 59, 59), } } data = utils.group_by_weekday(days) self.assertEqual(data, excepted_result) self.assertTrue( datetime.datetime.strptime( str(datetime.date(2013, 9, 12)), '%Y-%m-%d' ) )
def mean_time_weekday_view(user_id): """ Returns mean presence time of given user grouped by weekday. """ data = get_data() if user_id not in data: log.debug('User %s not found!', user_id) abort(404) weekdays = group_by_weekday(data[user_id]) result = [(calendar.day_abbr[weekday], mean(intervals)) for weekday, intervals in enumerate(weekdays)] return result
def presence_weekday_view(user_id): """ Returns total presence time of given user grouped by weekday. """ data = get_data() if user_id not in data: log.debug('User %s not found!', user_id) abort(404) weekdays = group_by_weekday(data[user_id]) result = [(calendar.day_abbr[weekday], sum(intervals)) for weekday, intervals in enumerate(weekdays)] result.insert(0, ('Weekday', 'Presence (s)')) return result
def mean_time_weekday_view(user_id): """ Returns mean presence time of given user grouped by weekday. """ data = get_data() if user_id not in data: log.debug('User %s not found!', user_id) return [] weekdays = group_by_weekday(data[user_id]) result = [ (calendar.day_abbr[weekday], mean(intervals)) for weekday, intervals in enumerate(weekdays) ] return result
def presence_weekday_view(user_id): """ Returns total presence time of given user grouped by weekday. """ data = get_data() if user_id not in data: log.debug('User %s not found!', user_id) return [] weekdays = group_by_weekday(data[user_id]) result = [ (calendar.day_abbr[weekday], sum(intervals)) for weekday, intervals in enumerate(weekdays) ] result.insert(0, ('Weekday', 'Presence (s)')) return result
def presence_start_end_view(user_id): """ Returns start and end time of given user grouped by weekday. """ data = get_data() if user_id not in data: log.debug('User %s not found!', user_id) return [] weekdays = group_by_weekday(data[user_id]) start_end_weekdays = group_by_start_end(data[user_id]) result = [( calendar.day_abbr[weekday], mean(start_end_weekdays[weekday]['start']), mean(start_end_weekdays[weekday]['end'])) for weekday, intervals in enumerate(weekdays) ] return result