Cue/scales

Example on how to do dynamic stats collection?

joeshaw opened this issue · 2 comments

(I couldn't find any other good contact info for this software, so I'm filing it as an issue. It would be good to add an example of this to the README. :)

What's the best way to dynamically define stats to collect? I don't know until runtime what the different possible values are. (Think different "types" that are pulled from a database at runtime.)

data = get_data()
stats = scales.collection('/data', *[scales.IntStat(n) for n in names])

for d in data:
    # increment the count
    setattr(stats, d, getattr(stats, d) + 1)

This is kinda ugly but it works. Is there a nicer way?

You're probably looking for an IntDictStat - I added an example in the Class Stats section of the README. Thanks!

Awesome! This is exactly what I was looking for, thank you.