mirror of
https://github.com/Lore09/Tesi-Magistrale.git
synced 2025-12-19 12:24:31 +00:00
moved plots to utils
This commit is contained in:
31
utils/plot-startup.py
Normal file
31
utils/plot-startup.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import matplotlib.pyplot as plt
|
||||
import seaborn as sns
|
||||
import random
|
||||
import pandas as pd
|
||||
|
||||
# Genera i dati mock
|
||||
data = [{"tempo di esecuzione": round(random.gauss(23, 1), 3)} for _ in range(9)]
|
||||
df = pd.DataFrame(data)
|
||||
|
||||
# Creazione del boxplot con grafico più largo e barra più stretta
|
||||
plt.figure(figsize=(10, 6)) # Grafico più largo
|
||||
ax = sns.boxplot(y=df["tempo di esecuzione"], width=0.3, flierprops={"marker": "o", "color": "red", "markersize": 8}, color="lightgreen")
|
||||
|
||||
# Calcolo della media
|
||||
mean_value = df["tempo di esecuzione"].mean()
|
||||
|
||||
# Aggiungi il testo della media alla base
|
||||
plt.text(0, 0, f'Media: {mean_value:.2f}', ha='center', va='bottom', fontsize=14, fontweight='bold', color="black")
|
||||
|
||||
# Imposta i label con font più grande
|
||||
plt.ylabel("Downtime (s)", fontsize=14)
|
||||
plt.xticks([]) # Rimuove i tick sull'asse X
|
||||
plt.yticks(fontsize=12)
|
||||
|
||||
# Mostra griglia leggera
|
||||
plt.grid(axis='y', linestyle='--', alpha=0.6)
|
||||
|
||||
# Salva il plot
|
||||
plt.tight_layout()
|
||||
plt.savefig("benchmark/boxplot_failover.png")
|
||||
plt.show()
|
||||
98
utils/plot_compared_metrics.py
Normal file
98
utils/plot_compared_metrics.py
Normal file
@@ -0,0 +1,98 @@
|
||||
import seaborn as sns
|
||||
import matplotlib.pyplot as plt
|
||||
import yaml
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
# Function to read and parse a metric file
|
||||
def read_metrics(file_path, label):
|
||||
with open(file_path, 'r') as file:
|
||||
data = yaml.safe_load(file)
|
||||
runs = data['runs']
|
||||
|
||||
extracted_data = []
|
||||
for run in runs:
|
||||
if 'build' in run:
|
||||
extracted_data.append({'Task': run['n_task'], 'Type': 'Build Time', 'Time': float(run['build']['components_build_time']), 'Source': label})
|
||||
|
||||
if 'code_gen' in run:
|
||||
extracted_data.append({'Task': run['n_task'], 'Type': 'Generation Time', 'Time': float(run['code_gen']['gen_time']), 'Source': label})
|
||||
|
||||
if 'deploy' in run:
|
||||
extracted_data.append({'Task': run['n_task'], 'Type': 'Deployment Time', 'Time': float(run['deploy']['components_deploy_time']), 'Source': label})
|
||||
|
||||
if 'time_total' in run:
|
||||
extracted_data.append({'Task': run['n_task'], 'Type': 'Total Time', 'Time': float(run['time_total']), 'Source': label})
|
||||
|
||||
return extracted_data
|
||||
|
||||
# Paths for the two metric files
|
||||
file_path_1 = 'res/metrics/metrics-parallel-nats.yaml' # First metrics file
|
||||
file_path_2 = 'res/metrics/metrics-sequential.yaml' # Second metrics file
|
||||
|
||||
# Read and combine the data
|
||||
data1 = read_metrics(file_path_1, 'Esecuzione Parallelizzata')
|
||||
data2 = read_metrics(file_path_2, 'Esecuzione Sequenziale')
|
||||
|
||||
df = pd.DataFrame(data1 + data2)
|
||||
|
||||
# Ensure benchmark directory exists
|
||||
os.makedirs('benchmark', exist_ok=True)
|
||||
|
||||
# Function to plot boxplot
|
||||
def plot_boxplot(metric, filename):
|
||||
subset = df[df['Type'] == metric]
|
||||
plt.figure(figsize=(10, 6))
|
||||
sns.boxplot(x='Task', y='Time', hue='Source', data=subset, showfliers=False)
|
||||
|
||||
plt.ylabel('Time (seconds)')
|
||||
plt.grid(True, linestyle='--', alpha=0.7)
|
||||
plt.legend(title='Source')
|
||||
plt.tight_layout()
|
||||
plt.savefig(f'benchmark/{filename}')
|
||||
plt.close()
|
||||
|
||||
# Function to plot line plot with confidence intervals
|
||||
def plot_lineplot(metric, filename):
|
||||
subset = df[df['Type'] == metric]
|
||||
plt.figure(figsize=(10, 6))
|
||||
sns.lineplot(x='Task', y='Time', hue='Source', data=subset, errorbar=('ci', 95), linewidth=2, marker='o')
|
||||
|
||||
plt.xlabel('Number of Tasks')
|
||||
plt.ylabel('Time (seconds)')
|
||||
plt.grid(True, linestyle='--', alpha=0.7)
|
||||
plt.legend(title='Source')
|
||||
plt.tight_layout()
|
||||
plt.savefig(f'benchmark/{filename}')
|
||||
plt.close()
|
||||
|
||||
# Function to plot bar plot with confidence intervals
|
||||
def plot_barplot(metric, filename):
|
||||
subset = df[df['Type'] == metric]
|
||||
plt.figure(figsize=(10, 6))
|
||||
|
||||
sns.barplot(x='Task', y='Time', hue='Source', data=subset, errorbar=('ci', 95), palette=['salmon', 'skyblue'])
|
||||
|
||||
plt.xlabel('Task', fontsize=14) # Aumenta la dimensione del font dell'asse X
|
||||
plt.ylabel('Time (seconds)', fontsize=14) # Aumenta la dimensione del font dell'asse Y
|
||||
plt.xticks(fontsize=12) # Modifica la dimensione del font dei tick dell'asse X
|
||||
plt.yticks(fontsize=12) # Modifica la dimensione del font dei tick dell'asse Y
|
||||
plt.legend(title='Source', title_fontsize=14, fontsize=12) # Modifica il font della legenda
|
||||
|
||||
plt.grid(True, linestyle='--', alpha=0.7)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f'benchmark/{filename}')
|
||||
plt.close()
|
||||
|
||||
|
||||
# Generate plots for each metric
|
||||
metrics = ['Build Time', 'Generation Time', 'Deployment Time', 'Total Time']
|
||||
filenames = ['build_time', 'gen_time', 'deploy_time', 'total_time']
|
||||
|
||||
for metric, filename in zip(metrics, filenames):
|
||||
#plot_boxplot(metric, f'{filename}_boxplot.png')
|
||||
#plot_lineplot(metric, f'{filename}_lineplot.png')
|
||||
plot_barplot(metric, f'{filename}_paired_barplot.png')
|
||||
|
||||
print('Comparison plots saved successfully in "benchmark" directory!')
|
||||
113
utils/plot_metrics.py
Normal file
113
utils/plot_metrics.py
Normal file
@@ -0,0 +1,113 @@
|
||||
import seaborn as sns
|
||||
import matplotlib.pyplot as plt
|
||||
import yaml
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
# Function to read and parse the file
|
||||
def read_metrics(file_path):
|
||||
with open(file_path, 'r') as file:
|
||||
data = yaml.safe_load(file)
|
||||
return data['runs']
|
||||
|
||||
# Read metrics from the file
|
||||
file_path = 'res/metrics-parallel.yaml' # Replace with your file path
|
||||
runs = read_metrics(file_path)
|
||||
|
||||
# Flatten data into a list of dictionaries
|
||||
data = []
|
||||
for run in runs:
|
||||
if 'build' in run:
|
||||
data.append({'Task': run['n_task'], 'Type': 'Build Time', 'Time': float(run['build']['components_build_time'])})
|
||||
|
||||
if 'code_gen' in run:
|
||||
data.append({'Task': run['n_task'], 'Type': 'Generation Time', 'Time': float(run['code_gen']['gen_time'])})
|
||||
|
||||
if 'deploy' in run:
|
||||
data.append({'Task': run['n_task'], 'Type': 'Deployment Time', 'Time': float(run['deploy']['components_deploy_time'])})
|
||||
|
||||
if 'time_total' in run:
|
||||
data.append({'Task': run['n_task'], 'Type': 'Total Time', 'Time': float(run['time_total'])})
|
||||
|
||||
# Convert to DataFrame
|
||||
df = pd.DataFrame(data)
|
||||
|
||||
# Make sure the benchmark directory exists
|
||||
os.makedirs('benchmark', exist_ok=True)
|
||||
|
||||
# Function to plot boxplot
|
||||
def plot_boxplot(metric, filename, color):
|
||||
subset = df[df['Type'] == metric]
|
||||
plt.figure(figsize=(10, 6))
|
||||
sns.boxplot(x='Task', y='Time', data=subset, color=color, showfliers=False)
|
||||
|
||||
# Label median values
|
||||
medians = subset.groupby('Task')['Time'].median()
|
||||
for i, task in enumerate(medians.index):
|
||||
median_value = medians[task]
|
||||
plt.text(i, median_value, f'{median_value:.3f}', ha='center', va='center', fontsize=10, color='white',
|
||||
bbox=dict(facecolor='black', alpha=0.6, boxstyle='round,pad=0.3'))
|
||||
|
||||
plt.ylabel('Time (seconds)')
|
||||
plt.grid(True, linestyle='--', alpha=0.7)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f'benchmark/{filename}')
|
||||
plt.close()
|
||||
|
||||
# Function to plot line plot with confidence intervals
|
||||
def plot_lineplot(metric, filename, color):
|
||||
subset = df[df['Type'] == metric]
|
||||
plt.figure(figsize=(10, 6))
|
||||
sns.lineplot(x='Task', y='Time', data=subset, errorbar=('ci', 95), color=color, linewidth=2, marker='o')
|
||||
|
||||
min_task = subset['Task'].min()
|
||||
max_task = subset['Task'].max()
|
||||
all_tasks = np.arange(min_task, max_task + 1)
|
||||
plt.xticks(all_tasks)
|
||||
|
||||
for i, row in subset.groupby('Task')['Time'].median().reset_index().iterrows():
|
||||
plt.text(row['Task'], row['Time'], f'{row["Time"]:.3f}', ha='center', va='bottom', fontsize=10)
|
||||
|
||||
plt.xlabel('Number of Tasks')
|
||||
plt.ylabel('Time (seconds)')
|
||||
plt.grid(True, linestyle='--', alpha=0.7)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f'benchmark/{filename}')
|
||||
plt.close()
|
||||
|
||||
# Function to plot bar plot with confidence intervals
|
||||
def plot_barplot(metric, filename, color):
|
||||
subset = df[df['Type'] == metric]
|
||||
plt.figure(figsize=(10, 6))
|
||||
sns.barplot(x='Task', y='Time', data=subset, color=color, errorbar=('ci', 95))
|
||||
|
||||
means = subset.groupby('Task')['Time'].mean()
|
||||
for i, task in enumerate(means.index):
|
||||
mean_value = means[task]
|
||||
plt.text(i, 0, f'{mean_value:.3f}', ha='center', va='bottom', fontsize=10, alpha=0.7)
|
||||
|
||||
plt.ylabel('Time (seconds)')
|
||||
plt.grid(True, linestyle='--', alpha=0.7)
|
||||
plt.tight_layout()
|
||||
plt.savefig(f'benchmark/{filename}')
|
||||
plt.close()
|
||||
|
||||
# Plot each metric separately
|
||||
#plot_boxplot('Build Time', 'build_time_boxplot.png', 'skyblue')
|
||||
#plot_lineplot('Build Time', 'build_time_lineplot.png', 'skyblue')
|
||||
plot_barplot('Build Time', 'build_time_barplot.png', 'skyblue')
|
||||
|
||||
#plot_boxplot('Generation Time', 'gen_time_boxplot.png', 'lightgreen')
|
||||
#plot_lineplot('Generation Time', 'gen_time_lineplot.png', 'lightgreen')
|
||||
plot_barplot('Generation Time', 'gen_time_barplot.png', 'lightgreen')
|
||||
|
||||
#plot_boxplot('Deployment Time', 'deploy_time_boxplot.png', 'salmon')
|
||||
#plot_lineplot('Deployment Time', 'deploy_time_lineplot.png', 'salmon')
|
||||
plot_barplot('Deployment Time', 'deploy_time_barplot.png', 'salmon')
|
||||
|
||||
#plot_boxplot('Total Time', 'total_time_boxplot.png', 'purple')
|
||||
#plot_lineplot('Total Time', 'total_time_lineplot.png', 'purple')
|
||||
plot_barplot('Total Time', 'total_time_barplot.png', 'orange')
|
||||
|
||||
print('Plots saved successfully in "benchmark" directory!')
|
||||
Reference in New Issue
Block a user