def get_state(self, duration): '''Run any necessary calculations on the data collected from the logs and return a list of metric objects.''' metrics = [] if duration > 0: metrics += [MetricObject(counter, self.counts[counter]/duration) for counter in self.counts] for time_name in self.times: values = self.times[time_name]['values'] unit = self.times[time_name]['unit'] metrics.append(MetricObject(time_name+'.mean', stats_helper.find_mean(values), unit)) metrics.append(MetricObject(time_name+'.median', stats_helper.find_median(values), unit)) metrics += [MetricObject('%s.%sth_percentile' % (time_name,percentile), stats_helper.find_percentile(values,int(percentile)), unit) for percentile in self.percentiles] return metrics
def test_90th_1_to_15_noncontiguous(self): self.assertAlmostEqual(stats_helper.find_percentile([1,2,3,4,5,6,7,8,9,15],90), 9.6)
def test_90th_1_to_11(self): self.assertEqual(stats_helper.find_percentile([1,2,3,4,5,6,7,8,9,10,11],90), 10)
def test_90th_1_minus1(self): self.assertEqual(stats_helper.find_percentile([1,-1],90), 0.8)
def test_90th_1_2_3(self): self.assertEqual(stats_helper.find_percentile([1,2,3],90), 2.8)
def test_90th_1_2(self): self.assertEqual(stats_helper.find_percentile([1,2],90), 1.9)
def test_90th_0(self): self.assertEqual(stats_helper.find_percentile([0],90), 0)
def test_12th_0_to_9(self): self.assertEqual(stats_helper.find_percentile([0,1,2,3,4,5,6,7,8,9],12), 1.08)
def test_10th_1_to_3(self): self.assertEqual(stats_helper.find_percentile([1,2,3],10), 1.2)
def test_10th_0_to_10(self): self.assertEqual(stats_helper.find_percentile([0,1,2,3,4,5,6,7,8,9,10],10), 1)
def test_max_floats(self): self.assertEqual(stats_helper.find_percentile([0,0.1,1.5,100],100), 100)
def test_max_0_to_11(self): self.assertEqual(stats_helper.find_percentile([0,1,2,3,4,5,6,7,8,9,10,11],100), 11)
def test_max_0_to_6(self): self.assertEqual(stats_helper.find_percentile([0,1,2,3,4,5,6],100), 6)
def test_max_0_to_3(self): self.assertEqual(stats_helper.find_percentile([0,1,2,3],100), 3)
def test_max_0(self): self.assertEqual(stats_helper.find_percentile([0],100), 0)