Create utils/report.py
Browse files- utils/utils/report.py +24 -0
utils/utils/report.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from weasyprint import HTML
|
2 |
+
import pandas as pd
|
3 |
+
import logging
|
4 |
+
import os
|
5 |
+
|
6 |
+
logger = logging.getLogger(__name__)
|
7 |
+
|
8 |
+
def generate_pdf(df):
|
9 |
+
"""Generate a PDF report from log data."""
|
10 |
+
logger.info("Generating PDF report...")
|
11 |
+
try:
|
12 |
+
html_content = f"""
|
13 |
+
<h1>LabOps Dashboard Report</h1>
|
14 |
+
<p>Generated on: {pd.Timestamp.now().strftime('%Y-%m-%d')}</p>
|
15 |
+
<h2>Log Data</h2>
|
16 |
+
{df.head().to_html(index=False)}
|
17 |
+
"""
|
18 |
+
pdf_path = "/tmp/labops_report.pdf"
|
19 |
+
HTML(string=html_content).write_pdf(pdf_path)
|
20 |
+
logger.info(f"PDF report saved to {pdf_path}")
|
21 |
+
return pdf_path
|
22 |
+
except Exception as e:
|
23 |
+
logger.error(f"Failed to generate PDF report: {e}")
|
24 |
+
raise
|