mirror of
https://github.com/Lore09/Tesi-Magistrale.git
synced 2025-12-19 04:14:35 +00:00
added line plot
This commit is contained in:
@@ -2,6 +2,8 @@ import seaborn as sns
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import yaml
|
import yaml
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import numpy as np
|
||||||
|
import os
|
||||||
|
|
||||||
# Function to read and parse the file
|
# Function to read and parse the file
|
||||||
def read_metrics(file_path):
|
def read_metrics(file_path):
|
||||||
@@ -28,29 +30,59 @@ for run in runs:
|
|||||||
# Convert to DataFrame
|
# Convert to DataFrame
|
||||||
df = pd.DataFrame(data)
|
df = pd.DataFrame(data)
|
||||||
|
|
||||||
# Function to plot and add median labels
|
# Make sure the benchmark directory exists
|
||||||
def plot_metric(metric, filename, color):
|
os.makedirs('benchmark', exist_ok=True)
|
||||||
subset = df[df['Type'] == metric]
|
|
||||||
plt.figure(figsize=(8, 6))
|
|
||||||
ax = sns.boxplot(x='Task', y='Time', data=subset, color=color)
|
|
||||||
|
|
||||||
# Add median labels
|
# 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()
|
medians = subset.groupby('Task')['Time'].median()
|
||||||
for i, task in enumerate(medians.index):
|
for i, task in enumerate(medians.index):
|
||||||
median_value = medians[task]
|
median_value = medians[task]
|
||||||
ax.text(i, median_value, f'{median_value:.3f}', ha='center', va='center',
|
plt.text(i, median_value, f'{median_value:.3f}', ha='center', va='center', fontsize=10, color='white',
|
||||||
fontsize=10, color='white', bbox=dict(facecolor='black', alpha=0.6, boxstyle='round,pad=0.3'))
|
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')
|
||||||
|
|
||||||
|
# Fill missing x-axis values
|
||||||
|
min_task = subset['Task'].min()
|
||||||
|
max_task = subset['Task'].max()
|
||||||
|
all_tasks = np.arange(min_task, max_task + 1)
|
||||||
|
plt.xticks(all_tasks)
|
||||||
|
|
||||||
|
# Label points
|
||||||
|
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.title(f'{metric} by Number of Tasks')
|
|
||||||
plt.xlabel('Number of Tasks')
|
plt.xlabel('Number of Tasks')
|
||||||
plt.ylabel('Time (seconds)')
|
plt.ylabel('Time (seconds)')
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.7)
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
plt.savefig(filename)
|
plt.savefig(f'benchmark/{filename}')
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
# Plot each metric separately
|
# Plot each metric separately
|
||||||
plot_metric('Build Time', 'res/build_time_boxplot.png', 'skyblue')
|
plot_boxplot('Build Time', 'build_time_boxplot.png', 'skyblue')
|
||||||
plot_metric('Generation Time', 'res/gen_time_boxplot.png', 'lightgreen')
|
plot_lineplot('Build Time', 'build_time_lineplot.png', 'skyblue')
|
||||||
plot_metric('Deployment Time', 'res/deploy_time_boxplot.png', 'salmon')
|
|
||||||
|
|
||||||
print('Plots saved successfully!')
|
plot_boxplot('Generation Time', 'gen_time_boxplot.png', 'lightgreen')
|
||||||
|
plot_lineplot('Generation Time', 'gen_time_lineplot.png', 'lightgreen')
|
||||||
|
|
||||||
|
plot_boxplot('Deployment Time', 'deploy_time_boxplot.png', 'salmon')
|
||||||
|
plot_lineplot('Deployment Time', 'deploy_time_lineplot.png', 'salmon')
|
||||||
|
|
||||||
|
print('Plots saved successfully in "benchmark" directory!')
|
||||||
Reference in New Issue
Block a user