fix: Zuordnungen zuverlässig speichern und Mengen-Varianten zusammenfassen
Mapping bleibt erhalten, auch wenn der Nährwert-Rebuild länger dauert. Offene Liste führt 1 ml/2 ml Olivenöl als ein Lebensmittel. Dazu JSON-Sicherung, eigener Katalogeintrag und Gramm-pro-Einheit. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
86f15e6957
commit
c1873a47b1
17 files changed
+875
-54
No files matched your search
@@ -0,0 +1,42 @@
|
||||
from data_layer.food_knowledge import (
|
||||
BUNDLE_FORMAT,
|
||||
parse_food_knowledge_bundle,
|
||||
portable_mapping,
|
||||
)
|
||||
|
||||
|
||||
def test_parse_rejects_unknown_format():
|
||||
try:
|
||||
parse_food_knowledge_bundle({"format": "other", "version": 1})
|
||||
except ValueError as e:
|
||||
assert "Mitai-Zuordnungsdatei" in str(e)
|
||||
else:
|
||||
raise AssertionError("expected ValueError")
|
||||
|
||||
|
||||
def test_parse_accepts_bundle():
|
||||
data = parse_food_knowledge_bundle({
|
||||
"format": BUNDLE_FORMAT,
|
||||
"version": 1,
|
||||
"mappings": [],
|
||||
"recipes": [],
|
||||
})
|
||||
assert data["version"] == 1
|
||||
|
||||
|
||||
def test_portable_mapping_drops_ids():
|
||||
row = portable_mapping({
|
||||
"id": 99,
|
||||
"food_id": "uuid-here",
|
||||
"source_system": "fddb",
|
||||
"source_name_raw": "Haferflocken, Großblatt",
|
||||
"source_name_normalized": "haferflocken großblatt",
|
||||
"bls_code": "C131000",
|
||||
"food_name_de": "Hafer roh",
|
||||
"catalog_kind": "official_bls",
|
||||
"external_key": None,
|
||||
})
|
||||
assert "id" not in row
|
||||
assert "food_id" not in row
|
||||
assert row["bls_code"] == "C131000"
|
||||
assert row["source_name_raw"] == "Haferflocken, Großblatt"
|
||||
@@ -1,17 +1,35 @@
|
||||
from csv_parser.executor import guess_nutrition_item_fields
|
||||
from data_layer.food_mapping import normalize_food_name, parse_quantity_g
|
||||
from data_layer.food_mapping import merge_unmapped_rows, normalize_food_name, parse_quantity, parse_quantity_g
|
||||
from data_layer.nutrition_items import macros_differ
|
||||
|
||||
|
||||
def test_normalize_strips_leading_quantity():
|
||||
assert normalize_food_name("50 g Hähnchen") == "hähnchen"
|
||||
assert normalize_food_name(" Vollmilch 3,5% ") == "vollmilch 3.5%"
|
||||
assert normalize_food_name("1 ml Olivenöl") == normalize_food_name("2 ml Olivenöl") == "olivenöl"
|
||||
|
||||
|
||||
def test_merge_unmapped_collapses_quantity_variants():
|
||||
rows = merge_unmapped_rows([
|
||||
{"source_name_raw": "1 ml Olivenöl", "source_name_normalized": "1 ml olivenöl", "count": 3, "kind": "diary"},
|
||||
{"source_name_raw": "2 ml Olivenöl", "source_name_normalized": "2 ml olivenöl", "count": 1, "kind": "diary"},
|
||||
])
|
||||
assert len(rows) == 1
|
||||
assert rows[0]["source_name_normalized"] == "olivenöl"
|
||||
assert rows[0]["count"] == 4
|
||||
assert rows[0]["source_name_raw"].lower() == "olivenöl"
|
||||
|
||||
|
||||
def test_parse_quantity_g():
|
||||
assert parse_quantity_g("150 g") == 150.0
|
||||
assert parse_quantity_g("150") == 150.0
|
||||
assert parse_quantity_g("1 kg") == 1000.0
|
||||
assert parse_quantity_g("5 ml") == 5.0
|
||||
assert parse_quantity_g("1 Stück") is None
|
||||
assert parse_quantity_g("1 Stück", 60) == 60.0
|
||||
assert parse_quantity_g("2 EL") == 30.0
|
||||
assert parse_quantity("1 Scheibe")["needs_unit_map"] is True
|
||||
assert parse_quantity("2 EL")["unit"] == "el"
|
||||
|
||||
|
||||
def test_guess_fddb_bezeichnung_without_template_mapping():
|
||||
|
||||
Reference in new issue
Block a user