-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyear_end.py
46 lines (40 loc) · 1.52 KB
/
year_end.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
import json
def get_subtotals(exercise):
points = 0
kgs = 0
km = 0
for workout_set in exercise:
points += workout_set['points']
try:
unit = workout_set['effort1_metric_unit']['name']
except TypeError: # first key was None
continue
if unit == 'Reps':
weight = 0 if not workout_set['effort0_metric'] else workout_set['effort0_metric']
reps = workout_set['effort1']
multiplier = workout_set['action']['multiplier']
kgs += weight * reps * multiplier
elif unit == 'Kilometers':
km += workout_set['effort1_metric']
elif unit == 'Meters':
km += workout_set['effort1_metric'] / 1000.0
else:
print('unexpected unit: {}'.format(unit))
return {"points": points, "kgs": kgs, "km": km}
try:
myHistoryFile = "fitocracyHistory.json"
with open(myHistoryFile) as file:
decoded = json.load(file)
year = "2015"
totals = {"points": 0, "kgs": 0, "km": 0}
for identifier in decoded:
for item in decoded[identifier]['data']:
if year in item['date']:
subtotals = get_subtotals(item['actions'])
totals = {key: totals[key] + subtotals[key] for key in totals}
print("{} totals:\n".format(year))
print("{} points".format(totals["points"]))
print("{0:.0f} kgs".format(totals["kgs"]))
print("{0:.2f} km".format(totals["km"]))
finally:
input("\npress enter to continue")