-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrick_network.py
50 lines (43 loc) · 1.56 KB
/
trick_network.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import json
import firebase_admin
from firebase_admin import db
from firebase_admin import credentials
from trick import Trick
types = ['basics', 'manipulation', 'power', 'releases', 'multiples', 'impossible']
cred = credentials.Certificate('key.json')
firebase_admin.initialize_app(cred, {
'databaseURL' : 'https://project-5641153190345267944.firebaseio.com/'
})
root = db.reference()
# Add a new user under /users.
tricktionary = []
tricknames = []
id = 0
for i in range(5):
tricks = root.child('tricks').child(str(i)).child('subs').get()
for trick in tricks:
if True:#trick['type'] == 'Multiples':
t = Trick(id, i, trick['name'], types.index(str(trick['type']).lower()))
prereqs = []
for prereq in trick['prerequisites']:
if prereq['name'] != 'None':
prereqs.append(prereq['name'])
t.prereqs = prereqs
id += 1
tricktionary.append(t)
tricknames.append(t.name)
print(t.name)
nodes = [] ; links = []
for trick in tricktionary:
nodes.append({'group': trick.type, 'name': trick.name})
if trick.prereqs:
for prereq in trick.prereqs:
try:
print(trick.prereqs)
links.append({'source': trick.id, 'target': tricknames.index(str(prereq)), 'value': 1})
except Exception as e:
print(str(prereq), 'not in list')
graph = {'nodes': nodes, 'links': links}
os.remove('static/graph.json')
with open('static/graph.json','w') as f: json.dump(graph,f)