4
0
mirror of https://github.com/cwinfo/yggdrasil-map synced 2025-08-14 15:58:10 +00:00

add histogramming code, update crawler, allow longer names

This commit is contained in:
Arceliar
2021-07-31 10:34:52 -05:00
parent 17c800f4b1
commit 19cdf8de34
3 changed files with 51 additions and 1 deletions

41
scripts/ratio.py Normal file
View File

@@ -0,0 +1,41 @@
#!/usr/bin/env python2.7
import json
with open("current", "r") as f:
data = json.loads(f.read())
kinds = ["peers", "dht", "ratio"]
results = dict()
for kind in kinds:
results[kind] = dict()
for k,v in data["yggnodes"].iteritems():
for kind in kinds:
if kind not in v: continue
num = len(v[kind])
if num not in results[kind]: results[kind][num] = 0
results[kind][num] += 1
# Added ratio part
if "dht" in v and "peers" in v:
ratio = float(len(v["dht"]))/len(v["peers"])
if ratio not in results["ratio"]: results["ratio"][ratio] = 0
results["ratio"][ratio] += 1
import matplotlib.pyplot as plt
fig, axs = plt.subplots(1, len(kinds), sharey=True, tight_layout=True)
for kdx in xrange(len(kinds)):
kind = kinds[kdx]
bins = []
for num,count in results[kind].iteritems():
bins += [num]*count
nbins = max(results[kind].keys())+1
axs[kdx].set_title(kind)
if kind == "ratio":
nbins="auto"
axs[kdx].set_title("ratio (dht/peers)")
axs[kdx].hist(bins, bins=nbins)
plt.savefig("fig.svg")
print results