Skip to content

Commit

Permalink
refactor: adjust overall estimates using weekdaily
Browse files Browse the repository at this point in the history
Adjust overall estimates based on representative week by converting to
"weekdaily" first.
  • Loading branch information
chanshing committed Dec 6, 2023
1 parent 381c2fc commit 998ceab
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/stepcount/stepcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 998ceab

Please sign in to comment.