61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
|
|
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import csv
|
||
|
|
from collections import defaultdict
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
import matplotlib.pyplot as plt
|
||
|
|
|
||
|
|
|
||
|
|
def load_average_results(csv_file: str):
|
||
|
|
results = []
|
||
|
|
with open(csv_file, "r", encoding="utf-8") as f:
|
||
|
|
reader = csv.DictReader(f)
|
||
|
|
for row in reader:
|
||
|
|
if row["Замер"] != "среднее":
|
||
|
|
continue
|
||
|
|
results.append({
|
||
|
|
"structure": row["Структура"],
|
||
|
|
"mode": row["Режим"],
|
||
|
|
"operation": row["Операция"],
|
||
|
|
"time": float(row["Время (сек)"]),
|
||
|
|
})
|
||
|
|
return results
|
||
|
|
|
||
|
|
|
||
|
|
def build_graphs(results, output_dir: str = "docs/data"):
|
||
|
|
output = Path(output_dir)
|
||
|
|
output.mkdir(parents=True, exist_ok=True)
|
||
|
|
|
||
|
|
grouped = defaultdict(list)
|
||
|
|
for row in results:
|
||
|
|
grouped[row["operation"]].append(row)
|
||
|
|
|
||
|
|
for operation in ("insert", "find", "delete"):
|
||
|
|
rows = grouped[operation]
|
||
|
|
labels = [f"{r['structure']}\n{r['mode']}" for r in rows]
|
||
|
|
values = [r["time"] for r in rows]
|
||
|
|
|
||
|
|
plt.figure(figsize=(11, 6))
|
||
|
|
plt.bar(labels, values)
|
||
|
|
plt.title(f"{operation.capitalize()} comparison")
|
||
|
|
plt.xlabel("Structure / data order")
|
||
|
|
plt.ylabel("Time, seconds")
|
||
|
|
plt.xticks(rotation=20)
|
||
|
|
plt.tight_layout()
|
||
|
|
filename = output / f"{operation}.png"
|
||
|
|
plt.savefig(filename, dpi=160)
|
||
|
|
plt.close()
|
||
|
|
print(f"Saved {filename}")
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
results = load_average_results("results.csv")
|
||
|
|
build_graphs(results)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|