Skip to content

Commit 7463747

Browse files
committed
WIP: begin writing analyzer to generate combined report
This is definitely a work in progress.
1 parent 0f8f729 commit 7463747

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

ica/analyzers/combined_report.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
# type: ignore
3+
4+
import os
5+
import os.path
6+
7+
from openpyxl import Workbook
8+
from openpyxl.styles import Alignment, Font
9+
10+
import ica
11+
from ica.analyzers.message_totals import get_results as message_totals
12+
13+
14+
def main() -> None:
15+
cli_args = ica.get_cli_args()
16+
17+
sheet_name = "Message Totals"
18+
df = ica.normalize_df_for_output(message_totals(cli_args))
19+
is_default_index = not df.index.name
20+
21+
excel_file_path = os.path.expanduser("~/Desktop/output.xlsx")
22+
23+
# Create a new Excel workbook and set up a sheet
24+
wb = Workbook()
25+
ws = wb.active
26+
ws.title = sheet_name
27+
28+
# Write DataFrame headers with styling
29+
for col_num, column_name in enumerate(
30+
df.columns, 1
31+
): # Columns start from 1 in openpyxl
32+
cell = ws.cell(row=1, column=col_num, value=column_name)
33+
# Apply header styles
34+
cell.font = Font(bold=True)
35+
cell.alignment = Alignment(horizontal="center")
36+
37+
# Write DataFrame rows
38+
for row_num, row in enumerate(
39+
df.itertuples(index=not is_default_index), 2
40+
): # Rows start from 2 (after headers)
41+
for col_num, value in enumerate(row, 1):
42+
ws.cell(row=row_num, column=col_num, value=value)
43+
44+
wb.save(excel_file_path)
45+
46+
47+
if __name__ == "__main__":
48+
main()

0 commit comments

Comments
 (0)