From ffc596dc17f5d1528856ef6109a9fbd899b03a97 Mon Sep 17 00:00:00 2001 From: Cosimo Bassi <65770425+cusma@users.noreply.github.com> Date: Sun, 10 Sep 2023 12:30:08 +0200 Subject: [PATCH] PPoS Dex subplots (#23) * PPoS Dex subplots * Nit --- docs/0_cover.md | 2 +- ppos_dex.py | 6 ++++-- src/plots.py | 36 +++++++++++++++++++++++++++++------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/docs/0_cover.md b/docs/0_cover.md index c2b8e36..3a0ba77 100644 --- a/docs/0_cover.md +++ b/docs/0_cover.md @@ -10,4 +10,4 @@ ``` -Algorand Pure Proof of Stake Decentralization Index (by [cusma](https://cusma.algo.xyz)) +Algorand Pure Proof of Stake Decentralization Index (by [cusma](https://x.com/cusma_b)) diff --git a/ppos_dex.py b/ppos_dex.py index 96a4455..2f9ecbc 100644 --- a/ppos_dex.py +++ b/ppos_dex.py @@ -120,10 +120,12 @@ def main(): end_block=args["--end-block"], ) if args["timeseries"]: - print("💾 Saving timeseries in './docs/images/timeseries'...\n") + if args["--save"]: + print("💾 Saving timeseries in './docs/images/timeseries'...\n") plots.timeseries(ppos_dex_data, args["--save"]) elif args["snapshot"]: - print("💾 Saving snapshots in './docs/images/snapshot'...\n") + if args["--save"]: + print("💾 Saving snapshots in './docs/images/snapshot'...\n") plots.snapshot(ppos_dex_data, args["--save"]) elif args["export"]: print("💾 Exporting PPoS Dex data to 'ppos_dex_data.csv'...\n") diff --git a/src/plots.py b/src/plots.py index df2358a..0604900 100644 --- a/src/plots.py +++ b/src/plots.py @@ -132,22 +132,32 @@ def ts_ppos_inequality_unb( def ts_ppos_dex( ppos_dex_v1: list[float | None], + x_axsis_v1: list[int], + x_ticks_v1: list[str], ppos_dex_v2: list[float | None], - x_axsis: list[int], - x_ticks: list[str], + x_axsis_v2: list[int], + x_ticks_v2: list[str], x_ticks_rotation: int = XTICKS_ROTATION, x_ticks_number: int = N_XTICKS, save: bool = False, ) -> None: plt.suptitle("PPoS Dex") + plt.subplot(2, 1, 1) plt.title("(1 = perfect decentralization)", fontsize="medium") - plt.plot(x_axsis, ppos_dex_v1, label="PPoS Dex V1") - plt.plot(x_axsis, ppos_dex_v2, label="PPoS Dex V2") - plt.xticks(x_axsis, x_ticks, rotation=x_ticks_rotation) + plt.plot(x_axsis_v1, ppos_dex_v1, label="PPoS Dex V1") + plt.xticks(x_axsis_v1, x_ticks_v1, rotation=x_ticks_rotation) plt.locator_params(nbins=x_ticks_number) + plt.ylim(0) + plt.grid(True) plt.legend() + plt.subplot(2, 1, 2) + plt.title("(1 = perfect decentralization)", fontsize="medium") + plt.plot(x_axsis_v2, ppos_dex_v2, label="PPoS Dex V2") + plt.xticks(x_axsis_v2, x_ticks_v2, rotation=x_ticks_rotation) + plt.locator_params(nbins=x_ticks_number) plt.ylim(0) plt.grid(True) + plt.legend() plt.tight_layout() if save: plt.savefig(fname="./docs/images/timeseries/ppos_dex") @@ -339,9 +349,21 @@ def timeseries(ppos_dex_data: list[dict], save: bool = False) -> None: ts_ppos_inequality_unb(ppos_theil_l, ppos_theil_t, x_axsis, x_ticks, save=save) # PPoS Dex + ppos_dex_data_v2 = [d for d in ppos_dex_data if d.get("ppos_dex_v2")] + x_axsis_v2 = list(range(len(ppos_dex_data_v2))) + x_ticks_v2 = [d["timestamp"][:10] for d in ppos_dex_data_v2] + ppos_dex_v1 = [d.get("ppos_dex") for d in ppos_dex_data] - ppos_dex_v2 = [d.get("ppos_dex_v2") for d in ppos_dex_data] - ts_ppos_dex(ppos_dex_v1, ppos_dex_v2, x_axsis, x_ticks, save=save) + ppos_dex_v2 = [d.get("ppos_dex_v2") for d in ppos_dex_data_v2] + ts_ppos_dex( + ppos_dex_v1=ppos_dex_v1, + x_axsis_v1=x_axsis, + x_ticks_v1=x_ticks, + ppos_dex_v2=ppos_dex_v2, + x_axsis_v2=x_axsis_v2, + x_ticks_v2=x_ticks_v2, + save=save, + ) def snapshot(ppos_dex_data: list[dict], save: bool = False) -> None: