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

Commit

Permalink
Merge pull request #62 from LimaoC/mitch-pi-posture
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchellJC authored Sep 21, 2024
2 parents 9c9ddae + c3a81e8 commit 620c444
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit 620c444

Please sign in to comment.