-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-withings-csv.py
132 lines (101 loc) · 3.84 KB
/
parse-withings-csv.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import csv
import os, sys
import json
import datetime as dt
import pytz
with open('/Users/chi/Code/WithingsImport/activities.csv') as csvfile:
dialect = csv.Sniffer().sniff(csvfile.read(1024))
csvfile.seek(0)
reader = csv.DictReader(csvfile)
# define variables
jahr = 0
e_anz = 0
e_dist = 0
c_anz = 0
c_dist = 0
w_anz = 0
r_anz = 0
r_dist = 0
h_anz = 0
h_dist = 0
wa_anz = 0
wa_dist = 0
for row in reader:
activity_data = json.loads(row['Data'])
try:
distance = activity_data["manual_distance"]
if distance < 1: distance = activity_data["distance"]
pjahr = jahr
zeit = row['von']
jahr = zeit[0:4]
monat = zeit[5:7]
tag = zeit[8:10]
# print jahr, monat, tag, row['Activity type'], (distance / 1000)
# creating the results
if jahr == pjahr:
if row['Activity type'] == "Elliptical":
e_dist = e_dist + distance
e_anz = e_anz + 1
if "Cycling" in row['Activity type'] :
c_dist = c_dist + distance
c_anz = c_anz + 1
if row['Activity type'] == "Weights":
w_anz = w_anz + 1
if row['Activity type'] == "Running":
r_dist = r_dist + distance
r_anz = r_anz + 1
if row['Activity type'] == "Hiking":
h_dist = h_dist + distance
h_anz = h_anz + 1
if row['Activity type'] == "Walking":
wa_dist = wa_dist + distance
wa_anz = wa_anz + 1
else:
print pjahr
print "Elliptical :",e_anz,"/",(e_dist / 1000)
print "Cycling :",c_anz,"/",(c_dist / 1000)
print "Running :",r_anz,"/",(r_dist / 1000)
print "Weights :",w_anz
print "Hiking :",h_anz,"/",(h_dist / 1000)
print "walking :",wa_anz,"/",(wa_dist / 1000)
print
e_anz = 0
e_dist = 0
c_anz = 0
c_dist = 0
r_anz = 0
r_dist = 0
w_anz = 0
h_anz = 0
h_dist = 0
wa_anz = 0
wa_dist = 0
if row['Activity type'] == "Elliptical":
e_dist = e_dist + distance
e_anz = e_anz + 1
if "Cycling" in row['Activity type']:
c_dist = c_dist + distance
c_anz = c_anz + 1
if row['Activity type'] == "Weights":
w_anz = w_anz + 1
if row['Activity type'] == "Running":
r_dist = r_dist + distance
r_anz = r_anz + 1
if row['Activity type'] == "Hiking":
h_dist = h_dist + distance
h_anz = h_anz + 1
if row['Activity type'] == "Walking":
wa_dist = wa_dist + distance
wa_anz = wa_anz + 1
except KeyError:
if row['Activity type'] == "Elliptical":
e_anz = e_anz + 1
if "Cycling" in row['Activity type']:
c_anz = c_anz + 1
if row['Activity type'] == "Weights":
w_anz = w_anz + 1
print jahr
print "Elliptical :",e_anz,"/",(e_dist / 1000)
print "Cycling :",c_anz,"/",(c_dist / 1000)
print "Running :",r_anz,"/",(r_dist / 1000)
print "Weights :",w_anz