import csv from pathlib import Path import matplotlib.pyplot as plt def create_plot(csv_path="docs/data/results_summary.csv", output_path="docs/data/performance.png"): with Path(csv_path).open(encoding="utf-8-sig") as file: rows = list(csv.DictReader(file)) operations = ["insert", "find_110", "delete_50"] titles = ["Вставка всех записей", "Поиск 110 имён", "Удаление 50 записей"] labels = [(structure, mode) for mode in ("shuffled", "sorted") for structure in ("LinkedList", "HashTable", "BST")] figure, axes = plt.subplots(1, 3, figsize=(15, 5)) for axis, operation, title in zip(axes, operations, titles): values = [] for structure, mode in labels: row = next(item for item in rows if item["structure"] == structure and item["mode"] == mode and item["operation"] == operation) values.append(float(row["mean_seconds"]) * 1000) axis.bar(range(len(labels)), values, color=["#4472C4", "#70AD47", "#ED7D31"] * 2) axis.set_title(title) axis.set_ylabel("Время, мс") axis.set_xticks(range(len(labels)), [f"{s}\n{m}" for s, m in labels], rotation=35, ha="right") axis.grid(axis="y", alpha=0.25) figure.suptitle("Производительность структур данных (средние значения)") figure.tight_layout() figure.savefig(output_path, dpi=180) plt.close(figure) return Path(output_path) if __name__ == "__main__": print(f"График сохранён: {create_plot()}")