rapids/src/features/fitbit_sleep_features.py

19 lines
1.1 KiB
Python
Raw Normal View History

import pandas as pd
2020-06-13 00:44:05 +02:00
from fitbit_sleep.fitbit_sleep_base import base_fitbit_sleep_features
import itertools
sleep_summary_data = pd.read_csv(snakemake.input["sleep_summary_data"])
2020-06-13 00:44:05 +02:00
requested_summary_features = snakemake.params["summary_features"]
requested_sleep_type = snakemake.params["sleep_types"]
day_segment = snakemake.params["day_segment"]
2020-06-13 00:44:05 +02:00
sleep_features = pd.DataFrame(columns=["local_date"])
2020-06-13 00:44:05 +02:00
sleep_features = sleep_features.merge(base_fitbit_sleep_features(sleep_summary_data, day_segment, requested_summary_features, requested_sleep_type), on="local_date", how="outer")
2020-06-13 00:44:05 +02:00
requested_features = ["".join(feature) for feature in itertools.product(requested_summary_features, requested_sleep_type)] if day_segment == "daily" else []
2020-06-13 00:44:05 +02:00
assert len(requested_features) + 1 == sleep_features.shape[1], "The number of features in the output dataframe (=" + str(sleep_features.shape[1]) + ") does not match the expected value (=" + str(len(requested_features)) + " + 1). Verify your fitbit sleep feature extraction functions"
2020-06-13 00:44:05 +02:00
sleep_features.to_csv(snakemake.output[0], index=False)