Skip to content

Commit

Permalink
PPoS Dex subplots (#23)
Browse files Browse the repository at this point in the history
* PPoS Dex subplots

* Nit
  • Loading branch information
cusma committed Sep 10, 2023
1 parent 3e097a7 commit ffc596d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/0_cover.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
6 changes: 4 additions & 2 deletions ppos_dex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
36 changes: 29 additions & 7 deletions src/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ffc596d

Please sign in to comment.