From 84068ab33cc546fc6bb18168a77f148d14ff5a96 Mon Sep 17 00:00:00 2001 From: Meng Li <34143965+Meng6@users.noreply.github.com> Date: Wed, 28 Oct 2020 13:07:35 -0400 Subject: [PATCH] Update fitbit_parse_steps.py: add summary data --- src/data/fitbit_parse_steps.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/data/fitbit_parse_steps.py b/src/data/fitbit_parse_steps.py index 653a2e77..f0d067f2 100644 --- a/src/data/fitbit_parse_steps.py +++ b/src/data/fitbit_parse_steps.py @@ -4,6 +4,11 @@ import numpy as np from datetime import datetime, timezone from math import trunc +STEPS_SUMMARY_COLUMNS = ("device_id", + "steps_rapids_intradaycountallsteps", + "local_date_time", + "timestamp") + STEPS_INTRADAY_COLUMNS = ("device_id", "steps", "local_date_time", @@ -14,12 +19,23 @@ def parseStepsData(steps_data): if steps_data.empty: return pd.DataFrame(), pd.DataFrame(columns=STEPS_INTRADAY_COLUMNS) device_id = steps_data["device_id"].iloc[0] - records_intraday = [] + records_summary, records_intraday = [], [] # Parse JSON into individual records for record in steps_data.fitbit_data: record = json.loads(record) # Parse text into JSON + + # Parse summary data curr_date = datetime.strptime( record["activities-steps"][0]["dateTime"], "%Y-%m-%d") + + row_summary = (device_id, + record["activities-steps"][0]["value"], + curr_date, + 0) + + records_summary.append(row_summary) + + # Parse intraday data dataset = record["activities-steps-intraday"]["dataset"] for data in dataset: d_time = datetime.strptime(data["time"], '%H:%M:%S').time() @@ -32,7 +48,7 @@ def parseStepsData(steps_data): records_intraday.append(row_intraday) - return pd.DataFrame(data=[], columns=["local_date_time", "timestamp"]), pd.DataFrame(data=records_intraday, columns=STEPS_INTRADAY_COLUMNS) + return pd.DataFrame(data=records_summary, columns=STEPS_SUMMARY_COLUMNS), pd.DataFrame(data=records_intraday, columns=STEPS_INTRADAY_COLUMNS) table_format = snakemake.params["table_format"] timezone = snakemake.params["timezone"]