feat: add viz_bundle support to report generation and enhance schema
Deploy Development / deploy (push) Successful in 1m1s
Build Test / pytest-backend (push) Successful in 5s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 20s

- Introduced the `viz_bundle` block type to the report profile schema, allowing for the inclusion of bundled visualizations in PDF reports.
- Updated the `build_structured_report_pdf` function to handle `VizBundleBlock` and append its content to the report.
- Enhanced the report catalog API to include details for the new `viz_bundle` block type.
- Added configuration editors for various visualization bundles in the frontend settings page.
- Updated tests to validate the new `viz_bundle` functionality and ensure proper handling of report profiles.
- Bumped application version to reflect these enhancements.
This commit is contained in:
Lars committed 2026-04-29 11:46:34 +02:00
1 parent 62729d0648
commit 3ab5dae130
7 files changed
+682 -104

No files matched your search

+43 -9
View File
@@ -3,15 +3,18 @@ Konfigurierbarer PDF-Bericht v1: Payload-Schema (unabhängig vom Dashboard-Layou
Block-Typen:
- section: Überschrift
- viz_bundle: Layer-2b-Ver bundles (KPIs, Text, Charts) — gleiche Config wie Dashboard
- chart: diagramm via report_chart_fetch (chart_id + window_days)
- ai_insight: optional insight_id (UUID), sonst Platzhalter für spätere Auswahl
"""
from __future__ import annotations
from typing import Literal, Union
from typing import Any, Literal, Union
from pydantic import BaseModel, Field, model_validator
from dashboard_widget_config import validate_widget_entry_config
ALLOWED_CHART_IDS: frozenset[str] = frozenset(
{
"weight_trend",
@@ -22,7 +25,17 @@ ALLOWED_CHART_IDS: frozenset[str] = frozenset(
}
)
_MAX_BLOCKS = 24
_MAX_BLOCKS = 32
ALLOWED_VIZ_BUNDLE_IDS: frozenset[str] = frozenset(
{
"body_history_viz",
"nutrition_history_viz",
"fitness_history_viz",
"recovery_history_viz",
"history_overview_viz",
}
)
class SectionBlock(BaseModel):
@@ -48,10 +61,27 @@ class AiInsightBlock(BaseModel):
insight_id: str | None = Field(default=None, max_length=48)
class VizBundleBlock(BaseModel):
"""Gleiche Layer-2b-Bundles wie im Dashboard; config wie validate_widget_entry_config."""
type: Literal["viz_bundle"] = "viz_bundle"
bundle_id: str = Field(min_length=1, max_length=64)
config: dict[str, Any] = Field(default_factory=dict)
@model_validator(mode="after")
def _bundle_config(self) -> VizBundleBlock:
if self.bundle_id not in ALLOWED_VIZ_BUNDLE_IDS:
raise ValueError(
f"Unbekanntes bundle_id: {self.bundle_id!r} (erlaubt: {sorted(ALLOWED_VIZ_BUNDLE_IDS)})"
)
self.config = validate_widget_entry_config(self.bundle_id, self.config)
return self
class ReportProfilePayload(BaseModel):
version: Literal[1] = 1
document_title: str = Field(default="", max_length=120)
blocks: list[Union[SectionBlock, ChartBlock, AiInsightBlock]]
blocks: list[Union[SectionBlock, ChartBlock, AiInsightBlock, VizBundleBlock]]
@model_validator(mode="after")
def _blocks_limit(self) -> ReportProfilePayload:
@@ -74,12 +104,16 @@ def default_report_profile_dict() -> dict:
p = ReportProfilePayload(
document_title="",
blocks=[
SectionBlock(title="Körpergewicht"),
ChartBlock(chart_id="weight_trend", window_days=90),
SectionBlock(title="Energiebilanz"),
ChartBlock(chart_id="energy_balance", window_days=28),
SectionBlock(title="Trainingsvolumen"),
ChartBlock(chart_id="training_volume", window_days=84),
SectionBlock(title="Verlauf — Körper"),
VizBundleBlock(bundle_id="body_history_viz", config={"chart_days": 90}),
SectionBlock(title="Verlauf — Ernährung"),
VizBundleBlock(bundle_id="nutrition_history_viz", config={"chart_days": 90}),
SectionBlock(title="Verlauf — Fitness"),
VizBundleBlock(bundle_id="fitness_history_viz", config={"chart_days": 90}),
SectionBlock(title="Verlauf — Erholung"),
VizBundleBlock(bundle_id="recovery_history_viz", config={"chart_days": 90}),
SectionBlock(title="Gesamtübersicht"),
VizBundleBlock(bundle_id="history_overview_viz", config={"chart_days": 90}),
],
)
return p.to_stored_dict()