Skip to content

Commit 15c2926

Browse files
Mikel CortesMikel Cortes
authored andcommitted
Add overall view analyzer as little mods in analyzer
1 parent a9f922e commit 15c2926

File tree

3 files changed

+61
-19
lines changed

3 files changed

+61
-19
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ src/bin
88

99
# Ignore the example folder (personal to each user)
1010
examples/*
11+
# Ignore the example folder (personal to each user)
12+
results/*
1113

12-
# Ignore System Files
14+
# Ignore System Files (from MAC)
1315
.DS_Store
1416
._.DS_Store
1517

1618
# ignore the venv
1719
src/analyzer/venv
18-
19-
src/analyzer/dashboard/static/plots

src/analyzer/armiarma-analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ def main():
752752

753753
## -- website code --
754754
print("\n")
755-
print("Results from crawler run on [month] running for [crawling time].<br>Total amount of peers on the peerstore:", peerstoreLen,".<br>Number of clients with the TPC port at 13000 (Prysm?):", cnt13000,".<br>Percentage of 'Prysm' peers from the peerstore (based on the TCP port):", round((cnt13000*100)/peerstoreLen,2),"%.<br>We manage to connect with", succeed,"peers from the peerstore.<br>This would be the distribution.")
755+
print("Results from crawler run on [month] running for [crawling time].\n<br>Total amount of peers on the peerstore:", peerstoreLen,".\n<br>Number of clients with the TPC port at 13000 (Prysm?):", cnt13000,".\n<br>Percentage of 'Prysm' peers from the peerstore (based on the TCP port):", round((cnt13000*100)/peerstoreLen,2),"%.\n<br>We manage to connect with", succeed,"peers from the peerstore.\n<br>This would be the distribution.")
756756
print("\n")
757757

758758

src/analyzer/total-overview-analysis.py

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,41 @@
66
import json
77
import pandas as pd
88
import matplotlib.pyplot as plt
9+
import numpy as np
910

1011

1112
def mainexecution():
1213
projectsFolder = sys.argv[1]
14+
outFolder = sys.argv[2]
1315

16+
outJson = outFolder + '/' + 'client-distribution.json'
1417
# So far, the generated panda will just contain the client count
1518
p = {'date': [], 'Lighthouse': [], 'Teku': [], 'Nimbus': [], 'Prysm': [], 'Lodestar': [], 'Unknown': []}
19+
# Concatenation of the Json values
20+
j = []
1621
print(projectsFolder)
1722
for root, dirs, _ in os.walk(projectsFolder):
1823
print(dirs)
24+
dirs.sort()
1925
# We just need to access the folders inside examples
2026
for d in dirs:
2127
fold = os.path.join(root, d)
2228
f = fold + '/metrics/custom-metrics.json'
2329
if os.path.exists(f):
2430
# Load the readed values from the json into the panda
25-
poblatePandaCustomMetrics(p, f)
31+
poblatePandaCustomMetrics(p, j, f)
2632
break
33+
34+
# Export the Concatenated json to the given folder
35+
with open(outJson, 'w', encoding='utf-8') as f:
36+
json.dump(j, f, ensure_ascii=False, indent=4)
37+
2738
# After filling the dict with all the info from the JSONs, generate the panda
2839
df = pd.DataFrame (p, columns = ['date', 'Lighthouse', 'Teku', 'Nimbus', 'Prysm', 'Lodestar', 'Unknown'])
40+
df = df.sort_values(by="date")
2941
print(df)
3042

43+
outputFigsFolder = outFolder + '/' + 'plots'
3144
clientList = ['Lighthouse', 'Teku', 'Nimbus', 'Prysm', 'Lodestar', 'Unknown']
3245
figSize = (10,6)
3346
titleSize = 24
@@ -36,12 +49,16 @@ def mainexecution():
3649
# Plot the images
3750
plotStackedChart(df, opts={
3851
'figSize': figSize,
39-
'figTitle': 'CrawlSummary.png',
52+
'figTitle': 'Client-Distribution.png',
53+
'figtitle': 'client-distribution.png',
54+
'outputPath': outputFigsFolder,
4055
'align': 'center',
56+
'grid': 'y',
4157
'textSize': textSize,
42-
'title': "Evolution of the observed client distribution",
58+
'title': "Evolution of the projected client distribution",
4359
'ylabel': 'Client concentration (%)',
44-
'xlabel': None,
60+
'xlabel': None,
61+
'yticks': np.arange(0, 110, 10),
4562
'legendLabels': clientList,
4663
'titleSize': titleSize,
4764
'labelSize': labelSize,
@@ -50,24 +67,43 @@ def mainexecution():
5067
'tickRotation': 90,
5168
'show': True})
5269

53-
def poblatePandaCustomMetrics(p, jsonFile):
54-
print('poblating panda')
70+
def poblatePandaCustomMetrics(p, j, jsonFile):
5571
# Read the Json
5672
jsf = open(jsonFile)
5773
jsonValues = json.load(jsf)
5874
jsf.close()
75+
76+
# Add readed Json to the previous ones (concatenate them)
77+
j.append(jsonValues)
5978

6079
# Compose the date of the crawling day
6180
cday = str(jsonValues['StartTime']['Year']) + '-' + str(jsonValues['StartTime']['Month']) + '-' + str(jsonValues['StartTime']['Day'])
6281
p['date'].append(cday)
63-
ps = jsonValues['PeerStore']['ConnectionSucceed']['Total']
82+
ps = jsonValues['PeerStore']['Total']
6483
# 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
84+
crwlig = jsonValues['PeerStore']['ConnectionSucceed']['Lighthouse']['Total']
85+
crwtek = jsonValues['PeerStore']['ConnectionSucceed']['Teku']['Total']
86+
crwnim = jsonValues['PeerStore']['ConnectionSucceed']['Nimbus']['Total']
87+
crwlod = jsonValues['PeerStore']['ConnectionSucceed']['Lodestar']['Total']
88+
crwunk = jsonValues['PeerStore']['ConnectionSucceed']['Unknown']['Total']
89+
90+
prysPort = jsonValues['PeerStore']['Port13000']
91+
res = ps - prysPort
92+
93+
noPrysm = crwlig + crwtek + crwnim + crwlod + crwunk
94+
95+
estimlig = (res*crwlig)/noPrysm
96+
estimtek = (res*crwtek)/noPrysm
97+
estimnim = (res*crwnim)/noPrysm
98+
estimlod = (res*crwlod)/noPrysm
99+
estimunk = (res*crwunk)/noPrysm
100+
101+
lig = round((estimlig*100)/ps, 2)
102+
tek = round((estimtek*100)/ps, 2)
103+
nim = round((estimnim*100)/ps, 2)
104+
pry = round((prysPort*100)/ps, 2)
105+
lod = round((estimlod*100)/ps, 2)
106+
unk = round((estimunk*100)/ps, 2)
71107

72108
p['Lighthouse'].append(lig)
73109
p['Teku'].append(tek)
@@ -78,7 +114,8 @@ def poblatePandaCustomMetrics(p, jsonFile):
78114

79115

80116
def plotStackedChart(p, opts):
81-
117+
outputFile = str(opts['outputPath']) + '/' + opts['figTitle']
118+
82119
ax = p.plot.area(figsize = opts['figSize'], x='date', stacked=True)
83120

84121
# labels
@@ -90,9 +127,14 @@ def plotStackedChart(p, opts):
90127
handles,legends = ax.get_legend_handles_labels()
91128
ax.legend(handles=handles, labels=opts['legendLabels'], loc='upper center', bbox_to_anchor=(0.5, -0.05), fancybox=True, shadow=True, ncol=6)
92129

130+
if opts['grid'] != None:
131+
ax.grid(which='major', axis=opts['grid'], linestyle='--')
132+
133+
plt.yticks(opts['yticks'])
134+
93135
plt.title(opts['title'], fontsize = opts['titleSize'])
94136
plt.tight_layout()
95-
#plt.savefig(outputFile)
137+
plt.savefig(outputFile)
96138
if opts['show'] is True:
97139
plt.show()
98140

0 commit comments

Comments
 (0)