Spaces:
Sleeping
Sleeping
| from typing import Any, Dict, Optional, Tuple | |
| def format_facts(facts: Dict[str, Any]) -> str: | |
| sgv = facts.get("sgv") | |
| roc = facts.get("roc15_mgdl_min") | |
| age = facts.get("age_min") | |
| mode = facts.get("mode") | |
| parts = [] | |
| if sgv is not None: | |
| parts.append(f"Aktueller Wert: **{sgv:.0f} mg/dL**") | |
| if roc is not None: | |
| trend = "fallend" if roc < 0 else "steigend" if roc > 0 else "stabil" | |
| parts.append(f"Trend (15 min): **{trend}** ({roc:+.2f} mg/dL/min)") | |
| if age is not None: | |
| parts.append(f"Datenalter: **{age:.1f} min**") | |
| if mode: | |
| parts.append(f"Modus: **{mode}**") | |
| return " • ".join(parts) | |
| def compose_guidance_message( | |
| role: str, | |
| mode: str, | |
| event_type: str, | |
| facts: Dict[str, Any], | |
| guidance: Optional[Dict[str, Any]], | |
| ) -> Tuple[str, str]: | |
| facts_md = format_facts(facts) | |
| if guidance: | |
| steps = str(guidance.get("steps") or "").strip() | |
| questions = str(guidance.get("questions") or "").strip() | |
| escalation = str(guidance.get("escalation") or "").strip() | |
| gid = str(guidance.get("guidance_id") or "").strip() | |
| else: | |
| steps = questions = escalation = gid = "" | |
| md = [f"### Event: **{event_type}**", "", f"**Fakten:** {facts_md}", ""] | |
| md += ["**Nach euren Leitplanken:**", steps, ""] if steps else ["**Hinweis:** Für dieses Event ist noch keine Guidance hinterlegt.", ""] | |
| if questions: | |
| md += ["**Rückfragen (falls unklar):**", questions, ""] | |
| if escalation: | |
| md += ["**Eskalation:**", escalation, ""] | |
| if gid: | |
| md += [f"_Guidance-ID: `{gid}`_", ""] | |
| sgv = facts.get("sgv") | |
| roc = facts.get("roc15_mgdl_min") | |
| if sgv is None: | |
| tts = f"{event_type}. Bitte prüfe den Sensor oder die Verbindung." | |
| else: | |
| trend_word = "stabil" | |
| if roc is not None: | |
| trend_word = "fallend" if roc < 0 else "steigend" if roc > 0 else "stabil" | |
| tts = f"{event_type}. Wert {int(round(sgv))} mg pro Deziliter, Trend {trend_word}. " | |
| if steps: | |
| tts += steps.splitlines()[0].strip() | |
| if escalation: | |
| tts += " Wenn unsicher: Eltern informieren und nach Notfallplan handeln." | |
| return "\n".join(md).strip(), tts |