feat: Enhance context generation and report generation services with improved data handling and structure

This commit is contained in:
bolade
2025-10-04 10:25:10 +01:00
parent d66f3fd18b
commit 358898b7db
7 changed files with 163 additions and 48 deletions
+11 -5
View File
@@ -11,10 +11,9 @@ from typing import Any, Dict, List
import pandas as pd
from jinja2 import Environment, FileSystemLoader
from playwright.sync_api import sync_playwright
from app.services.context_generator import ContextGenerator
from app.services.graph_generator import GraphGenerator
from app.services.spirometry_table_extractor import extract_spirometry_table_from_pdf
from services.context_generator import ContextGenerator
from services.graph_generator import GraphGenerator
from services.spirometry_table_extractor import extract_spirometry_table_from_pdf
class ReportGeneratorService:
@@ -61,7 +60,13 @@ class ReportGeneratorService:
"""
# Load data
df = pd.read_csv(pnoe_csv_path, delimiter=";")
df = df.apply(pd.to_numeric, errors="ignore")
# Convert numeric columns (updated approach)
for col in df.columns:
try:
df[col] = pd.to_numeric(df[col])
except (ValueError, TypeError):
pass # Keep as-is if not numeric
# Calculate derived columns
df["VO2 Pulse"] = df["VO2(ml/min)"] / df["HR(bpm)"]
@@ -395,6 +400,7 @@ class ReportGeneratorService:
)
report_path = self.reports_dir / output_filename
print(f"Generating PDF report at {report_path}")
self.html_to_pdf(html_content, str(report_path))
return {