-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.py
83 lines (69 loc) · 2.81 KB
/
analysis.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
# -*- coding: utf-8 -*-
import pprint
import json
import time
from datetime import datetime
pp = pprint.PrettyPrinter(indent=4)
def findStepsInRange(start, end, file):
pass
def findStepsByMonth():
# load the steps file
file = 'exports/dataset-1638116329.json'
with open(file) as f:
data = json.load(f)
# search the file for each month
for i in range(12):
month = i+1
if month < 12:
# set the start of the month for the current year
start_of_month = datetime.now().date().replace(month=month, day=1)
next_month = datetime.now().date().replace(month=month+1, day=1)
month_name = start_of_month.strftime("%B")
# convert date ns timestamp
start_timestamp = datetime(
start_of_month.year,
start_of_month.month,
start_of_month.day, 0, 0).timestamp()* 1000000000
next_timestamp = datetime(
next_month.year,
next_month.month,
next_month.day, 0, 0).timestamp()* 1000000000
# find the sum of steps in that month
steps = sum(d['value'][0]['intVal'] for d in data['point'] if start_timestamp < int(d['startTimeNanos']) < next_timestamp)
print( month_name, steps)
print(f"average per day: {int(steps/30)}")
elif month == 12:
# just find the rest
start_of_month = datetime.now().date().replace(month=month, day=1)
month_name = start_of_month.strftime("%B")
start_timestamp = datetime(
start_of_month.year,
start_of_month.month,
start_of_month.day, 0, 0).timestamp()* 1000000000
steps = sum(d['value'][0]['intVal'] for d in data['point'] if start_timestamp < int(d['startTimeNanos']))
print( month_name, steps)
print(f"average per day: {int(steps/30)}")
def main():
pass
def test():
file = 'exports/dataset-1638111837.json'
with open(file) as f:
data = json.load(f)
start_of_month = datetime.now().date().replace(month=1, day=1)
next_month = datetime.now().date().replace(month=2, day=1)
# ns timestamp
start_timestamp = int(datetime(
start_of_month.year,
start_of_month.month,
start_of_month.day, 0, 0).timestamp()* 1000000000)
next_timestamp = int(datetime(
next_month.year,
next_month.month,
next_month.day, 0, 0).timestamp()* 1000000000)
# if start_timestamp < d['startTimeNanos'] < next_timestamp:
# pass
steps = sum(d['value'][0]['intVal'] for d in data['point'] if start_timestamp < int(d['startTimeNanos']) < next_timestamp)
print(next_month.strftime("%B"))
print(steps)
if __name__ == '__main__':
findStepsByMonth()