Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100478
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: subclassing collections.Counter |
| Date | 2015-12-15 10:55 -0700 |
| Message-ID | <mailman.38.1450202154.22044.python-list@python.org> (permalink) |
| References | <567036A5.6050205@gmail.com> <CALwzidnifp20WayShDXTGJ-PxdCk0LeZVb-o9fTQzFCN6i1dUQ@mail.gmail.com> <56703DE8.7010609@gmail.com> <CALwzid=DCLsBXMtWYtScP9pZYzXPU6rRFa8hzC3GD8hru3iQSQ@mail.gmail.com> <56705129.2020004@gmail.com> |
On Tue, Dec 15, 2015 at 10:43 AM, Pavlos Parissis
<pavlos.parissis@gmail.com> wrote:
>> If you want your metrics container to act like a dict, then my
>> suggestion would be to just use a dict, with pseudo-collections for
>> the values as above.
>>
>
> If I understood you correctly, you are saying store all metrics in a
> dict and have a counter key as well to store the times metrics are
> pushed in, and then have a function to do the math. Am I right?
That would work, although I was actually thinking of something like this:
class SummedMetric:
def __init__(self):
self.total = 0
self.count = 0
@property
def average(self):
return self.total / self.count
def add(self, value):
self.total += value
self.count += 1
metrics = {}
for metric_name in all_metrics:
metrics[metric_name] = SummedMetric()
For averaged metrics, look at metrics['f'].average, otherwise look at
metrics['f'].total.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: subclassing collections.Counter Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-15 10:55 -0700
csiph-web