import csv import os import matplotlib.pyplot as plt data = [] with open("docs/data/results.csv", "r", encoding="utf-8") as file: reader = csv.DictReader(file) for row in reader: data.append(row) def get_average(structure, order, operation): for row in data: if ( row["structure"] == structure and row["order"] == order and row["operation"] == operation ): return float(row["average"]) return 0 structures = ["LinkedList", "HashTable", "BST"] orders = ["random", "sorted"] os.makedirs("docs/data", exist_ok=True) for operation in ["insert", "find", "delete"]: random_values = [ get_average(s, "random", operation) for s in structures ] sorted_values = [ get_average(s, "sorted", operation) for s in structures ] x = range(len(structures)) plt.figure() plt.bar([i - 0.2 for i in x], random_values, width=0.4, label="random") plt.bar([i + 0.2 for i in x], sorted_values, width=0.4, label="sorted") plt.xticks(list(x), structures) plt.ylabel("Time, seconds") plt.title(operation.capitalize() + " time") plt.yscale("log") plt.legend() plt.tight_layout() plt.savefig("docs/data/graph_" + operation + ".png") plt.close() print("Graphs saved to docs/data/")