Skip to content

Commit 3ac12e7

Browse files
committed
Fix the bug of step intraday features when INCLUDE_ZERO_STEP_ROWS is False
1 parent 1520a1e commit 3ac12e7

File tree

1 file changed

+6
-10
lines changed
  • src/features/fitbit_steps_intraday/rapids

1 file changed

+6
-10
lines changed

src/features/fitbit_steps_intraday/rapids/main.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,18 @@ def rapids_features(sensor_data_files, time_segment, provider, filter_data_by_se
8787

8888
intraday_features_to_compute = intraday_features_to_compute_steps + intraday_features_to_compute_sedentarybout + intraday_features_to_compute_activebout
8989

90+
# exclude rows when the total step count is ZERO during the whole day
91+
if (not steps_intraday_data.empty) and (not include_zero_step_rows):
92+
dailycountstep = steps_intraday_data.groupby(["local_date"])[["steps"]].sum()
93+
zerocountdates = dailycountstep[dailycountstep["steps"] == 0].index.tolist()
94+
steps_intraday_data = steps_intraday_data[~steps_intraday_data["local_date"].isin(zerocountdates)]
95+
9096
# extract features from intraday features
9197
steps_intraday_features = pd.DataFrame(columns=["local_segment"] + intraday_features_to_compute)
9298
if not steps_intraday_data.empty:
9399
steps_intraday_data = filter_data_by_segment(steps_intraday_data, time_segment)
94100

95101
if not steps_intraday_data.empty:
96102
steps_intraday_features = extractStepsFeaturesFromIntradayData(steps_intraday_data, threshold_active_bout, intraday_features_to_compute_steps, intraday_features_to_compute_sedentarybout, intraday_features_to_compute_activebout, steps_intraday_features)
97-
98-
# exclude rows when the total step count is ZERO during the whole day
99-
if not include_zero_step_rows:
100-
steps_intraday_features.index = steps_intraday_features["local_segment"].apply(lambda segment: segment.split("#")[1][:10])
101-
102-
steps_intraday_features["dailycountstep"] = steps_intraday_data.groupby(["local_date"])["steps"].sum()
103-
steps_intraday_features = steps_intraday_features.query("dailycountstep != 0")
104-
105-
del steps_intraday_features["dailycountstep"]
106-
steps_intraday_features.reset_index(drop=True, inplace=True)
107103

108104
return steps_intraday_features

0 commit comments

Comments
 (0)