forked from UNN/2026-rff_mp
53 lines
2.1 KiB
Python
53 lines
2.1 KiB
Python
|
|
import pandas as pd
|
|||
|
|
import matplotlib.pyplot as plt
|
|||
|
|
import seaborn as sns
|
|||
|
|
import sys
|
|||
|
|
import os
|
|||
|
|
|
|||
|
|
def plot_results(csv_file: str, output_dir: str = "plots"):
|
|||
|
|
if not os.path.exists(csv_file):
|
|||
|
|
print(f"Файл {csv_file} не найден.")
|
|||
|
|
return
|
|||
|
|
df = pd.read_csv(csv_file, encoding='utf-8')
|
|||
|
|
required = ["лабиринт", "стратегия", "время_мс", "посещено_клеток", "длина_пути"]
|
|||
|
|
for col in required:
|
|||
|
|
if col not in df.columns:
|
|||
|
|
print(f"В CSV отсутствует колонка {col}")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
os.makedirs(output_dir, exist_ok=True)
|
|||
|
|
|
|||
|
|
sns.set_style("whitegrid")
|
|||
|
|
|
|||
|
|
for maze_name in df["лабиринт"].unique():
|
|||
|
|
maze_df = df[df["лабиринт"] == maze_name]
|
|||
|
|
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
|
|||
|
|
fig.suptitle(f"Сравнение стратегий для лабиринта {maze_name}", fontsize=14)
|
|||
|
|
|
|||
|
|
ax = axes[0]
|
|||
|
|
sns.barplot(data=maze_df, x="стратегия", y="время_мс", ax=ax, palette="viridis")
|
|||
|
|
ax.set_title("Время выполнения (мс)")
|
|||
|
|
ax.set_ylabel("мс")
|
|||
|
|
|
|||
|
|
ax = axes[1]
|
|||
|
|
sns.barplot(data=maze_df, x="стратегия", y="посещено_клеток", ax=ax, palette="plasma")
|
|||
|
|
ax.set_title("Количество посещённых клеток")
|
|||
|
|
ax.set_ylabel("клетки")
|
|||
|
|
|
|||
|
|
ax = axes[2]
|
|||
|
|
sns.barplot(data=maze_df, x="стратегия", y="длина_пути", ax=ax, palette="coolwarm")
|
|||
|
|
ax.set_title("Длина найденного пути")
|
|||
|
|
ax.set_ylabel("шаги")
|
|||
|
|
|
|||
|
|
plt.tight_layout()
|
|||
|
|
plt.savefig(os.path.join(output_dir, f"results_{maze_name}.png"), dpi=150)
|
|||
|
|
plt.close()
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
if len(sys.argv) < 2:
|
|||
|
|
print("Использование: python tables.py <csv_файл> <папка_для_сохранения>")
|
|||
|
|
print("Пример: python tables.py res.csv plots")
|
|||
|
|
sys.exit(1)
|
|||
|
|
csv_file = sys.argv[1]
|
|||
|
|
out_dir = sys.argv[2] if len(sys.argv) > 2 else "plots"
|
|||
|
|
plot_results(csv_file, out_dir)
|