in visualize/generate.py [0:0]
def visualize_output(filepath,only_workload:bool):
log_items = read_csv_and_structure_data(filepath,only_workload)
#pie
data_by_epoch_comm = split_data_by_epoch(1,log_items) #only comm
comm_type_counts = count_by_epoch(data_by_epoch_comm)
pie_chart = create_pie_chart_for_epoch(comm_type_counts['epoch_0'])
data = extract_data_from_log_items(data_by_epoch_comm['epoch_0'])
#commtype Scatter
effect_scatter_by_commtype = create_scatter_chart("commtype",data)
#commtype cdf
cdf_data = calculate_cdf_by_commtype(data)
cdf_chart = create_cdf_chart_by_commtype(cdf_data)
#group Scatter
effect_scatter_by_group = create_scatter_chart("group",data)
#comp-comm pattern
data_by_epoch = split_data_by_epoch(0, log_items)
timeline_charts = []
ratio_pies = []
all_ratio_pie = []
if not only_workload:
all_iterations = extract_iteration(data_by_epoch['epoch_0'])
for iteration in all_iterations:
timeline_chart, ratio_pie = create_timeline_chart(iteration)
timeline_charts.append(timeline_chart.dump_options())
ratio_pies.append(ratio_pie.dump_options())
all_ratio_pie = create_ratio_pie(data_by_epoch['epoch_0'])
else:
all_ratio_pie = None
context = {
'pie_chart_js': pie_chart.dump_options(),
'scatter_by_commtype_js': effect_scatter_by_commtype.dump_options(),
'cdf_chart_js': cdf_chart.dump_options(),
'scatter_by_group_js': effect_scatter_by_group.dump_options(),
'timeline_charts_js': json.dumps(timeline_charts),
'ratio_pies_js': json.dumps(ratio_pies),
'iteration_count': len(all_iterations) if not only_workload else 0,
'all_ratio_pie':all_ratio_pie.dump_options() if all_ratio_pie else None,
}
# read Example.html
with open('visualize/example.html', 'r', encoding='utf-8') as f:
template = Template(f.read())
rendered_html = template.render(**context)
# write to file
default_folder_path = 'results/visual_output'
if not os.path.exists(default_folder_path):
os.makedirs(default_folder_path, exist_ok=True)
filename = os.path.basename(filepath).split(".")[0]+'.html'
output_file = os.path.join('results/visual_output',filename)
with open(output_file, 'w', encoding='utf-8') as f:
f.write(rendered_html)
print(f"Report generated:{output_file}")