-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
save_json.py
58 lines (50 loc) · 2.24 KB
/
save_json.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
51
52
53
54
55
56
57
58
import json
from mascots import MASCOTS
class Simulation:
def __init__(self, num_sims, results_dict, points_dict, teams):
conferences_list = []
for conference, standings in results_dict.items():
teams_list = []
conf_name = standings['name']
for nickname, standings in standings['results'].items():
position = standings['points'].index(max(standings['points']))
win_prob = float(standings['points'][0]) / float(num_sims)
seed_prob = float(standings['points'][position]) / \
float(num_sims)
points = points_dict[conference]['points'][nickname]
name = teams(nickname).name
mascot = MASCOTS[nickname]
team_dict = {
"name": name,
"abbreviation": nickname,
"mascot": mascot,
"standings": standings['points'],
"projectedWins": float(points) / float(num_sims),
"seedProbability": seed_prob,
"winProbability": win_prob
}
teams_list.append(team_dict)
conferences_list.append({'teams': teams_list,
'conferenceAbbreviation': conference,
'conferenceName': conf_name,
'latest': True,
'num_sims': num_sims})
self.simulation = {
"conferences": conferences_list
}
def save_predictions_json(predictions, output_file):
prediction_json = []
for prediction in predictions:
prediction_json.append(prediction)
prediction_json = {"predictions": prediction_json}
with open(output_file, 'w') as fp:
json.dump(prediction_json, fp)
def save_simulation(num_sims, results_dict, points_dict, output_file, teams):
simulation = Simulation(num_sims, results_dict, points_dict,
teams).__dict__
with open(output_file, 'w') as fp:
json.dump(simulation, fp)
return simulation
def save_json(json_data, output_file):
with open(output_file, 'w') as fp:
json.dump(json_data, fp)