Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

fix: made mean computations more robust for posture tracker #62

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions client/models/pose_detection/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"pose_landmarker_lite.task"
)

PERIOD_SECONDS = 10
NO_USER = -1
STOP_CHILD = -2

Expand Down Expand Up @@ -139,15 +140,15 @@ def track_posture(self) -> None:
self._save_period()

def _save_period(self) -> None:
if time.time() - self._start_time <= 60:
if time.time() - self._start_time <= PERIOD_SECONDS:
return

period_end = datetime.now()
posture = Posture(
id_=None,
user_id=self.user_id,
prop_good=statistics.mean(self._posture_scores),
prop_in_frame=statistics.mean(self._in_frames),
prop_good=_safe_mean(self._posture_scores),
prop_in_frame=_safe_mean(self._in_frames),
period_start=self._period_start,
period_end=period_end,
)
Expand Down Expand Up @@ -257,3 +258,10 @@ def _run_posture(
tracker.user_id = parent_msg

tracker.track_posture()


def _safe_mean(data: list[bool]) -> float:
mean = 0.0
if len(data) != 0:
mean = statistics.mean(data)
return mean