Add INCLUDE_ZERO_STEP_ROWS flag for step sensor

pull/95/head
Meng Li 2020-03-09 15:59:51 -04:00
parent 529d6e4bf8
commit b23bb0e402
3 changed files with 10 additions and 1 deletions

View File

@ -122,6 +122,7 @@ STEP:
SEDENTARY_BOUT: ["countsedentarybout", "maxdurationsedentarybout", "mindurationsedentarybout", "avgdurationsedentarybout", "stddurationsedentarybout"] SEDENTARY_BOUT: ["countsedentarybout", "maxdurationsedentarybout", "mindurationsedentarybout", "avgdurationsedentarybout", "stddurationsedentarybout"]
ACTIVE_BOUT: ["countactivebout", "maxdurationactivebout", "mindurationactivebout", "avgdurationactivebout", "stddurationactivebout"] ACTIVE_BOUT: ["countactivebout", "maxdurationactivebout", "mindurationactivebout", "avgdurationactivebout", "stddurationactivebout"]
THRESHOLD_ACTIVE_BOUT: 10 # steps THRESHOLD_ACTIVE_BOUT: 10 # steps
INCLUDE_ZERO_STEP_ROWS: True
METRICS_FOR_ANALYSIS: METRICS_FOR_ANALYSIS:
SOURCES: &sources ["phone_metrics", "fitbit_metrics", "phone_fitbit_metrics"] SOURCES: &sources ["phone_metrics", "fitbit_metrics", "phone_fitbit_metrics"]

View File

@ -168,7 +168,8 @@ rule fitbit_step_metrics:
metrics_all_steps = config["STEP"]["METRICS"]["ALL_STEPS"], metrics_all_steps = config["STEP"]["METRICS"]["ALL_STEPS"],
metrics_sedentary_bout = config["STEP"]["METRICS"]["SEDENTARY_BOUT"], metrics_sedentary_bout = config["STEP"]["METRICS"]["SEDENTARY_BOUT"],
metrics_active_bout = config["STEP"]["METRICS"]["ACTIVE_BOUT"], metrics_active_bout = config["STEP"]["METRICS"]["ACTIVE_BOUT"],
threshold_active_bout = config["STEP"]["THRESHOLD_ACTIVE_BOUT"] threshold_active_bout = config["STEP"]["THRESHOLD_ACTIVE_BOUT"],
include_zero_step_rows = config["STEP"]["INCLUDE_ZERO_STEP_ROWS"]
output: output:
"data/processed/{pid}/fitbit_step_{day_segment}.csv" "data/processed/{pid}/fitbit_step_{day_segment}.csv"
script: script:

View File

@ -8,6 +8,7 @@ all_steps = snakemake.params["metrics_all_steps"]
sedentary_bout = snakemake.params["metrics_sedentary_bout"] sedentary_bout = snakemake.params["metrics_sedentary_bout"]
active_bout = snakemake.params["metrics_active_bout"] active_bout = snakemake.params["metrics_active_bout"]
threshold_active_bout = snakemake.params['threshold_active_bout'] threshold_active_bout = snakemake.params['threshold_active_bout']
include_zero_step_rows = snakemake.params["include_zero_step_rows"]
#Read csv into a pandas dataframe #Read csv into a pandas dataframe
data = pd.read_csv(snakemake.input['steps_data'],parse_dates=['local_date_time']) data = pd.read_csv(snakemake.input['steps_data'],parse_dates=['local_date_time'])
@ -92,6 +93,12 @@ else:
if("stddurationactivebout" in active_bout): if("stddurationactivebout" in active_bout):
finalDataset["step_" + str(day_segment) + "_stddurationactivebout"] = statsMinutes[statsMinutes['active_sedentary']== 'active']['std'] finalDataset["step_" + str(day_segment) + "_stddurationactivebout"] = statsMinutes[statsMinutes['active_sedentary']== 'active']['std']
#Exclude data when the total step count is ZERO during the whole epoch
if not include_zero_step_rows:
finalDataset["sumallsteps_aux"] = resampledData["steps"].resample("D").sum()
finalDataset = finalDataset.query("sumallsteps_aux != 0")
del finalDataset["sumallsteps_aux"]
finalDataset.index.names = ['local_date'] finalDataset.index.names = ['local_date']
finalDataset.to_csv(snakemake.output[0]) finalDataset.to_csv(snakemake.output[0])