def test_get_call_with_date_range_and_interval(self): """We can specify a date range and interval for call data.""" level = 'global' call_stats_client = stats_client.CallStatsClient(level) # Setup client params, converting datetimes to timestamps. start_datetime = TIME_OF_LAST_EVENT - timedelta(hours=96) start_timestamp = calendar.timegm(start_datetime.utctimetuple()) end_timestamp = calendar.timegm(TIME_OF_LAST_EVENT.utctimetuple()) data = call_stats_client.timeseries(start_time_epoch=start_timestamp, end_time_epoch=end_timestamp, interval='days') days, values = zip(*data) # The interval comes back from qsstats with an extra day at the # beginning. expected_datetimes = [TIME_OF_LAST_EVENT - timedelta(hours=96), TIME_OF_LAST_EVENT - timedelta(hours=72), TIME_OF_LAST_EVENT - timedelta(hours=48), TIME_OF_LAST_EVENT - timedelta(hours=24), TIME_OF_LAST_EVENT] # TIME_OF_LAST_EVENT has hour/minute info -- we need to clear that out # because the qsstats datetimes are, in this example, days only. expected_days = [dt.replace(hour=0, minute=0) for dt in expected_datetimes] # And finally we have to convert these to millisecond timestamps. expected_timestamps = [int(1e3 * calendar.timegm(dt.utctimetuple())) for dt in expected_days] self.assertSequenceEqual(expected_timestamps, days) # We expect 70 total calls to be sent and we can work out how they will # accumulate day-to-day by knowing that we added one usage event of # each type per hour, counting back from 8:15a (see _add_usage_events # for the timings). expected_values = [0+0, 0+0, 0+7, 21+24, 9+9] self.assertSequenceEqual(expected_values, values)
def test_get_specific_call_kind(self): """We can get timeseries call data of a specific kind.""" level = 'global' kind = 'local_call' call_stats_client = stats_client.CallStatsClient(level) data = call_stats_client.timeseries(kind=kind) local_call_count = sum(zip(*data)[1]) self.assertEqual(self.number_of_local_calls_bts_two, local_call_count)
def test_get_specific_call_kind_duration(self): """We can get timeseries billsec data of a specific kind.""" level = 'global' kind = 'local_call' call_stats_client = stats_client.CallStatsClient(level) data = call_stats_client.timeseries(kind=kind, aggregation='duration') local_billsec = sum(zip(*data)[1]) expected_duration = BILLSEC * self.number_of_local_calls_bts_two self.assertEqual(expected_duration, local_billsec)
def test_get_network_call_timeseries(self): """We can get timeseries call stats for a specific network.""" level = 'network' level_id = self.network_a.id call_stats_client = stats_client.CallStatsClient(level, level_id=level_id) data = call_stats_client.timeseries() network_call_count = sum(zip(*data)[1]) # Only BTS one is on Network A so we should only see that BTS's events. self.assertEqual(self.number_of_outside_calls_bts_one, network_call_count)
def test_get_network_billsec_timeseries(self): """We can get timeseries billsec stats for a specific network.""" level = 'network' level_id = self.network_a.id call_stats_client = stats_client.CallStatsClient(level, level_id=level_id) data = call_stats_client.timeseries(aggregation='duration') network_duration = sum(zip(*data)[1]) # Only BTS one is on Network A so we should only see that BTS's events. expected_duration = ( BILLSEC * self.number_of_outside_calls_bts_one) self.assertEqual(expected_duration, network_duration)
def test_get_global_call_timeseries(self): """We can get a timeseries of call count data with the call client.""" level = 'global' call_stats_client = stats_client.CallStatsClient(level) data = call_stats_client.timeseries() # The timeseries method returns a list and the last value should be # (millisecond timestamp, <total number of call UsageEvents>). Since # we haven't specified a timespan or a kind, the client will return all # of the data. timestamp, _ = data[-1] self.assertTrue(isinstance(timestamp, int)) call_count = sum(zip(*data)[1]) expected_number_of_calls = (self.number_of_outside_calls_bts_one + self.number_of_local_calls_bts_two) self.assertEqual(expected_number_of_calls, call_count)
def test_global_billsec_timeseries(self): """We can get a timeseries of billsec data.""" level = 'global' call_stats_client = stats_client.CallStatsClient(level) data = call_stats_client.timeseries(aggregation='duration') # The timeseries method returns a list and the last value should be # (millisecond timestamp, <duration of call UsageEvents>). Since we # haven't specified a timespan or a kind, the client will return all # of the data. We can do some initial checks on the types and the sum # of these values. timestamp, _ = data[-1] self.assertTrue(isinstance(timestamp, int)) total_duration = sum(zip(*data)[1]) expected_duration = ( BILLSEC * self.number_of_outside_calls_bts_one + BILLSEC * self.number_of_local_calls_bts_two) self.assertEqual(expected_duration, total_duration)