In [21]:
import seaborn as sns
import json
import itertools
cats = ['A','B','C','D','E']
subcats = ['W','X','Y','Z']
combos = list(itertools.product(cats,subcats))
In [68]:
from numpy.random import weibull
Nsamples = 5000
k=4.5
x = weibull(k,(Nsamples,))*3 - random.rand(Nsamples,)*5 + 10
hist(x);
def rand_x():
return x[rand()*len(x)]
print rand_x()
print [rand_x() for i in range(5)]
In [84]:
#cats = ['A','B','C','D','E']
#subcats = ['W','X','Y','Z']
#combos = list(itertools.product(cats,subcats))
cc = [5,3,9,2,5]
ss = [4,1,2,10,3]
cs = list(itertools.product(cc,ss))
dd = {}
for combo, product in zip(combos,cs):
dd[combo[0]+combo[1]] = product[0]*product[1]
print dd
In [86]:
tree = {}
tree['name'] = 'root'
children = []
for iic,cat in enumerate(cats):
child = {}
child['name'] = cat
grandchildren = []
for iis,subcat in enumerate(subcats):
grandchild = {}
grandchild['name'] = cat+subcat
grandchild['magnitude'] = dd[cat+subcat]
grandchildren.append(grandchild)
child['children'] = grandchildren
children.append(child)
tree['children'] = children
with open('slider_tree.json','w') as f:
json.dump(tree,f,
sort_keys=True,
indent=4,
separators=(',', ': '))
print "Done with json export."
In [90]:
print json.dumps(tree,
sort_keys=False,
indent=4,
separators=(',', ': '))
In [ ]:
In [ ]: