Skip to content

Commit a9f922e

Browse files
committed
Add script to analyze the global overview of the client distribution
1 parent 5c11252 commit a9f922e

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# This file compiles the code to analyze the gathered metrics from each of the
2+
# folders in the $ARMIARMAPATH/examples folder, providing a global overview of the
3+
# Peer distributions and client types over the dayly analysis
4+
5+
import os, sys
6+
import json
7+
import pandas as pd
8+
import matplotlib.pyplot as plt
9+
10+
11+
def mainexecution():
12+
projectsFolder = sys.argv[1]
13+
14+
# So far, the generated panda will just contain the client count
15+
p = {'date': [], 'Lighthouse': [], 'Teku': [], 'Nimbus': [], 'Prysm': [], 'Lodestar': [], 'Unknown': []}
16+
print(projectsFolder)
17+
for root, dirs, _ in os.walk(projectsFolder):
18+
print(dirs)
19+
# We just need to access the folders inside examples
20+
for d in dirs:
21+
fold = os.path.join(root, d)
22+
f = fold + '/metrics/custom-metrics.json'
23+
if os.path.exists(f):
24+
# Load the readed values from the json into the panda
25+
poblatePandaCustomMetrics(p, f)
26+
break
27+
# After filling the dict with all the info from the JSONs, generate the panda
28+
df = pd.DataFrame (p, columns = ['date', 'Lighthouse', 'Teku', 'Nimbus', 'Prysm', 'Lodestar', 'Unknown'])
29+
print(df)
30+
31+
clientList = ['Lighthouse', 'Teku', 'Nimbus', 'Prysm', 'Lodestar', 'Unknown']
32+
figSize = (10,6)
33+
titleSize = 24
34+
textSize = 20
35+
labelSize = 20
36+
# Plot the images
37+
plotStackedChart(df, opts={
38+
'figSize': figSize,
39+
'figTitle': 'CrawlSummary.png',
40+
'align': 'center',
41+
'textSize': textSize,
42+
'title': "Evolution of the observed client distribution",
43+
'ylabel': 'Client concentration (%)',
44+
'xlabel': None,
45+
'legendLabels': clientList,
46+
'titleSize': titleSize,
47+
'labelSize': labelSize,
48+
'lengendPosition': 1,
49+
'legendSize': labelSize,
50+
'tickRotation': 90,
51+
'show': True})
52+
53+
def poblatePandaCustomMetrics(p, jsonFile):
54+
print('poblating panda')
55+
# Read the Json
56+
jsf = open(jsonFile)
57+
jsonValues = json.load(jsf)
58+
jsf.close()
59+
60+
# Compose the date of the crawling day
61+
cday = str(jsonValues['StartTime']['Year']) + '-' + str(jsonValues['StartTime']['Month']) + '-' + str(jsonValues['StartTime']['Day'])
62+
p['date'].append(cday)
63+
ps = jsonValues['PeerStore']['ConnectionSucceed']['Total']
64+
# Get percentages for each of the clients
65+
lig = (100 * int(jsonValues['PeerStore']['ConnectionSucceed']['Lighthouse']['Total'])) / ps
66+
tek = (100 * int(jsonValues['PeerStore']['ConnectionSucceed']['Teku']['Total'])) / ps
67+
nim = (100 * int(jsonValues['PeerStore']['ConnectionSucceed']['Nimbus']['Total'])) / ps
68+
pry = (100 * int(jsonValues['PeerStore']['ConnectionSucceed']['Prysm']['Total'])) / ps
69+
lod = (100 * int(jsonValues['PeerStore']['ConnectionSucceed']['Lodestar']['Total'])) / ps
70+
unk = (100 * int(jsonValues['PeerStore']['ConnectionSucceed']['Unknown']['Total'])) / ps
71+
72+
p['Lighthouse'].append(lig)
73+
p['Teku'].append(tek)
74+
p['Nimbus'].append(nim)
75+
p['Prysm'].append(pry)
76+
p['Lodestar'].append(lod)
77+
p['Unknown'].append(unk)
78+
79+
80+
def plotStackedChart(p, opts):
81+
82+
ax = p.plot.area(figsize = opts['figSize'], x='date', stacked=True)
83+
84+
# labels
85+
if opts['ylabel'] is not None:
86+
plt.ylabel(opts['ylabel'], fontsize=opts['labelSize'])
87+
if opts['xlabel'] is not None:
88+
plt.xlabel(opts['xlabel'], fontsize=opts['labelSize'])
89+
90+
handles,legends = ax.get_legend_handles_labels()
91+
ax.legend(handles=handles, labels=opts['legendLabels'], loc='upper center', bbox_to_anchor=(0.5, -0.05), fancybox=True, shadow=True, ncol=6)
92+
93+
plt.title(opts['title'], fontsize = opts['titleSize'])
94+
plt.tight_layout()
95+
#plt.savefig(outputFile)
96+
if opts['show'] is True:
97+
plt.show()
98+
99+
if __name__ == '__main__':
100+
mainexecution()

0 commit comments

Comments
 (0)