@@ -0,0 +1,28 @@
|
||||
"""Канонические indicator_key для нутриентов компонента (без fuzzy-match)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from app.lab.norm_catalog import NORM_HEADER_TO_KEY
|
||||
|
||||
|
||||
def augment_with_indicator_keys(data: dict[str, Any] | None) -> dict[str, float]:
|
||||
"""Дублирует значения под slug indicator_key."""
|
||||
if not data:
|
||||
return {}
|
||||
out: dict[str, float] = {}
|
||||
for raw_key, raw_val in data.items():
|
||||
try:
|
||||
out[str(raw_key)] = float(raw_val)
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
for header, indicator_key in NORM_HEADER_TO_KEY.items():
|
||||
if header in out and indicator_key not in out:
|
||||
out[indicator_key] = out[header]
|
||||
return out
|
||||
|
||||
|
||||
def canonicalize_for_storage(data: dict[str, Any] | None) -> dict[str, float]:
|
||||
"""При записи в EAV: slug indicator_key + исходный заголовок."""
|
||||
return augment_with_indicator_keys(data)
|
||||
Reference in New Issue
Block a user