Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Better name for mad_thing()
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmuller committed Oct 28, 2014
1 parent 30d868f commit fb3cc0a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions backdrop/core/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,16 @@ def timeseries(start, end, period, data, default):
def fill_group_by_permutations(start, end, period, data, default, group_by):

# Generate all permutations of group_by keys
def mad_thing(key):
def unique_values(key):
return set([d[key] for d in data])
possible_keys = {group_key: mad_thing(group_key) for group_key in group_by}
step_1 = {k: [(k, v) for v in possible_keys[k]] for k in possible_keys}
step_2 = list(itertools.product(*[step_1[x] for x in step_1]))
permutations = [dict(things) for things in step_2]

def all_group_by_permutations():
possible_keys = {group_key: unique_values(group_key) for group_key in group_by}
step_1 = {k: [(k, v) for v in possible_keys[k]] for k in possible_keys}
step_2 = list(itertools.product(*[step_1[x] for x in step_1]))
return [dict(item) for item in step_2]

permutations = all_group_by_permutations()

results = []
# for each time period (e.g. 1 week) in the period requested (e.g. 3 weeks)
Expand Down

0 comments on commit fb3cc0a

Please sign in to comment.