Skip to content

Commit 0be067c

Browse files
committed
first alpha version
1 parent 6b59ec8 commit 0be067c

File tree

1 file changed

+82
-30
lines changed

1 file changed

+82
-30
lines changed

src/analyzer/crawler-progresion.py

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
import os, sys
66
import json
7+
import time
78
import pandas as pd
89
import matplotlib.pyplot as plt
910
import numpy as np
11+
from datetime import datetime
1012

13+
inittime = 0
1114

1215
def mainexecution():
1316
projectsFolder = sys.argv[1]
@@ -20,7 +23,7 @@ def mainexecution():
2023
clientDist = {'date': [], 'Lighthouse': [], 'Teku': [], 'Nimbus': [], 'Prysm': [], 'Lodestar': [], 'Unknown': []}
2124
stimationDist = {'date': [], 'Lighthouse': [], 'Teku': [], 'Nimbus': [], 'Prysm': [], 'Lodestar': [], 'Unknown': []}
2225
# Concatenation of the Json values
23-
j = []
26+
2427
print(projectsFolder)
2528
for root, dirs, _ in os.walk(projectsFolder):
2629
print(dirs)
@@ -105,55 +108,78 @@ def poblatePandaObservedClients(clientDist, jsonFile, customFile):
105108
cfValues = json.load(cf)
106109
cf.close()
107110

108-
109-
# Aux Variables
110-
tcp13000 = 0
111+
global inittime
111112

112113
crwlig = 0
113114
crwtek = 0
114115
crwnim = 0
115-
crwlod = 0
116116
crwpry = 0
117+
crwlod = 0
117118
crwunk = 0
118119
cnt = 0
119120
for k in jsonValues:
120121
peer = jsonValues[k]
121122
if 'MetadataRequest' in peer:
122123
if peer['MetadataRequest'] == True:
123124
cnt = cnt + 1
124-
if 'Light' in peer['ClientType']:
125+
if 'lig' in peer['ClientType'].lower():
125126
crwlig = crwlig + 1
126-
elif 'Teku' in peer['ClientType']:
127+
elif 'teku' in peer['ClientType'].lower():
127128
crwtek = crwtek + 1
128-
elif 'Nimbus' in peer['ClientType']:
129+
elif 'nimbus' in peer['ClientType'].lower():
129130
crwnim = crwnim + 1
130-
elif 'Prysm' in peer['ClientType']:
131+
elif 'prysm' in peer['ClientType'].lower():
131132
crwpry = crwpry + 1
132-
elif 'Lod' in peer['ClientType']:
133+
elif 'js-libp2p' in peer['ClientType'].lower():
133134
crwlod = crwlod + 1
134-
elif 'Unk' in peer['ClientType']:
135+
elif 'unk' in peer['ClientType'].lower():
136+
crwunk = crwunk + 1
137+
else:
135138
crwunk = crwunk + 1
136139
else:
137140
return
138141

139-
total = crwlig + crwtek + crwtek + crwpry + crwlod + crwunk
140142
print("total in metrics:", len(jsonValues))
141143
print("total requested:", cnt)
142-
print("total of client sum:", total)
143144

144-
if total == 0:
145+
if cnt == 0:
145146
print(jsonValues)
146147
return
147148

148-
lig = round((crwlig*100)/total, 2)
149-
tek = round((crwtek*100)/total, 2)
150-
nim = round((crwnim*100)/total, 2)
151-
pry = round((crwpry*100)/total, 2)
152-
lod = round((crwlod*100)/total, 2)
153-
unk = round((crwunk*100)/total, 2)
154-
155-
cday = str(cfValues['StopTime']['Year']) + '/' + str(cfValues['StopTime']['Month']) + '/' + str(cfValues['StopTime']['Day']) + '-' + str(cfValues['StopTime']['Hour'])
156-
clientDist['date'].append(cday)
149+
lig = round((crwlig*100)/cnt, 3)
150+
tek = round((crwtek*100)/cnt, 3)
151+
nim = round((crwnim*100)/cnt, 3)
152+
pry = round((crwpry*100)/cnt, 3)
153+
lod = round((crwlod*100)/cnt, 3)
154+
unk = round((crwunk*100)/cnt, 3)
155+
156+
if cfValues['StopTime']['Month'] < 10:
157+
month = "0" + str(cfValues['StopTime']['Month'])
158+
else:
159+
month = str(cfValues['StopTime']['Month'])
160+
161+
if cfValues['StopTime']['Day'] < 10:
162+
day = "0" + str(cfValues['StopTime']['Day'])
163+
else:
164+
day = str(cfValues['StopTime']['Day'])
165+
166+
if cfValues['StopTime']['Hour'] < 10:
167+
hour = "0" + str(cfValues['StopTime']['Hour'])
168+
else:
169+
hour = str(cfValues['StopTime']['Hour'])
170+
171+
if cfValues['StopTime']['Minute'] < 10:
172+
minutes = "0" + str(cfValues['StopTime']['Minute'])
173+
else:
174+
minutes = str(cfValues['StopTime']['Minute'])
175+
176+
177+
cday = str(cfValues['StopTime']['Year']) + '/' + month + '/' + day + '-' + hour + '-' + minutes
178+
s = time.mktime(datetime.strptime(cday, "%Y/%m/%d-%H-%M").timetuple())
179+
if inittime == 0:
180+
inittime = s
181+
h = (s -inittime)/(60*60) # to get it in Hours
182+
clientDist['date'].append(h)
157183
clientDist['Lighthouse'].append(lig)
158184
clientDist['Teku'].append(tek)
159185
clientDist['Nimbus'].append(nim)
@@ -171,6 +197,8 @@ def poblatePandaStimatedClients(stimatedDist, jsonFile, customFile):
171197
cfValues = json.load(cf)
172198
cf.close()
173199

200+
global inittime
201+
174202
# Aux Variables
175203
tcp13000 = 0
176204

@@ -185,15 +213,15 @@ def poblatePandaStimatedClients(stimatedDist, jsonFile, customFile):
185213
if 'MetadataRequest' in peer:
186214
if peer['MetadataRequest'] == True:
187215
cnt = cnt + 1
188-
if 'Light' in peer['ClientType']:
216+
if 'lig' in peer['ClientType'].lower():
189217
crwlig = crwlig + 1
190-
elif 'Teku' in peer['ClientType']:
218+
elif 'teku' in peer['ClientType'].lower():
191219
crwtek = crwtek + 1
192-
elif 'Nimbus' in peer['ClientType']:
220+
elif 'nimbus' in peer['ClientType'].lower():
193221
crwnim = crwnim + 1
194-
elif 'Lod' in peer['ClientType']:
222+
elif 'js-libp2p' in peer['ClientType'].lower():
195223
crwlod = crwlod + 1
196-
elif 'Unk' in peer['ClientType']:
224+
elif 'unk' in peer['ClientType'].lower():
197225
crwunk = crwunk + 1
198226
if '/13000' in peer['Addrs']:
199227
tcp13000 = tcp13000 + 1
@@ -225,8 +253,32 @@ def poblatePandaStimatedClients(stimatedDist, jsonFile, customFile):
225253
lod = round((estimlod*100)/total, 2)
226254
unk = round((estimunk*100)/total, 2)
227255

228-
cday = str(cfValues['StopTime']['Year']) + '/' + str(cfValues['StopTime']['Month']) + '/' + str(cfValues['StopTime']['Day']) + '-' + str(cfValues['StopTime']['Hour'])
229-
stimatedDist['date'].append(cday)
256+
if cfValues['StopTime']['Month'] < 10:
257+
month = "0" + str(cfValues['StopTime']['Month'])
258+
else:
259+
month = str(cfValues['StopTime']['Month'])
260+
261+
if cfValues['StopTime']['Day'] < 10:
262+
day = "0" + str(cfValues['StopTime']['Day'])
263+
else:
264+
day = str(cfValues['StopTime']['Day'])
265+
266+
if cfValues['StopTime']['Hour'] < 10:
267+
hour = "0" + str(cfValues['StopTime']['Hour'])
268+
else:
269+
hour = str(cfValues['StopTime']['Hour'])
270+
271+
if cfValues['StopTime']['Minute'] < 10:
272+
minutes = "0" + str(cfValues['StopTime']['Minute'])
273+
else:
274+
minutes = str(cfValues['StopTime']['Minute'])
275+
276+
cday = str(cfValues['StopTime']['Year']) + '/' + month + '/' + day + '-' + hour + '-' + minutes
277+
s = time.mktime(datetime.strptime(cday, "%Y/%m/%d-%H-%M").timetuple())
278+
if inittime == 0:
279+
inittime = s
280+
h = (s -inittime)/(60*60) # to get it in Hours
281+
stimatedDist['date'].append(h)
230282
stimatedDist['Lighthouse'].append(lig)
231283
stimatedDist['Teku'].append(tek)
232284
stimatedDist['Nimbus'].append(nim)

0 commit comments

Comments
 (0)