forked from com-chain/pyc3l
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blockRateMonitoring.py
49 lines (38 loc) · 1.25 KB
/
blockRateMonitoring.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from PythonClient.ApiHandling import ApiHandling
from PythonClient.ApiCommunication import ApiCommunication
from datetime import datetime, timedelta
import numpy as np
import time
# Load the API
api_handling = ApiHandling()
# refresh the node list
api_handling.updateNodeRepo()
#load the high level functions
api_com = ApiCommunication(api_handling, 'Lemanopolis')
# configure run
test_duration = 20 # [min]
step = 2 # [sec]
number = int((test_duration*60)/step)
# test run
blocks = []
dt = []
print('Staring the run. See you in '+str(test_duration)+' min')
start_block = api_com.getBlockNumber()
start_time = datetime.now()
for counter in range(number):
curr_block = api_com.getBlockNumber()
curr_time = datetime.now()
if curr_block>start_block:
delta = curr_time - start_time
sec = delta.total_seconds()
blocks.append(start_block)
dt.append(sec)
start_block = curr_block
start_time = curr_time
print('New block after '+str(sec)+' s')
time.sleep(step)
# output result
total_block = len(blocks)
delta_times = np.array(dt)
average_dt = np.sum(delta_times)/total_block
print('During the '+str(test_duration)+' min run '+str(total_block)+' blocks where added average delay ='+str(average_dt)+' s.')