"""Membuat Gambar 1-3 naskah dari data/*.csv (matplotlib).""" import csv, os, sys import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt sys.path.insert(0, os.path.dirname(__file__)) import model_saas as model # noqa: E402 D = os.path.join(os.path.dirname(__file__), "..", "data") G = os.path.join(os.path.dirname(__file__), "..", "gambar") os.makedirs(G, exist_ok=True) plt.rcParams.update({"font.family": "DejaVu Sans", "font.size": 10, "axes.spines.top": False, "axes.spines.right": False}) TEAL, ORANGE, GREY, RED = "#0f766e", "#c2410c", "#9ca3af", "#dc2626" rd = lambda n: list(csv.DictReader(open(os.path.join(D, n)))) # Gambar 1: p95 & rerata vs N + titik DES xs = list(range(10, 96)) p95 = [model.metrics(n, 2.0, 40.0, 8)["p95_ms"] for n in xs] mean = [model.metrics(n, 2.0, 40.0, 8)["mean_ms"] for n in xs] v = rd("validasi_des.csv") fig, ax = plt.subplots(figsize=(6.4, 3.6), dpi=200) ax.plot(xs, p95, color=TEAL, lw=2, label="p95 model (Erlang C)") ax.plot(xs, mean, color=GREY, lw=1.6, ls="--", label="Rerata model") ax.errorbar([int(r["N"]) for r in v], [float(r["p95_des_ms"]) for r in v], yerr=[float(r["p95_des_ik95"]) for r in v], fmt="o", color=ORANGE, ms=5, capsize=3, label="p95 simulasi DES (IK 95%)") ax.axhline(model.SLO_MS, color=RED, ls=":", lw=1.4) ax.text(11, model.SLO_MS + 6, "SLO p95 = 200 ms", color=RED, fontsize=9) ax.axvline(90, color=TEAL, lw=0.8, alpha=.4) ax.text(88.5, 60, "N maks = 90", rotation=90, color=TEAL, fontsize=8, va="bottom", ha="right") ax.set_xlabel("Jumlah tenant per node (N)") ax.set_ylabel("Waktu tanggap (ms)") ax.set_ylim(0, 340) ax.legend(frameon=False, fontsize=8, loc="upper left") fig.tight_layout() fig.savefig(os.path.join(G, "gambar1_latensi.png")) # Gambar 2: biaya per tenant vs N s = rd("sapuan_tenant.csv") fig, ax = plt.subplots(figsize=(6.4, 3.3), dpi=200) ns = [int(r["N"]) for r in s if r["memenuhi_slo"] == "1"] by = [float(r["biaya_tenant_rp_bulan"]) / 1000 for r in s if r["memenuhi_slo"] == "1"] ax.plot(ns, by, color=TEAL, lw=2, marker="o", ms=3.5) ax.axhline(547.5, color=ORANGE, ls="--", lw=1.4) ax.text(52, 565, "Isolasi penuh: Rp547,5 ribu", color=ORANGE, fontsize=9) ax.annotate("N = 90: Rp48,7 ribu", xy=(90, 48.667), xytext=(62, 170), arrowprops=dict(arrowstyle="->", color=TEAL), color=TEAL, fontsize=9) ax.set_xlabel("Jumlah tenant per node (N)") ax.set_ylabel("Biaya per tenant (ribu Rp/bulan)") ax.set_ylim(0, 620) fig.tight_layout() fig.savefig(os.path.join(G, "gambar2_biaya.png")) # Gambar 3: N maks vs jumlah worker untuk tiga waktu layanan z = rd("sensitivitas.csv") fig, ax = plt.subplots(figsize=(6.4, 3.3), dpi=200) for sv, col, lab in (("20.0", TEAL, "S = 20 ms"), ("40.0", ORANGE, "S = 40 ms"), ("80.0", GREY, "S = 80 ms (SLO tidak tercapai)")): rr = [r for r in z if r["layanan_ms"] == sv] ax.plot([int(r["worker_c"]) for r in rr], [int(r["n_maks"]) for r in rr], marker="o", color=col, lw=2, label=lab) ax.set_xscale("log", base=2) ax.set_xticks([4, 8, 16, 32]); ax.set_xticklabels(["4", "8", "16", "32"]) ax.set_xlabel("Jumlah worker per node (c)") ax.set_ylabel("N maks (tenant per node)") ax.legend(frameon=False, fontsize=8) fig.tight_layout() fig.savefig(os.path.join(G, "gambar3_sensitivitas.png")) print("ok")