Skip to content

Commit 434894f

Browse files
committed
Add the correct decorators and inheritance patterns, error handling, and replace several names to be more descriptive in the reportt class
1 parent 1c2e358 commit 434894f

File tree

6 files changed

+194
-175
lines changed

6 files changed

+194
-175
lines changed

report/main.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
report, report_metadata = yaml_manager.load_report_metadata('./report_metadata_micw2graph.yaml')
1111

1212
# Create report view
13-
# doc_report = doc_reportview.QuartoReportView(report_metadata['report']['identifier'], report_metadata['report']['name'],
14-
# report=report,
15-
# report_type = ReportType[report_metadata['report']['report_type'].upper()],
16-
# report_format = doc_reportview.ReportFormat[report_metadata['report']['report_format'].upper()],
17-
# columns=None)
18-
# doc_report.generate_report(output_dir="quarto_report/")
19-
# doc_report.run_report(output_dir="quarto_report/")
13+
doc_report = doc_reportview.QuartoReportView(report_metadata['report']['id'], report_metadata['report']['name'],
14+
report=report,
15+
report_type = ReportType[report_metadata['report']['report_type'].upper()],
16+
report_format = doc_reportview.ReportFormat[report_metadata['report']['report_format'].upper()],
17+
columns=None)
18+
doc_report.generate_report(output_dir="quarto_report/")
19+
doc_report.run_report(output_dir="quarto_report/")
2020

21-
st_report = st_reportview.StreamlitReportView(report_metadata['report']['identifier'], report_metadata['report']['name'],
22-
report=report, report_type = ReportType[report_metadata['report']['report_type'].upper()], columns=None)
23-
st_report.generate_report(output_dir="streamlit_report/sections")
24-
st_report.run_report(output_dir="streamlit_report/sections")
21+
# st_report = st_reportview.StreamlitReportView(report_metadata['report']['id'], report_metadata['report']['name'],
22+
# report=report, report_type = ReportType[report_metadata['report']['report_type'].upper()], columns=None)
23+
# st_report.generate_report(output_dir="streamlit_report/sections")
24+
# st_report.run_report(output_dir="streamlit_report/sections")
2525

report/metadata_manager.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def load_report_metadata(self, file_path: str) -> r.Report:
2424

2525
# Create a Report object
2626
report = r.Report(
27-
identifier=metadata['report']['identifier'],
27+
id=metadata['report']['id'],
2828
name=metadata['report']['name'],
2929
title=metadata['report'].get('title'),
3030
description=metadata['report'].get('description'),
@@ -36,7 +36,7 @@ def load_report_metadata(self, file_path: str) -> r.Report:
3636
# Create Sections
3737
for section_data in metadata['sections']:
3838
section = r.Section(
39-
identifier=section_data['identifier'],
39+
id=section_data['id'],
4040
name=section_data['name'],
4141
title=section_data.get('title'),
4242
description=section_data.get('description'),
@@ -46,7 +46,7 @@ def load_report_metadata(self, file_path: str) -> r.Report:
4646
# Create Subsections
4747
for subsection_data in section_data['subsections']:
4848
subsection = r.Subsection(
49-
identifier=subsection_data['identifier'],
49+
id=subsection_data['id'],
5050
name=subsection_data['name'],
5151
title=subsection_data.get('title'),
5252
description=subsection_data.get('description'),
@@ -57,25 +57,25 @@ def load_report_metadata(self, file_path: str) -> r.Report:
5757
for component_data in subsection_data['components']:
5858
component_type = r.ComponentType[component_data['component_type'].upper()]
5959
file_path = component_data['file_path']
60-
identifier = component_data['identifier']
60+
id = component_data['id']
6161
name = component_data['name']
6262
title = component_data.get('title')
6363
caption = component_data.get('caption')
6464

6565
# Define a component based on its type
6666
if component_type == r.ComponentType.PLOT:
6767
plot_type = r.PlotType[component_data['plot_type'].upper()]
68-
visualization_tool = (r.VisualizationTool[component_data['visualization_tool'].upper()]
69-
if component_data.get('visualization_tool') else None)
68+
int_visualization_tool = (r.IntVisualizationTool[component_data['int_visualization_tool'].upper()]
69+
if component_data.get('int_visualization_tool') else None)
7070
csv_network_format = (r.CSVNetworkFormat[component_data['csv_network_format'].upper()]
7171
if component_data.get('csv_network_format') else None)
7272
# Create a Plot component
7373
component = r.Plot(
74-
identifier=identifier,
74+
id=id,
7575
name=name,
7676
file_path=file_path,
7777
plot_type=plot_type,
78-
visualization_tool=visualization_tool,
78+
int_visualization_tool=int_visualization_tool,
7979
title=title,
8080
caption=caption,
8181
csv_network_format=csv_network_format
@@ -86,7 +86,7 @@ def load_report_metadata(self, file_path: str) -> r.Report:
8686
delimiter = component_data.get('delimiter')
8787
# Create a DataFrame component
8888
component = r.DataFrame(
89-
identifier=identifier,
89+
id=id,
9090
name=name,
9191
file_path=file_path,
9292
file_format=file_format,
@@ -98,7 +98,7 @@ def load_report_metadata(self, file_path: str) -> r.Report:
9898
elif component_type == r.ComponentType.MARKDOWN:
9999
# Create a Markdown component
100100
component = r.Markdown(
101-
identifier=identifier,
101+
id=id,
102102
name=name,
103103
file_path=file_path,
104104
component_type=component_type,

report/quarto_reportview.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ReportFormat(StrEnum):
1111
ODT = auto()
1212
REVEALJS = auto()
1313
PPTX = auto()
14-
JUPYTER = auto()
14+
JUPYTER = auto()
1515

1616
class QuartoReportView(r.ReportView):
1717
"""
@@ -241,21 +241,21 @@ def _generate_plot_content(self, plot, is_report_static) -> List[str]:
241241
else:
242242
html_plot_file = f"quarto_report/{plot.name.replace(' ', '_')}.html"
243243

244-
if plot.visualization_tool == r.VisualizationTool.PLOTLY:
244+
if plot.int_visualization_tool == r.IntVisualizationTool.PLOTLY:
245245
plot_content.append(self._generate_plot_code(plot))
246246
if is_report_static:
247247
plot_content.append(f"""fig_plotly.write_image("{os.path.join("..", static_plot_path)}")\n```\n""")
248248
plot_content.append(self._generate_image_content(static_plot_path, plot.name))
249249
else:
250250
plot_content.append(f"""fig_plotly.show()\n```\n""")
251-
elif plot.visualization_tool == r.VisualizationTool.ALTAIR:
251+
elif plot.int_visualization_tool == r.IntVisualizationTool.ALTAIR:
252252
plot_content.append(self._generate_plot_code(plot))
253253
if is_report_static:
254254
plot_content.append(f"""fig_altair.save("{os.path.join("..", static_plot_path)}")\n```\n""")
255255
plot_content.append(self._generate_image_content(static_plot_path, plot.name))
256256
else:
257257
plot_content.append(f"""fig_altair\n```\n""")
258-
elif plot.visualization_tool == r.VisualizationTool.PYVIS:
258+
elif plot.int_visualization_tool == r.IntVisualizationTool.PYVIS:
259259
G = plot.read_network()
260260
num_nodes = G.number_of_nodes()
261261
num_edges = G.number_of_edges()
@@ -296,13 +296,13 @@ def _generate_plot_code(self, plot, output_file = "") -> str:
296296
plot_data = plot_file.read()
297297
"""
298298
# Add specific code for each visualization tool
299-
if plot.visualization_tool == r.VisualizationTool.PLOTLY:
299+
if plot.int_visualization_tool == r.IntVisualizationTool.PLOTLY:
300300
plot_code += """fig_plotly = pio.from_json(plot_data)
301301
fig_plotly.update_layout(width=950, height=500)
302302
"""
303-
elif plot.visualization_tool == r.VisualizationTool.ALTAIR:
303+
elif plot.int_visualization_tool == r.IntVisualizationTool.ALTAIR:
304304
plot_code += """fig_altair = alt.Chart.from_json(plot_data).properties(width=900, height=400)"""
305-
elif plot.visualization_tool == r.VisualizationTool.PYVIS:
305+
elif plot.int_visualization_tool == r.IntVisualizationTool.PYVIS:
306306
plot_code = f"""<div style="text-align: center;">
307307
<iframe src="{os.path.join("..", output_file)}" alt="{plot.name} plot" width="800px" height="630px"></iframe>
308308
</div>\n"""
@@ -451,8 +451,8 @@ def _generate_component_imports(self, component: r.Component) -> List[str]:
451451
# Dictionary to hold the imports for each component type
452452
components_imports = {
453453
'plot': {
454-
r.VisualizationTool.ALTAIR: ['import altair as alt'],
455-
r.VisualizationTool.PLOTLY: ['import plotly.io as pio']
454+
r.IntVisualizationTool.ALTAIR: ['import altair as alt'],
455+
r.IntVisualizationTool.PLOTLY: ['import plotly.io as pio']
456456
},
457457
'dataframe': ['import pandas as pd', 'from itables import show', 'import dataframe_image as dfi'],
458458
'markdown': ['import IPython.display as display']
@@ -464,9 +464,9 @@ def _generate_component_imports(self, component: r.Component) -> List[str]:
464464

465465
# Add relevant imports based on component type and visualization tool
466466
if component_type == r.ComponentType.PLOT:
467-
visualization_tool = getattr(component, 'visualization_tool', None)
468-
if visualization_tool in components_imports['plot']:
469-
component_imports.extend(components_imports['plot'][visualization_tool])
467+
int_visualization_tool = getattr(component, 'int_visualization_tool', None)
468+
if int_visualization_tool in components_imports['plot']:
469+
component_imports.extend(components_imports['plot'][int_visualization_tool])
470470
elif component_type == r.ComponentType.DATAFRAME:
471471
component_imports.extend(components_imports['dataframe'])
472472
elif component_type == r.ComponentType.MARKDOWN:

0 commit comments

Comments
 (0)