mirror of
https://github.com/This-weiyuqing/mi-fitness-health.git
synced 2026-10-18 03:03:49 +08:00
feat: sync spo2 stress and abnormal heart beat
This commit is contained in:
1 parent
b532ee652d
commit
0ff3dd1c82
8 files changed
+596
-3
No files matched your search
@@ -301,6 +301,62 @@ class QueryService:
|
||||
return samples[:limit]
|
||||
return samples
|
||||
|
||||
|
||||
def get_spo2_samples(
|
||||
self,
|
||||
start_date: str,
|
||||
end_date: str,
|
||||
limit: int | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
records = self.db.query_spo2_samples(self.user_id, start_date, end_date)
|
||||
samples = [
|
||||
{
|
||||
"timestamp": record["timestamp"],
|
||||
"spo2_pct": record["spo2_pct"],
|
||||
}
|
||||
for record in records
|
||||
]
|
||||
return samples[:limit] if limit is not None else samples
|
||||
|
||||
def get_stress_samples(
|
||||
self,
|
||||
start_date: str,
|
||||
end_date: str,
|
||||
level: str | None = None,
|
||||
limit: int | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
records = self.db.query_stress_samples(self.user_id, start_date, end_date)
|
||||
samples = []
|
||||
for record in records:
|
||||
if level and record.get("level") != level:
|
||||
continue
|
||||
samples.append(
|
||||
{
|
||||
"timestamp": record["timestamp"],
|
||||
"stress_score": record["stress_score"],
|
||||
"level": record["level"],
|
||||
}
|
||||
)
|
||||
return samples[:limit] if limit is not None else samples
|
||||
|
||||
def get_abnormal_heart_beat_events(
|
||||
self,
|
||||
start_date: str,
|
||||
end_date: str,
|
||||
limit: int | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
records = self.db.query_abnormal_heart_beat_events(self.user_id, start_date, end_date)
|
||||
events = [
|
||||
{
|
||||
"event_id": record["event_id"],
|
||||
"start_at": record["start_at"],
|
||||
"end_at": record["end_at"],
|
||||
"duration_seconds": record["duration_seconds"],
|
||||
}
|
||||
for record in records
|
||||
]
|
||||
return events[:limit] if limit is not None else events
|
||||
|
||||
def get_data_coverage(self, data_types: list[str] | None = None) -> list[dict[str, Any]]:
|
||||
"""Get data coverage information."""
|
||||
coverage = self.db.get_data_coverage(self.user_id)
|
||||
|
||||
Reference in new issue
Block a user