-
Notifications
You must be signed in to change notification settings - Fork 1
/
activity_rings_summary.py
62 lines (41 loc) · 2.53 KB
/
activity_rings_summary.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
import argparse
import pathlib
import pandas as pd
def ring_closed(x):
return 1 if x >= 0 else 0
def all_rings_closed(x):
return 1 if x == 3 else 0
def activity_rings_summary(csv_data_path: str):
activity_summary = pd.read_csv(f"{csv_data_path}/activity-summary.csv", parse_dates=['dateComponents'])
activity_rings_data = activity_summary.loc[:, ["dateComponents", "activeEnergyBurned", "appleExerciseTime"]]
# Apple Health has a row of data with 0 activeEnergyBurned calories on the day before the Apple Watch was activated
activity_rings_data = activity_rings_data[activity_rings_data["activeEnergyBurned"] > 0]
activity_rings_data["energy_goal_delta"] = activity_summary["activeEnergyBurned"] - activity_summary[
"activeEnergyBurnedGoal"]
activity_rings_data["apple_exercise_time_goal_delta"] = activity_summary["appleExerciseTime"] - activity_summary[
"appleExerciseTimeGoal"]
activity_rings_data["apple_stand_hours_goal_delta"] = activity_summary["appleStandHours"] - activity_summary[
"appleStandHoursGoal"]
activity_rings_data = activity_rings_data.rename(
columns={
'dateComponents': 'date',
'activeEnergyBurned': 'active_energy_burned',
'appleExerciseTime': 'apple_exercise_time'
})
activity_rings_data["energy_ring_closed"] = activity_rings_data["energy_goal_delta"].map(ring_closed)
activity_rings_data["exercise_ring_closed"] = activity_rings_data["apple_exercise_time_goal_delta"].map(
ring_closed)
activity_rings_data["stand_ring_closed"] = activity_rings_data["apple_stand_hours_goal_delta"].map(ring_closed)
activity_rings_data["rings_closed"] = activity_rings_data["energy_ring_closed"] + activity_rings_data[
"exercise_ring_closed"] + activity_rings_data["stand_ring_closed"]
activity_rings_data["all_rings_closed"] = activity_rings_data["rings_closed"].map(all_rings_closed)
activity_rings_data.to_csv(f"{csv_data_path}/activity-rings-summary.csv", index=False)
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog=__file__,
description='Generates summary datasets of cumulative quantity sample types.')
parser.add_argument('-partition-date', type=str, required=True, help='partition-date subfolder')
args = parser.parse_args()
home = pathlib.Path.home()
partition_date = args.partition_date
csv_data_path = f"{home}/small-data/apple-health-csv/full-extract/{partition_date}"
activity_rings_summary(csv_data_path)