p="content_graphic_variants.py"
src=open(p).read()
old=''' fit = (item.get("score_components") or {}).get("fit_hook_haupttext_cta")
item["text_image_fit_10"] = score_to_10(fit if fit is not None else item["score_text_graphic"])
return item'''
new=''' fit = (item.get("score_components") or {}).get("fit_hook_haupttext_cta")
item["text_image_fit_10"] = score_to_10(fit if fit is not None else item["score_text_graphic"])
item["focus_fit"] = _focus_fit_summary(item)
return item
def _focus_fit_summary(item: dict[str, Any]) -> dict[str, Any]:
"""MAS-IG-CO2-FOCUS Punkt 5: Variantenkarten transparent machen.
Liefert Themenfit (aus gespeichertem Themenfokus), Signalfit, Plattformfit
und eine einzeilige Begründung für die UI-Anzeige je Medienvariante.
"""
spec = item.get("creative_spec") if isinstance(item.get("creative_spec"), dict) else {}
components = item.get("score_components") if isinstance(item.get("score_components"), dict) else {}
focus = str(spec.get("topic_focus") or item.get("topic_focus") or "auto")
label = str(spec.get("focus_label") or "") or "Automatisch"
family = str(spec.get("topic_family") or "")
signal_fit = _clamp(float(components.get("semantic_visual_fit") or components.get("motivqualität") or 0))
platform_fit = _clamp(float(components.get("platform_fit") or 0))
thewen = None
if focus == "luftqualitaet_co2":
negatives = (spec.get("focus_prompt_brief") or {}).get("negative_rules") or []
thewen = "CO2-/Luftqualitätssemantik klar erkennbar" if "kein Schimmelhauptmotiv" in negatives else "Fokus Luftqualität / CO2"
elif focus == "feuchte_schimmel":
thewen = "Feuchte-/Schimmelbezug passend zum Fokus"
elif focus == "lueftung":
thewen = "Lüftungs-/Systembezug zum Fokus"
elif focus == "gebaeude_diagnose":
thewen = "diagnostischer Ansatz zum Fokus"
elif focus == "energie_komfort":
thewen = "Energie-/Komfortbezug zum Fokus"
else:
thewen = f"automatisch ermittelte Themenfamilie: {family or 'general'}"
return {
"themen_fit": label,
"themen_family": family,
"signal_fit": score_to_10(signal_fit),
"platform_fit": score_to_10(platform_fit),
"begruendung": thewen,
"focus_value": focus,
}'''
assert old in src, "row_to_dict marker not found"
src2=src.replace(old,new,1)
open(p,"w").write(src2)
print("content_graphic_variants focus_fit helper added OK")