Skip to content

Commit ffc596d

Browse files
authored
PPoS Dex subplots (#23)
* PPoS Dex subplots * Nit
1 parent 3e097a7 commit ffc596d

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

docs/0_cover.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
1111
```
1212

13-
Algorand Pure Proof of Stake Decentralization Index (by [cusma](https://cusma.algo.xyz))
13+
Algorand Pure Proof of Stake Decentralization Index (by [cusma](https://x.com/cusma_b))

ppos_dex.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,12 @@ def main():
120120
end_block=args["--end-block"],
121121
)
122122
if args["timeseries"]:
123-
print("💾 Saving timeseries in './docs/images/timeseries'...\n")
123+
if args["--save"]:
124+
print("💾 Saving timeseries in './docs/images/timeseries'...\n")
124125
plots.timeseries(ppos_dex_data, args["--save"])
125126
elif args["snapshot"]:
126-
print("💾 Saving snapshots in './docs/images/snapshot'...\n")
127+
if args["--save"]:
128+
print("💾 Saving snapshots in './docs/images/snapshot'...\n")
127129
plots.snapshot(ppos_dex_data, args["--save"])
128130
elif args["export"]:
129131
print("💾 Exporting PPoS Dex data to 'ppos_dex_data.csv'...\n")

src/plots.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,32 @@ def ts_ppos_inequality_unb(
132132

133133
def ts_ppos_dex(
134134
ppos_dex_v1: list[float | None],
135+
x_axsis_v1: list[int],
136+
x_ticks_v1: list[str],
135137
ppos_dex_v2: list[float | None],
136-
x_axsis: list[int],
137-
x_ticks: list[str],
138+
x_axsis_v2: list[int],
139+
x_ticks_v2: list[str],
138140
x_ticks_rotation: int = XTICKS_ROTATION,
139141
x_ticks_number: int = N_XTICKS,
140142
save: bool = False,
141143
) -> None:
142144
plt.suptitle("PPoS Dex")
145+
plt.subplot(2, 1, 1)
143146
plt.title("(1 = perfect decentralization)", fontsize="medium")
144-
plt.plot(x_axsis, ppos_dex_v1, label="PPoS Dex V1")
145-
plt.plot(x_axsis, ppos_dex_v2, label="PPoS Dex V2")
146-
plt.xticks(x_axsis, x_ticks, rotation=x_ticks_rotation)
147+
plt.plot(x_axsis_v1, ppos_dex_v1, label="PPoS Dex V1")
148+
plt.xticks(x_axsis_v1, x_ticks_v1, rotation=x_ticks_rotation)
147149
plt.locator_params(nbins=x_ticks_number)
150+
plt.ylim(0)
151+
plt.grid(True)
148152
plt.legend()
153+
plt.subplot(2, 1, 2)
154+
plt.title("(1 = perfect decentralization)", fontsize="medium")
155+
plt.plot(x_axsis_v2, ppos_dex_v2, label="PPoS Dex V2")
156+
plt.xticks(x_axsis_v2, x_ticks_v2, rotation=x_ticks_rotation)
157+
plt.locator_params(nbins=x_ticks_number)
149158
plt.ylim(0)
150159
plt.grid(True)
160+
plt.legend()
151161
plt.tight_layout()
152162
if save:
153163
plt.savefig(fname="./docs/images/timeseries/ppos_dex")
@@ -339,9 +349,21 @@ def timeseries(ppos_dex_data: list[dict], save: bool = False) -> None:
339349
ts_ppos_inequality_unb(ppos_theil_l, ppos_theil_t, x_axsis, x_ticks, save=save)
340350

341351
# PPoS Dex
352+
ppos_dex_data_v2 = [d for d in ppos_dex_data if d.get("ppos_dex_v2")]
353+
x_axsis_v2 = list(range(len(ppos_dex_data_v2)))
354+
x_ticks_v2 = [d["timestamp"][:10] for d in ppos_dex_data_v2]
355+
342356
ppos_dex_v1 = [d.get("ppos_dex") for d in ppos_dex_data]
343-
ppos_dex_v2 = [d.get("ppos_dex_v2") for d in ppos_dex_data]
344-
ts_ppos_dex(ppos_dex_v1, ppos_dex_v2, x_axsis, x_ticks, save=save)
357+
ppos_dex_v2 = [d.get("ppos_dex_v2") for d in ppos_dex_data_v2]
358+
ts_ppos_dex(
359+
ppos_dex_v1=ppos_dex_v1,
360+
x_axsis_v1=x_axsis,
361+
x_ticks_v1=x_ticks,
362+
ppos_dex_v2=ppos_dex_v2,
363+
x_axsis_v2=x_axsis_v2,
364+
x_ticks_v2=x_ticks_v2,
365+
save=save,
366+
)
345367

346368

347369
def snapshot(ppos_dex_data: list[dict], save: bool = False) -> None:

0 commit comments

Comments
 (0)