Spaces:
Sleeping
Sleeping
Update src/report.py
Browse files- src/report.py +32 -32
src/report.py
CHANGED
|
@@ -1,32 +1,32 @@
|
|
| 1 |
-
# report.py
|
| 2 |
-
from fpdf import FPDF
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
class ReportBuilder:
|
| 6 |
-
def __init__(self, output_path="
|
| 7 |
-
self.pdf = FPDF()
|
| 8 |
-
self.pdf.set_auto_page_break(auto=True, margin=15)
|
| 9 |
-
self.output_path = output_path
|
| 10 |
-
|
| 11 |
-
def add_title(self, title):
|
| 12 |
-
self.pdf.add_page()
|
| 13 |
-
self.pdf.set_font("Arial", "B", 16)
|
| 14 |
-
self.pdf.cell(0, 10, title, ln=True, align="C")
|
| 15 |
-
self.pdf.ln(10)
|
| 16 |
-
|
| 17 |
-
def add_section(self, title, body):
|
| 18 |
-
self.pdf.set_font("Arial", "B", 14)
|
| 19 |
-
self.pdf.cell(0, 10, title, ln=True)
|
| 20 |
-
self.pdf.set_font("Arial", "", 12)
|
| 21 |
-
self.pdf.multi_cell(0, 10, body)
|
| 22 |
-
self.pdf.ln(5)
|
| 23 |
-
|
| 24 |
-
def add_plot(self, image_path, caption):
|
| 25 |
-
if os.path.exists(image_path):
|
| 26 |
-
self.pdf.image(image_path, w=160)
|
| 27 |
-
self.pdf.set_font("Arial", "I", 11)
|
| 28 |
-
self.pdf.multi_cell(0, 8, f" {caption}")
|
| 29 |
-
self.pdf.ln(5)
|
| 30 |
-
|
| 31 |
-
def save(self):
|
| 32 |
-
self.pdf.output(self.output_path)
|
|
|
|
| 1 |
+
# report.py
|
| 2 |
+
from fpdf import FPDF
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
class ReportBuilder:
|
| 6 |
+
def __init__(self, output_path="/tmp/final_report.pdf"):
|
| 7 |
+
self.pdf = FPDF()
|
| 8 |
+
self.pdf.set_auto_page_break(auto=True, margin=15)
|
| 9 |
+
self.output_path = output_path
|
| 10 |
+
|
| 11 |
+
def add_title(self, title):
|
| 12 |
+
self.pdf.add_page()
|
| 13 |
+
self.pdf.set_font("Arial", "B", 16)
|
| 14 |
+
self.pdf.cell(0, 10, title, ln=True, align="C")
|
| 15 |
+
self.pdf.ln(10)
|
| 16 |
+
|
| 17 |
+
def add_section(self, title, body):
|
| 18 |
+
self.pdf.set_font("Arial", "B", 14)
|
| 19 |
+
self.pdf.cell(0, 10, title, ln=True)
|
| 20 |
+
self.pdf.set_font("Arial", "", 12)
|
| 21 |
+
self.pdf.multi_cell(0, 10, body)
|
| 22 |
+
self.pdf.ln(5)
|
| 23 |
+
|
| 24 |
+
def add_plot(self, image_path, caption):
|
| 25 |
+
if os.path.exists(image_path):
|
| 26 |
+
self.pdf.image(image_path, w=160)
|
| 27 |
+
self.pdf.set_font("Arial", "I", 11)
|
| 28 |
+
self.pdf.multi_cell(0, 8, f" {caption}")
|
| 29 |
+
self.pdf.ln(5)
|
| 30 |
+
|
| 31 |
+
def save(self):
|
| 32 |
+
self.pdf.output(self.output_path)
|