feat: Rezepte beim Zuordnen anlegen und offene Zutaten listen
Lebensmittel oder Rezept wählbar; gemappte Zutaten werden übernommen, offene erscheinen in der Liste. Dazu Fettgehalt-Suche, EPA-Stoffe, Rezept-CRUD und Wechsel bestehender Zuordnungen. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
132a364a3a
commit
a7e5511039
26 files changed
+1234
-147
No files matched your search
@@ -1,4 +1,25 @@
|
||||
from data_layer.food_suggest import collapse_key, score_name_match, suggest_batch, suggest_for_name
|
||||
from data_layer.food_suggest import (
|
||||
collapse_key,
|
||||
name_tokens,
|
||||
score_name_match,
|
||||
suggest_batch,
|
||||
suggest_for_name,
|
||||
)
|
||||
|
||||
|
||||
def _index(*foods):
|
||||
index = {"foods": [], "by_collapse": {}, "by_token": {}, "by_prefix": {}, "by_suffix": {}}
|
||||
for food in foods:
|
||||
food["_c"] = collapse_key(food["name_de"])
|
||||
food["_t"] = name_tokens(food["name_de"])
|
||||
if food["_c"]:
|
||||
index["by_collapse"].setdefault(food["_c"], []).append(food)
|
||||
index["by_prefix"].setdefault(food["_c"][:4], []).append(food)
|
||||
if len(food["_c"]) >= 4:
|
||||
index["by_suffix"].setdefault(food["_c"][-4:], []).append(food)
|
||||
for tok in food["_t"]:
|
||||
index["by_token"].setdefault(tok, []).append(food)
|
||||
return index
|
||||
|
||||
|
||||
def test_collapse_treats_space_as_same():
|
||||
@@ -63,3 +84,24 @@ def test_suggest_batch_dedupes_names():
|
||||
out = suggest_batch(_Cur(), None, ["Haferflocken", "Haferflocken", ""], limit=2)
|
||||
assert "Haferflocken" in out
|
||||
assert out["Haferflocken"]["suggestions"] == []
|
||||
|
||||
|
||||
def test_number_tokens_keep_decimal_fat():
|
||||
assert "9.5" in name_tokens("Joghurt 9,5%")
|
||||
assert "10" in name_tokens("Joghurt, aus Kuhmilch, 10 % Fett")
|
||||
|
||||
|
||||
def test_joghurt_10_ranks_above_35():
|
||||
light = {"id": "a", "name_de": "Joghurt >3,5% Fett", "name_en": "", "bls_code": "M", "catalog_kind": "official_bls"}
|
||||
full = {
|
||||
"id": "b",
|
||||
"name_de": "Joghurt, aus Kuhmilch, 10 % Fett",
|
||||
"name_en": "",
|
||||
"bls_code": "N",
|
||||
"catalog_kind": "official_bls",
|
||||
}
|
||||
index = _index(light, full)
|
||||
for query in ("Joghurt 10%", "Joghurt 9,5%", "Joghurt 10"):
|
||||
packed = suggest_for_name(index, query, limit=3)
|
||||
assert packed["suggestions"][0]["name_de"] == full["name_de"], query
|
||||
assert packed["suggestions"][0]["score"] > score_name_match(query, light["name_de"])
|
||||
Reference in new issue
Block a user