Example #1
0
    def test_database_insert_session(self):
        a = datetime(2017, 1, 1)
        b = datetime(2017, 1, 2)
        c = datetime(2017, 1, 3)

        event = Event(b, Active())
        self.database.insert_session_event(event)
        events = self.database.get_session_events()
        self.assertEqual(events, [event])

        spans = list(self.database.get_session_spans(a, c))
        self.assertEqual(spans, [Span(a, b, Inactive()), Span(b, c, Active())])
Example #2
0
 def test_compute_active_time_active(self):
     desk_span = Span(datetime.fromtimestamp(0),
                      datetime.fromtimestamp(1000), Down())
     session_span = Span(datetime.fromtimestamp(0),
                         datetime.fromtimestamp(1000), Active())
     self.assertEqual(
         stats.compute_active_time([session_span], [desk_span]),
         timedelta(seconds=1000))
Example #3
0
 def test_group_into_days_identity(self):
     spans = [
         Span(datetime(2017, 4, 12, 10, 0, 0),
              datetime(2017, 4, 12, 10, 30, 0), Active())
     ]
     flatten = lambda l: [item for sublist in l for item in sublist]
     daily_active_time = stats.compute_daily_active_time(spans)
     self.assertEqual(flatten(stats.group_into_days(daily_active_time)),
                      daily_active_time)
Example #4
0
def compute_active_time(session_spans, desk_spans):
    active_spans = spans.cut(
        desk_spans[-1].start,
        desk_spans[-1].end,
        session_spans)
    return spans.count(active_spans, Active(), timedelta(0))
Example #5
0
 def test_session_from_int(self):
     self.assertEqual(model.session_from_int(0), Inactive())
     self.assertEqual(model.session_from_int(1), Active())
     self.assertRaises(ValueError, model.session_from_int, 2)
Example #6
0
 def test_compute_daily_active_time_sum(self):
     spans = [
         Span(datetime(2017, 4, 12, 10, 0, 0),
              datetime(2017, 4, 12, 10, 30, 0), Active())
     ]
     self.assertEqual(sum(stats.compute_daily_active_time(spans)), 30)
Example #7
0
 def test_hardware_light_on(self):
     self.hardware.light(Active())
     self.gpio.output.assert_called_once_with(2, self.gpio.HIGH)