rename summarize to summarize_and_reset

This commit is contained in:
Job Evers-Meltzer 2016-10-18 16:49:31 -05:00
parent 7f800ce5bb
commit 229ed0d7dc
3 changed files with 6 additions and 6 deletions

View file

@ -44,7 +44,7 @@ class Manager(object):
self.analytics_api.track(heartbeat) self.analytics_api.track(heartbeat)
def _update_tracked_metrics(self): def _update_tracked_metrics(self):
should_send, value = self.track.summarize(constants.BLOB_BYTES_UPLOADED) should_send, value = self.track.summarize_and_reset(constants.BLOB_BYTES_UPLOADED)
if should_send: if should_send:
event = self.events_generator.metric_observed(constants.BLOB_BYTES_UPLOADED, value) event = self.events_generator.metric_observed(constants.BLOB_BYTES_UPLOADED, value)
self.analytics_api.track(event) self.analytics_api.track(event)

View file

@ -9,7 +9,7 @@ class Track(object):
def add_observation(self, metric, value): def add_observation(self, metric, value):
self.data[metric].append(value) self.data[metric].append(value)
def summarize(self, metric, op=sum): def summarize_and_reset(self, metric, op=sum):
"""Apply `op` on the current values for `metric`. """Apply `op` on the current values for `metric`.
This operation also resets the metric. This operation also resets the metric.

View file

@ -6,7 +6,7 @@ from twisted.trial import unittest
class TrackTest(unittest.TestCase): class TrackTest(unittest.TestCase):
def test_empty_summarize_is_None(self): def test_empty_summarize_is_None(self):
track = analytics.Track() track = analytics.Track()
_, result = track.summarize('a') _, result = track.summarize_and_reset('a')
self.assertEqual(None, result) self.assertEqual(None, result)
def test_can_get_sum_of_metric(self): def test_can_get_sum_of_metric(self):
@ -14,7 +14,7 @@ class TrackTest(unittest.TestCase):
track.add_observation('b', 1) track.add_observation('b', 1)
track.add_observation('b', 2) track.add_observation('b', 2)
_, result = track.summarize('b') _, result = track.summarize_and_reset('b')
self.assertEqual(3, result) self.assertEqual(3, result)
def test_summarize_resets_metric(self): def test_summarize_resets_metric(self):
@ -22,6 +22,6 @@ class TrackTest(unittest.TestCase):
track.add_observation('metric', 1) track.add_observation('metric', 1)
track.add_observation('metric', 2) track.add_observation('metric', 2)
track.summarize('metric') track.summarize_and_reset('metric')
_, result = track.summarize('metric') _, result = track.summarize_and_reset('metric')
self.assertEqual(None, result) self.assertEqual(None, result)