Files
mtusi2026lab4/student-tests/plot.py
T

37 lines
1.9 KiB
Python

"""Render only measured local evidence; optional matplotlib dependency."""
import json
from pathlib import Path
import statistics
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
ROOT = Path(__file__).resolve().parents[1]
evidence = ROOT / 'evidence'
plt.rcParams.update({'font.family': 'DejaVu Sans', 'font.size': 10})
research = json.loads((evidence / 'reconciliation.json').read_text())
groups = {}
for sample in research['scan_cost']:
groups.setdefault(sample['counts']['metadata'], []).append(sample['elapsed_seconds'])
fig, axes = plt.subplots(1, 2, figsize=(11, 4.2), layout='constrained')
for size, samples in groups.items():
axes[0].scatter([size] * len(samples), [x * 1000 for x in samples], color='#4e79a7', alpha=.65)
axes[0].plot(sorted(groups), [statistics.median(groups[n]) * 1000 for n in sorted(groups)], color='#4e79a7', label='Медиана 3 прогонов')
axes[0].set(xlabel='Число строк метаданных', ylabel='Полный обход, мс', title='Сверка PostgreSQL + S3')
axes[0].legend()
uploads = json.loads((evidence / 'uploads.json').read_text())['experiments']
labels = ['0,51 MiB\n0,18 Мп', '7,21 MiB\n2,52 Мп', '0,51 MiB\n40 Мп']
for i in range(2):
values = [int(list(e['after'].values())[i]['memory.peak']) / 1048576 for e in uploads]
axes[1].bar([n + (i - .5) * .34 for n in range(3)], values, width=.34, label='API ' + str(i + 1))
axes[1].axhline(512, color='#e15759', linestyle='--', label='Лимит на реплику')
axes[1].set(xticks=range(3), xticklabels=labels, ylabel='cgroup memory.peak, MiB', title='10 одновременных upload + download')
axes[1].legend(fontsize=8)
for ax in axes:
ax.grid(axis='y', alpha=.2)
ax.set_axisbelow(True)
fig.suptitle('ЛР 4 · измерения локального стенда · 27 октября 2026')
fig.savefig(evidence / 'research.png', dpi=160)
fig.savefig(evidence / 'research.svg')