39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from app.modules.zootech.lab.calc.nutrients import parse_num
|
|
from app.modules.zootech.lab.constants import NORM_COLUMN_ALIASES, RATION_QUALITY_INDICATORS
|
|
|
|
|
|
def merge_norms_from_profile(profile_data: Any, ration_type: str) -> dict[str, dict[str, float | None]]:
|
|
del ration_type
|
|
if not profile_data or not isinstance(profile_data, dict):
|
|
return {}
|
|
indicators = profile_data.get("indicators")
|
|
if isinstance(indicators, dict):
|
|
out: dict[str, dict[str, float | None]] = {}
|
|
for key, bounds in indicators.items():
|
|
if not isinstance(bounds, dict):
|
|
continue
|
|
out[str(key)] = {
|
|
"min": parse_num(bounds.get("min")),
|
|
"max": parse_num(bounds.get("max")),
|
|
}
|
|
return out
|
|
out = {}
|
|
for defn in RATION_QUALITY_INDICATORS:
|
|
key = defn["key"]
|
|
aliases = NORM_COLUMN_ALIASES.get(key)
|
|
if not aliases:
|
|
continue
|
|
for alias in aliases:
|
|
entry = profile_data.get(alias)
|
|
if isinstance(entry, dict):
|
|
out[key] = {
|
|
"min": parse_num(entry.get("min")),
|
|
"max": parse_num(entry.get("max")),
|
|
}
|
|
break
|
|
return out
|