2026-05-14 10:20:38 +02:00
|
|
|
|
import re
|
2026-05-14 10:11:55 +02:00
|
|
|
|
from pathlib import Path
|
2026-05-14 10:15:14 +02:00
|
|
|
|
from reportlab.lib.pagesizes import A4
|
|
|
|
|
|
from reportlab.lib.units import cm
|
|
|
|
|
|
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
|
|
|
|
|
from reportlab.lib import colors
|
2026-05-14 10:20:38 +02:00
|
|
|
|
from reportlab.lib.enums import TA_CENTER, TA_RIGHT
|
|
|
|
|
|
from reportlab.platypus import (BaseDocTemplate, PageTemplate, Frame,
|
|
|
|
|
|
Paragraph, Spacer, Table, TableStyle,
|
|
|
|
|
|
Image, HRFlowable, PageBreak, NextPageTemplate)
|
|
|
|
|
|
from reportlab.pdfgen import canvas as rl_canvas
|
|
|
|
|
|
from datetime import date
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
|
|
|
|
|
BASE = Path(__file__).parent
|
|
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
# ─── Palette colori ───────────────────────────────────────────────────────────
|
|
|
|
|
|
C_BLUE = colors.HexColor("#1a3a5c")
|
|
|
|
|
|
C_BLUE_LIGHT= colors.HexColor("#2c5f8a")
|
|
|
|
|
|
C_ACCENT = colors.HexColor("#e8f0f7")
|
|
|
|
|
|
C_GRAY = colors.HexColor("#f5f5f5")
|
|
|
|
|
|
C_BORDER = colors.HexColor("#c0c8d0")
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
TABLE_HDR = TableStyle([
|
|
|
|
|
|
("BACKGROUND", (0, 0), (-1, 0), C_BLUE_LIGHT),
|
|
|
|
|
|
("TEXTCOLOR", (0, 0), (-1, 0), colors.white),
|
|
|
|
|
|
("FONTNAME", (0, 0), (-1, 0), "Helvetica-Bold"),
|
|
|
|
|
|
("FONTSIZE", (0, 0), (-1, 0), 10),
|
|
|
|
|
|
("ROWBACKGROUNDS",(0, 1), (-1, -1), [colors.white, C_GRAY]),
|
|
|
|
|
|
("FONTNAME", (0, 1), (-1, -1), "Helvetica"),
|
|
|
|
|
|
("FONTSIZE", (0, 1), (-1, -1), 9),
|
|
|
|
|
|
("GRID", (0, 0), (-1, -1), 0.4, C_BORDER),
|
|
|
|
|
|
("TOPPADDING", (0, 0), (-1, -1), 5),
|
2026-05-14 10:15:14 +02:00
|
|
|
|
("BOTTOMPADDING", (0, 0), (-1, -1), 5),
|
2026-05-14 10:20:38 +02:00
|
|
|
|
("LEFTPADDING", (0, 0), (-1, -1), 8),
|
|
|
|
|
|
("RIGHTPADDING", (0, 0), (-1, -1), 8),
|
|
|
|
|
|
("VALIGN", (0, 0), (-1, -1), "MIDDLE"),
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
TABLE_SUMMARY = TableStyle([
|
|
|
|
|
|
("BACKGROUND", (0, 0), (-1, 0), C_BLUE),
|
|
|
|
|
|
("TEXTCOLOR", (0, 0), (-1, 0), colors.white),
|
|
|
|
|
|
("FONTNAME", (0, 0), (-1, 0), "Helvetica-Bold"),
|
|
|
|
|
|
("FONTSIZE", (0, 0), (-1, 0), 10),
|
|
|
|
|
|
("ROWBACKGROUNDS",(0, 1), (-1, -1), [colors.white, C_ACCENT]),
|
|
|
|
|
|
("FONTNAME", (0, 1), (-1, -1), "Helvetica"),
|
|
|
|
|
|
("FONTSIZE", (0, 1), (-1, -1), 9),
|
|
|
|
|
|
("GRID", (0, 0), (-1, -1), 0.4, C_BORDER),
|
|
|
|
|
|
("TOPPADDING", (0, 0), (-1, -1), 6),
|
|
|
|
|
|
("BOTTOMPADDING", (0, 0), (-1, -1), 6),
|
|
|
|
|
|
("LEFTPADDING", (0, 0), (-1, -1), 10),
|
|
|
|
|
|
("RIGHTPADDING", (0, 0), (-1, -1), 10),
|
|
|
|
|
|
("ALIGN", (2, 0), (-1, -1), "CENTER"),
|
|
|
|
|
|
("VALIGN", (0, 0), (-1, -1), "MIDDLE"),
|
2026-05-14 10:15:14 +02:00
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
# ─── Parser markdown ──────────────────────────────────────────────────────────
|
|
|
|
|
|
def parse_md(md_path: Path) -> dict:
|
|
|
|
|
|
text = md_path.read_text(encoding="utf-8")
|
|
|
|
|
|
data = {}
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
m = re.search(r"^# (.+)$", text, re.MULTILINE)
|
|
|
|
|
|
data["nome"] = m.group(1).strip() if m else md_path.parent.name
|
|
|
|
|
|
|
|
|
|
|
|
kv = dict(re.findall(r"^\| (.+?) \| (.+?) \|$", text, re.MULTILINE))
|
|
|
|
|
|
kv = {k.strip(): v.strip() for k, v in kv.items() if k.strip() != "---"}
|
|
|
|
|
|
|
|
|
|
|
|
data["t0"] = kv.get("Inizio", "").replace(" s", "")
|
|
|
|
|
|
data["t_end"] = kv.get("Fine", "").replace(" s", "")
|
|
|
|
|
|
data["n_punti"] = kv.get("Numero di punti", "")
|
|
|
|
|
|
data["zona_exc"] = kv.get("Zona esclusa (peso = 0)", None)
|
|
|
|
|
|
data["r2"] = kv.get("R²", "")
|
|
|
|
|
|
data["intervallo"] = f"{data['t0']} – {data['t_end']} s"
|
|
|
|
|
|
|
|
|
|
|
|
m = re.search(r"\$\$(.+?)\$\$", text, re.DOTALL)
|
|
|
|
|
|
data["equazione_latex"] = m.group(1).strip() if m else ""
|
|
|
|
|
|
eq = data["equazione_latex"].replace(r"\cdot", "·").replace(r"\infty", "∞")
|
|
|
|
|
|
data["equazione"] = eq
|
|
|
|
|
|
|
|
|
|
|
|
rows3 = re.findall(r"^\| (.+?) \| (.+?) \| (.+?) \|$", text, re.MULTILINE)
|
|
|
|
|
|
params = {r[0].strip(): (r[1].strip(), r[2].strip())
|
|
|
|
|
|
for r in rows3 if r[0].strip() not in ("Parametro", "---")}
|
|
|
|
|
|
data["A"] = params.get("A", ("", ""))[0].replace(" °C", "")
|
|
|
|
|
|
data["A_err"] = (params.get("A", ("", ""))[1]
|
|
|
|
|
|
.replace("± ", "").replace("+/- ", "").replace(" °C", ""))
|
|
|
|
|
|
data["tau"] = params.get("τ", ("", ""))[0].replace(" s", "")
|
|
|
|
|
|
data["tau_err"] = (params.get("τ", ("", ""))[1]
|
|
|
|
|
|
.replace("± ", "").replace("+/- ", "").replace(" s", ""))
|
|
|
|
|
|
|
|
|
|
|
|
pngs = sorted(md_path.parent.glob("*.png"))
|
|
|
|
|
|
data["png"] = pngs[0] if pngs else None
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def collect_induttori() -> list:
|
|
|
|
|
|
return [parse_md(md)
|
|
|
|
|
|
for folder in sorted(BASE.glob("induttore*/"))
|
|
|
|
|
|
for md in sorted(folder.glob("report*.md"))]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ─── Genera .tex ──────────────────────────────────────────────────────────────
|
|
|
|
|
|
def generate_tex(induttori: list):
|
|
|
|
|
|
lines = []
|
|
|
|
|
|
lines += [
|
|
|
|
|
|
r"\documentclass[11pt,a4paper]{article}",
|
|
|
|
|
|
r"\usepackage[utf8]{inputenc}",
|
|
|
|
|
|
r"\usepackage[T1]{fontenc}",
|
|
|
|
|
|
r"\usepackage[margin=2.5cm]{geometry}",
|
|
|
|
|
|
r"\usepackage{amsmath,amssymb}",
|
|
|
|
|
|
r"\usepackage{booktabs}",
|
|
|
|
|
|
r"\usepackage{graphicx}",
|
|
|
|
|
|
r"\usepackage{float}",
|
|
|
|
|
|
r"\usepackage{caption}",
|
|
|
|
|
|
r"\usepackage[table]{xcolor}",
|
|
|
|
|
|
r"\usepackage{hyperref}",
|
|
|
|
|
|
r"\definecolor{hdrblue}{HTML}{1a3a5c}",
|
|
|
|
|
|
r"\usepackage{fancyhdr}",
|
|
|
|
|
|
r"\pagestyle{fancy}",
|
|
|
|
|
|
r"\fancyhf{}",
|
|
|
|
|
|
r"\rhead{\textcolor{hdrblue}{\small Analisi Termica Forno}}",
|
|
|
|
|
|
r"\lhead{\textcolor{hdrblue}{\small Cevolani}}",
|
|
|
|
|
|
r"\rfoot{\thepage}",
|
|
|
|
|
|
r"\title{\textbf{Report Analisi Termica Forno}}",
|
|
|
|
|
|
r"\author{Analisi IR -- Cevolani}",
|
|
|
|
|
|
r"\date{\today}",
|
|
|
|
|
|
r"\begin{document}",
|
|
|
|
|
|
r"\maketitle",
|
|
|
|
|
|
r"\tableofcontents",
|
|
|
|
|
|
r"\newpage",
|
|
|
|
|
|
"",
|
|
|
|
|
|
r"\section{Modello di fitting}",
|
|
|
|
|
|
r"Ogni intervallo è interpolato con il modello di raffreddamento di Newton:",
|
|
|
|
|
|
r"\begin{equation}",
|
|
|
|
|
|
r" T(t) = T_\infty + A \cdot e^{-(t-t_0)/\tau}",
|
|
|
|
|
|
r"\end{equation}",
|
|
|
|
|
|
r"dove $T_\infty = 22.99\,^\circ\mathrm{C}$ è la temperatura ambiente media ponderata.",
|
|
|
|
|
|
r"La regressione non lineare usa il metodo \textit{Trust Region Reflective} (TRF)",
|
|
|
|
|
|
r"di \texttt{scipy.optimize.curve\_fit}.",
|
|
|
|
|
|
"",
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
for ind in induttori:
|
|
|
|
|
|
lines += [
|
|
|
|
|
|
rf"\section{{{ind['nome']}}}",
|
|
|
|
|
|
r"\subsection{Intervallo di campionamento}",
|
|
|
|
|
|
r"\begin{tabular}{ll}",
|
|
|
|
|
|
r"\toprule",
|
|
|
|
|
|
r"\textbf{Parametro} & \textbf{Valore} \\",
|
|
|
|
|
|
r"\midrule",
|
|
|
|
|
|
rf"Inizio & ${ind['t0']}$ s \\",
|
|
|
|
|
|
rf"Fine & ${ind['t_end']}$ s \\",
|
|
|
|
|
|
rf"Numero di punti & {ind['n_punti']} \\",
|
|
|
|
|
|
]
|
|
|
|
|
|
if ind["zona_exc"]:
|
|
|
|
|
|
lines.append(rf"Zona esclusa (peso = 0) & {ind['zona_exc']} \\")
|
|
|
|
|
|
lines += [
|
|
|
|
|
|
r"\bottomrule",
|
|
|
|
|
|
r"\end{tabular}",
|
|
|
|
|
|
"",
|
|
|
|
|
|
r"\subsection{Equazione trovata}",
|
|
|
|
|
|
r"\begin{equation}",
|
|
|
|
|
|
f" {ind['equazione_latex']}",
|
|
|
|
|
|
r"\end{equation}",
|
|
|
|
|
|
r"\begin{tabular}{lll}",
|
|
|
|
|
|
r"\toprule",
|
|
|
|
|
|
r"\textbf{Parametro} & \textbf{Valore} & \textbf{Incertezza (1$\sigma$)} \\",
|
|
|
|
|
|
r"\midrule",
|
|
|
|
|
|
rf"$A$ & ${ind['A']}\,^\circ\mathrm{{C}}$ & $\pm\,{ind['A_err']}\,^\circ\mathrm{{C}}$ \\",
|
|
|
|
|
|
rf"$\tau$ & ${ind['tau']}\,\mathrm{{s}}$ & $\pm\,{ind['tau_err']}\,\mathrm{{s}}$ \\",
|
|
|
|
|
|
rf"$R^2$ & \multicolumn{{2}}{{l}}{{{ind['r2']}}} \\",
|
|
|
|
|
|
r"\bottomrule",
|
|
|
|
|
|
r"\end{tabular}",
|
|
|
|
|
|
"",
|
|
|
|
|
|
r"\subsection{Grafico}",
|
|
|
|
|
|
r"\begin{figure}[H]",
|
|
|
|
|
|
r"\centering",
|
|
|
|
|
|
rf"\includegraphics[width=0.9\textwidth]{{{ind['png']}}}",
|
|
|
|
|
|
rf"\caption{{Fit esponenziale -- {ind['nome']} [{ind['intervallo']}]}}",
|
|
|
|
|
|
r"\end{figure}",
|
|
|
|
|
|
r"\newpage",
|
|
|
|
|
|
"",
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# Riepilogo
|
|
|
|
|
|
lines += [
|
|
|
|
|
|
r"\section{Riepilogo}",
|
|
|
|
|
|
r"\begin{tabular}{lllll}",
|
|
|
|
|
|
r"\toprule",
|
|
|
|
|
|
r"\textbf{Induttore} & \textbf{Intervallo [s]} & \textbf{A [°C]} & \textbf{$\tau$ [s]} & \textbf{$R^2$} \\",
|
|
|
|
|
|
r"\midrule",
|
|
|
|
|
|
]
|
|
|
|
|
|
for ind in induttori:
|
|
|
|
|
|
lines.append(
|
|
|
|
|
|
rf"{ind['nome']} & {ind['intervallo']} & {ind['A']} & {ind['tau']} & {ind['r2']} \\"
|
|
|
|
|
|
)
|
|
|
|
|
|
lines += [r"\bottomrule", r"\end{tabular}", "", r"\end{document}"]
|
|
|
|
|
|
|
|
|
|
|
|
out = BASE / "report_completo.tex"
|
|
|
|
|
|
out.write_text("\n".join(lines), encoding="utf-8")
|
|
|
|
|
|
print("report_completo.tex generato.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ─── Header / footer per reportlab ───────────────────────────────────────────
|
|
|
|
|
|
class NumberedCanvas(rl_canvas.Canvas):
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
self._saved_page_states = []
|
|
|
|
|
|
|
|
|
|
|
|
def showPage(self):
|
|
|
|
|
|
self._saved_page_states.append(dict(self.__dict__))
|
|
|
|
|
|
self._startPage()
|
|
|
|
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
|
|
num_pages = len(self._saved_page_states)
|
|
|
|
|
|
for state in self._saved_page_states:
|
|
|
|
|
|
self.__dict__.update(state)
|
|
|
|
|
|
self._draw_page_decoration(num_pages)
|
|
|
|
|
|
super().showPage()
|
|
|
|
|
|
super().save()
|
|
|
|
|
|
|
|
|
|
|
|
def _draw_page_decoration(self, page_count):
|
|
|
|
|
|
w, h = A4
|
|
|
|
|
|
self.saveState()
|
|
|
|
|
|
|
|
|
|
|
|
if self._pageNumber > 1:
|
|
|
|
|
|
# Header
|
|
|
|
|
|
self.setFillColor(C_BLUE)
|
|
|
|
|
|
self.rect(2.5*cm, h - 2*cm, w - 5*cm, 0.6*cm, fill=1, stroke=0)
|
|
|
|
|
|
self.setFillColor(colors.white)
|
|
|
|
|
|
self.setFont("Helvetica-Bold", 9)
|
|
|
|
|
|
self.drawString(2.8*cm, h - 1.65*cm, "Analisi Termica Forno")
|
|
|
|
|
|
self.setFont("Helvetica", 9)
|
|
|
|
|
|
self.drawRightString(w - 2.5*cm, h - 1.65*cm, "Cevolani")
|
|
|
|
|
|
|
|
|
|
|
|
# Footer
|
|
|
|
|
|
self.setStrokeColor(C_BLUE_LIGHT)
|
|
|
|
|
|
self.setLineWidth(0.5)
|
|
|
|
|
|
self.line(2.5*cm, 1.8*cm, w - 2.5*cm, 1.8*cm)
|
|
|
|
|
|
self.setFillColor(C_BLUE)
|
|
|
|
|
|
self.setFont("Helvetica", 8)
|
|
|
|
|
|
self.drawString(2.5*cm, 1.3*cm, f"Report generato il {date.today().strftime('%d/%m/%Y')}")
|
|
|
|
|
|
self.drawRightString(w - 2.5*cm, 1.3*cm,
|
|
|
|
|
|
f"Pag. {self._pageNumber} / {page_count}")
|
|
|
|
|
|
self.restoreState()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ─── Genera PDF ───────────────────────────────────────────────────────────────
|
|
|
|
|
|
def generate_pdf(induttori: list):
|
|
|
|
|
|
out = str(BASE / "report_completo.pdf")
|
|
|
|
|
|
w, h = A4
|
|
|
|
|
|
margin = 2.5*cm
|
|
|
|
|
|
frame_normal = Frame(margin, 2.5*cm, w - 2*margin, h - 5*cm,
|
|
|
|
|
|
id="normal", topPadding=0.8*cm)
|
|
|
|
|
|
frame_cover = Frame(margin, margin, w - 2*margin, h - 2*margin,
|
|
|
|
|
|
id="cover")
|
|
|
|
|
|
|
|
|
|
|
|
doc = BaseDocTemplate(out, pagesize=A4)
|
|
|
|
|
|
doc.addPageTemplates([
|
|
|
|
|
|
PageTemplate(id="cover", frames=[frame_cover]),
|
|
|
|
|
|
PageTemplate(id="normal", frames=[frame_normal]),
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
styles = getSampleStyleSheet()
|
|
|
|
|
|
s_body = styles["BodyText"]
|
|
|
|
|
|
s_h1 = ParagraphStyle("H1", fontName="Helvetica-Bold", fontSize=14,
|
|
|
|
|
|
textColor=C_BLUE, spaceBefore=14, spaceAfter=6,
|
|
|
|
|
|
borderPad=4)
|
|
|
|
|
|
s_h2 = ParagraphStyle("H2", fontName="Helvetica-Bold", fontSize=11,
|
|
|
|
|
|
textColor=C_BLUE_LIGHT, spaceBefore=10, spaceAfter=4)
|
|
|
|
|
|
s_eq = ParagraphStyle("EQ", fontName="Courier", fontSize=10,
|
|
|
|
|
|
leftIndent=24, spaceBefore=4, spaceAfter=6,
|
|
|
|
|
|
backColor=C_ACCENT, borderPad=6)
|
|
|
|
|
|
s_cover_title = ParagraphStyle("CoverTitle", fontName="Helvetica-Bold",
|
|
|
|
|
|
fontSize=28, textColor=C_BLUE,
|
|
|
|
|
|
alignment=TA_CENTER, spaceAfter=10)
|
|
|
|
|
|
s_cover_sub = ParagraphStyle("CoverSub", fontName="Helvetica",
|
|
|
|
|
|
fontSize=14, textColor=C_BLUE_LIGHT,
|
|
|
|
|
|
alignment=TA_CENTER, spaceAfter=6)
|
|
|
|
|
|
s_cover_date = ParagraphStyle("CoverDate", fontName="Helvetica",
|
|
|
|
|
|
fontSize=11, textColor=colors.grey,
|
|
|
|
|
|
alignment=TA_CENTER)
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
2026-05-14 10:15:14 +02:00
|
|
|
|
story = []
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
# ── Cover page ──
|
|
|
|
|
|
story.append(Spacer(1, 5*cm))
|
|
|
|
|
|
story.append(HRFlowable(width="100%", thickness=3, color=C_BLUE))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
story.append(Spacer(1, 0.5*cm))
|
2026-05-14 10:20:38 +02:00
|
|
|
|
story.append(Paragraph("Report Analisi Termica Forno", s_cover_title))
|
|
|
|
|
|
story.append(Spacer(1, 0.3*cm))
|
|
|
|
|
|
story.append(Paragraph("Analisi IR – Cevolani", s_cover_sub))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
story.append(Spacer(1, 0.5*cm))
|
2026-05-14 10:20:38 +02:00
|
|
|
|
story.append(HRFlowable(width="100%", thickness=3, color=C_BLUE))
|
|
|
|
|
|
story.append(Spacer(1, 1*cm))
|
|
|
|
|
|
story.append(Paragraph(f"Data: {date.today().strftime('%d %B %Y')}", s_cover_date))
|
|
|
|
|
|
story.append(Paragraph(f"Induttori analizzati: {len(induttori)}", s_cover_date))
|
|
|
|
|
|
story.append(NextPageTemplate("normal"))
|
|
|
|
|
|
story.append(PageBreak())
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
# ── Modello ──
|
|
|
|
|
|
story.append(Paragraph("Modello di fitting", s_h1))
|
|
|
|
|
|
story.append(HRFlowable(width="100%", thickness=1, color=C_BLUE_LIGHT))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
story.append(Spacer(1, 0.2*cm))
|
2026-05-14 10:20:38 +02:00
|
|
|
|
story.append(Paragraph(
|
|
|
|
|
|
"Ogni intervallo è interpolato con il modello di raffreddamento di Newton:", s_body))
|
|
|
|
|
|
story.append(Paragraph("T(t) = T_inf + A · exp( -(t - t0) / τ )", s_eq))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
story.append(Paragraph(
|
|
|
|
|
|
"dove <b>T_inf = 22.99 °C</b> è la temperatura ambiente media ponderata. "
|
2026-05-14 10:20:38 +02:00
|
|
|
|
"La regressione usa il metodo <i>Trust Region Reflective</i> (TRF) "
|
|
|
|
|
|
"di <font name='Courier'>scipy.optimize.curve_fit</font>.", s_body))
|
|
|
|
|
|
story.append(Spacer(1, 0.5*cm))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
# ── Sezione per ogni induttore ──
|
|
|
|
|
|
for ind in induttori:
|
|
|
|
|
|
story.append(Paragraph(ind["nome"], s_h1))
|
|
|
|
|
|
story.append(HRFlowable(width="100%", thickness=1, color=C_BLUE_LIGHT))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
story.append(Spacer(1, 0.2*cm))
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
# Intervallo
|
|
|
|
|
|
story.append(Paragraph("Intervallo di campionamento", s_h2))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
rows = [["Parametro", "Valore"],
|
|
|
|
|
|
["Inizio", f"{ind['t0']} s"],
|
|
|
|
|
|
["Fine", f"{ind['t_end']} s"],
|
|
|
|
|
|
["Numero di punti", ind["n_punti"]]]
|
|
|
|
|
|
if ind["zona_exc"]:
|
|
|
|
|
|
rows.append(["Zona esclusa (peso = 0)", ind["zona_exc"]])
|
2026-05-14 10:20:38 +02:00
|
|
|
|
story.append(Table(rows, colWidths=[8*cm, 6*cm], style=TABLE_HDR))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
story.append(Spacer(1, 0.3*cm))
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
2026-05-14 10:15:14 +02:00
|
|
|
|
# Equazione
|
2026-05-14 10:20:38 +02:00
|
|
|
|
story.append(Paragraph("Equazione trovata", s_h2))
|
|
|
|
|
|
story.append(Paragraph(ind["equazione"], s_eq))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
story.append(Spacer(1, 0.2*cm))
|
2026-05-14 10:20:38 +02:00
|
|
|
|
story.append(Table([
|
|
|
|
|
|
["Parametro", "Valore", "Incertezza (1σ)"],
|
|
|
|
|
|
["A", f"{ind['A']} °C", f"± {ind['A_err']} °C"],
|
|
|
|
|
|
["τ", f"{ind['tau']} s", f"± {ind['tau_err']} s"],
|
|
|
|
|
|
["R²", ind["r2"], ""],
|
|
|
|
|
|
], colWidths=[3.5*cm, 6*cm, 5*cm], style=TABLE_HDR))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
story.append(Spacer(1, 0.3*cm))
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
2026-05-14 10:15:14 +02:00
|
|
|
|
# Plot
|
2026-05-14 10:20:38 +02:00
|
|
|
|
if ind["png"] and Path(ind["png"]).exists():
|
|
|
|
|
|
story.append(Paragraph("Grafico", s_h2))
|
|
|
|
|
|
story.append(Image(str(ind["png"]), width=14*cm, height=8.4*cm))
|
|
|
|
|
|
story.append(Spacer(1, 0.4*cm))
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
# ── Riepilogo ──
|
2026-05-14 10:15:14 +02:00
|
|
|
|
story.append(PageBreak())
|
2026-05-14 10:20:38 +02:00
|
|
|
|
story.append(Paragraph("Riepilogo", s_h1))
|
|
|
|
|
|
story.append(HRFlowable(width="100%", thickness=1, color=C_BLUE_LIGHT))
|
|
|
|
|
|
story.append(Spacer(1, 0.3*cm))
|
2026-05-14 10:15:14 +02:00
|
|
|
|
summary = [["Induttore", "Intervallo [s]", "A [°C]", "τ [s]", "R²"]]
|
2026-05-14 10:20:38 +02:00
|
|
|
|
for ind in induttori:
|
2026-05-14 10:15:14 +02:00
|
|
|
|
summary.append([ind["nome"], ind["intervallo"],
|
|
|
|
|
|
ind["A"], ind["tau"], ind["r2"]])
|
2026-05-14 10:20:38 +02:00
|
|
|
|
story.append(Table(summary,
|
|
|
|
|
|
colWidths=[3.5*cm, 4.5*cm, 3*cm, 3*cm, 3*cm],
|
|
|
|
|
|
style=TABLE_SUMMARY))
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
doc.build(story, canvasmaker=NumberedCanvas)
|
|
|
|
|
|
print(f"report_completo.pdf generato ({len(induttori)} induttori).")
|
2026-05-14 10:11:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
2026-05-14 10:20:38 +02:00
|
|
|
|
# ─── Entry point ──────────────────────────────────────────────────────────────
|
2026-05-14 10:11:55 +02:00
|
|
|
|
if __name__ == "__main__":
|
2026-05-14 10:20:38 +02:00
|
|
|
|
induttori = collect_induttori()
|
|
|
|
|
|
if not induttori:
|
|
|
|
|
|
print("Nessun report*.md trovato nelle cartelle induttore*/.")
|
|
|
|
|
|
else:
|
|
|
|
|
|
generate_tex(induttori)
|
|
|
|
|
|
generate_pdf(induttori)
|