-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalizer.py
More file actions
45 lines (40 loc) · 1.56 KB
/
Copy pathnormalizer.py
File metadata and controls
45 lines (40 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from biometric_normalizer.schema import BiometricSnapshot, MaternalPhase
from biometric_normalizer.calibration import apply_pregnancy_calibration
from biometric_normalizer.registry import AdapterRegistry
import logging
logger = logging.getLogger(__name__)
class BiometricNormalizer:
def __init__(self, registry: AdapterRegistry):
self.registry = registry
async def ingest(
self,
source_device: str,
access_token: str,
start_date: str,
end_date: str,
phase: MaternalPhase | None = None,
gestational_week: int | None = None,
postpartum_week: int | None = None,
apply_calibration: bool = True,
) -> list[BiometricSnapshot]:
adapter = self.registry.get(source_device)
raw_records = await adapter.fetch(access_token, start_date, end_date)
snapshots = []
for raw in raw_records:
try:
snap = adapter.transform(
raw,
phase=phase,
gestational_week=gestational_week,
postpartum_week=postpartum_week,
)
if apply_calibration and phase in ("pregnant", "postpartum"):
snap = apply_pregnancy_calibration(snap)
snapshots.append(snap)
except Exception as e:
logger.warning(
f"[{source_device}] transform failed for record: {e}",
exc_info=True,
)
continue # never crash on bad device data
return snapshots