def presence_start_end_per_weekday_view(user_id):
    """
    Returns list of mean presence 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)
        abort(404)

    weekdays = start_end_group_by_weekday(data[user_id])
    mean_start_end = mean_start_end_by_weekday(weekdays)
    result = [(calendar.day_abbr[weekday], start_end[0], start_end[1])
              for weekday, start_end in enumerate(mean_start_end)]
    return result
def presence_start_end_per_weekday_view(user_id):
    """
    Returns list of mean presence 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)
        abort(404)

    weekdays = start_end_group_by_weekday(data[user_id])
    mean_start_end = mean_start_end_by_weekday(weekdays)
    result = [
        (calendar.day_abbr[weekday], start_end[0], start_end[1])
        for weekday, start_end in enumerate(mean_start_end)
    ]
    return result
 def test_mean_start_end_grouped_by_weekday(self):
     """
     Test mean start/end presence by workday.
     """
     data = utils.get_data()
     grouped_by_weekday = utils.start_end_group_by_weekday(data[11])
     mean_start_end_by_day = utils.mean_start_end_by_weekday(
         grouped_by_weekday)
     self.assertEqual(mean_start_end_by_day, [
         ['09:12:14', '15:54:17'],
         ['09:19:50', '13:55:54'],
         ['09:13:26', '16:15:27'],
         ['09:53:22', '16:16:26'],
         ['13:16:56', '15:04:02'],
         ['00:00:00', '00:00:00'],
         ['00:00:00', '00:00:00'],
     ])
 def test_start_end_grouped_by_weekday(self):
     """
     Test grouped start end presence by weekday.
     """
     data = utils.get_data()
     grouped_by_weekday = utils.start_end_group_by_weekday(data[11])
     self.assertDictEqual(
         grouped_by_weekday,
         {
             0: {'start': [33134], 'end': [57257]},
             1: {'start': [33590], 'end': [50154]},
             2: {'start': [33206], 'end': [58527]},
             3: {'start': [37116, 34088], 'end': [60085, 57087]},
             4: {'start': [47816], 'end': [54242]},
             5: {'start': [], 'end': []},
             6: {'start': [], 'end': []},
         }
     )
 def test_mean_start_end_grouped_by_weekday(self):
     """
     Test mean start/end presence by workday.
     """
     data = utils.get_data()
     grouped_by_weekday = utils.start_end_group_by_weekday(data[11])
     mean_start_end_by_day = utils.mean_start_end_by_weekday(
         grouped_by_weekday)
     self.assertEqual(
         mean_start_end_by_day,
         [
             ['09:12:14', '15:54:17'],
             ['09:19:50', '13:55:54'],
             ['09:13:26', '16:15:27'],
             ['09:53:22', '16:16:26'],
             ['13:16:56', '15:04:02'],
             ['00:00:00', '00:00:00'],
             ['00:00:00', '00:00:00'],
         ]
     )
 def test_start_end_grouped_by_weekday(self):
     """
     Test grouped start end presence by weekday.
     """
     data = utils.get_data()
     grouped_by_weekday = utils.start_end_group_by_weekday(data[11])
     self.assertDictEqual(
         grouped_by_weekday, {
             0: {
                 'start': [33134],
                 'end': [57257]
             },
             1: {
                 'start': [33590],
                 'end': [50154]
             },
             2: {
                 'start': [33206],
                 'end': [58527]
             },
             3: {
                 'start': [37116, 34088],
                 'end': [60085, 57087]
             },
             4: {
                 'start': [47816],
                 'end': [54242]
             },
             5: {
                 'start': [],
                 'end': []
             },
             6: {
                 'start': [],
                 'end': []
             },
         })