-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport_utils.py
More file actions
36 lines (34 loc) · 1.28 KB
/
Copy pathreport_utils.py
File metadata and controls
36 lines (34 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pandas as pd
import io
from odf.opendocument import OpenDocumentText
from odf.text import P, H
from odf.table import Table, TableRow, TableCell
def generate_csv_report(data_dict, project_name=None):
df = pd.DataFrame([data_dict])
output = io.StringIO()
if project_name:
output.write(f"Project Name,{project_name}\n")
df.to_csv(output, index=False)
return output.getvalue().encode('utf-8')
def generate_odt_report(data_dict, project_name=None):
doc = OpenDocumentText()
doc.text.addElement(H(outlinelevel=1, text='NFPA 780 Lightning Risk Assessment Report'))
if project_name:
doc.text.addElement(P(text=f'Project Name: {project_name}'))
doc.text.addElement(P(text='This report summarizes the results of the simplified lightning risk assessment.'))
doc.text.addElement(H(outlinelevel=2, text='Assessment Results'))
table = Table()
for k, v in data_dict.items():
row = TableRow()
cell1 = TableCell()
cell1.addElement(P(text=str(k)))
cell2 = TableCell()
cell2.addElement(P(text=str(v)))
row.addElement(cell1)
row.addElement(cell2)
table.addElement(row)
doc.text.addElement(table)
output = io.BytesIO()
doc.save(output)
output.seek(0)
return output.read()