diff --git a/src/stepcount/stepcount.py b/src/stepcount/stepcount.py index 611b5d1..f378faa 100644 --- a/src/stepcount/stepcount.py +++ b/src/stepcount/stepcount.py @@ -158,20 +158,34 @@ def _sum(x): total = np.round(Y.agg(_sum)) # total steps hourly = Y.resample('H').agg(_sum).round().rename('Steps') # steps, hourly daily = Y.resample('D').agg(_sum).round().rename('Steps') # steps, daily - daily_avg = np.round(daily.mean()) - daily_med = np.round(daily.median()) - daily_min = np.round(daily.min()) - daily_max = np.round(daily.max()) + if not adjust_estimates: + daily_avg = np.round(daily.mean()) + daily_med = np.round(daily.median()) + daily_min = np.round(daily.min()) + daily_max = np.round(daily.max()) + else: + weekdaily = daily.groupby(daily.index.weekday).mean() + daily_avg = np.round(weekdaily.mean()) + daily_med = np.round(weekdaily.median()) + daily_min = np.round(weekdaily.min()) + daily_max = np.round(weekdaily.max()) # walking dt = pd.Timedelta(infer_freq(Y.index)).seconds W = Y.mask(~Y.isna(), Y >= steptol) total_walk = np.round(W.agg(_sum) * dt / 60) daily_walk = (W.resample('D').agg(_sum) * dt / 60).round().rename('Walk(mins)') - daily_walk_avg = np.round(daily_walk.mean()) - daily_walk_med = np.round(daily_walk.median()) - daily_walk_min = np.round(daily_walk.min()) - daily_walk_max = np.round(daily_walk.max()) + if not adjust_estimates: + daily_walk_avg = np.round(daily_walk.mean()) + daily_walk_med = np.round(daily_walk.median()) + daily_walk_min = np.round(daily_walk.min()) + daily_walk_max = np.round(daily_walk.max()) + else: + weekdaily_walk = daily_walk.groupby(daily_walk.index.weekday).mean() + daily_walk_avg = np.round(weekdaily_walk.mean()) + daily_walk_med = np.round(weekdaily_walk.median()) + daily_walk_min = np.round(weekdaily_walk.min()) + daily_walk_max = np.round(weekdaily_walk.max()) def _max(x, n=1): return x.nlargest(n, keep='all').mean()