def test_ignore_start_end(self): """When start and end are None, only times between logs are compared.""" delta = datetime.timedelta(seconds=1) logs = self.create_logs(self.user1, delta=delta) period = TimePeriod(None, None) rates = UasTelemetry.rates(self.user1, [period]) self.assertSequenceEqual((1, 1), rates)
def test_constant_rate(self): """Rates computed correctly.""" delta = datetime.timedelta(seconds=1) logs = self.create_logs(self.user1, delta=delta) period = self.consistent_period(logs, delta) rates = UasTelemetry.rates(self.user1, [period]) self.assertSequenceEqual((1, 1), rates)
def test_no_data(self): log = UasTelemetry.last_for_user(self.user1) self.assertEqual(None, log) logs = UasTelemetry.by_user(self.user1) self.assertEqual(len(logs), 0) logs = UasTelemetry.by_time_period(self.user1, []) self.assertEqual(len(logs), 0) log_rates = UasTelemetry.rates(self.user1, []) self.assertTupleEqual(log_rates, (None, None))
def test_provided_logs(self): """Rates computed with provided logs.""" delta = datetime.timedelta(seconds=1) used_logs = self.create_logs(self.user1, delta=delta) unused_logs = self.create_logs(self.user1, delta=delta) period = self.consistent_period(used_logs, delta) rates = UasTelemetry.rates(self.user1, [period], time_period_logs=[used_logs]) self.assertSequenceEqual((1, 1), rates)
def test_multiple_periods(self): """Multiple periods are combined without introducing errors.""" delta = datetime.timedelta(seconds=1) logs = [ self.create_logs(self.user1, start=self.year2000, delta=delta), self.create_logs(self.user1, start=self.year2001, delta=delta), ] periods = [self.consistent_period(l, delta) for l in logs] rates = UasTelemetry.rates(self.user1, periods) self.assertSequenceEqual((1, 1), rates)
def test_different_deltas(self): """Sets of logs are combined for overall rates.""" delta = datetime.timedelta(seconds=1) logs = [ self.create_logs(self.user1, num=1000, start=self.year2000, delta=delta), self.create_logs(self.user1, num=1000, start=self.year2001, delta=delta / 2), ] periods = [self.consistent_period(l, delta) for l in logs] rates = UasTelemetry.rates(self.user1, periods) self.assertAlmostEqual(1.0, rates[0]) # max self.assertAlmostEqual(0.75, rates[1], delta=0.001) # avg