-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Yarom Swisa <[email protected] git config --global user.name Yarom>
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import requests | ||
from datetime import datetime | ||
|
||
def fetch_block_data(block_number): | ||
# URL that returns a JSON response | ||
url = 'https://lava.rest.lava.build/cosmos/base/tendermint/v1beta1/blocks/' + block_number | ||
|
||
# Fetch the data from the URL | ||
response = requests.get(url) | ||
|
||
# Parse the JSON data | ||
json_data = response.json() | ||
block_header = json_data.get("sdk_block").get("header") | ||
|
||
height = block_header.get("height") | ||
|
||
dt = datetime.strptime(block_header.get("time")[:26] + "Z", "%Y-%m-%dT%H:%M:%S.%fZ") | ||
time = dt.timestamp() | ||
|
||
proposer = block_header.get("proposer_address") | ||
|
||
return [int(height), float(time), proposer] | ||
|
||
stats_before = {} | ||
stats_current = {} | ||
current = fetch_block_data("latest") | ||
for i in range(10000): | ||
print(f"Progress: {i}", end='\r') | ||
before = fetch_block_data(str(current[0]-1)) | ||
|
||
if current[2] not in stats_current: | ||
stats_current[current[2]] = {"good": 0, "bad": 0} | ||
|
||
if before[2] not in stats_before: | ||
stats_before[before[2]] = {"good": 0, "bad": 0} | ||
|
||
if current[1] - before[1] < 10: | ||
stats_current[current[2]]["bad"] += 1 | ||
stats_before[before[2]]["bad"] += 1 | ||
else: | ||
stats_current[current[2]]["good"] += 1 | ||
stats_before[before[2]]["good"] += 1 | ||
|
||
current = before | ||
|
||
print(stats_before) | ||
print("---------------------------------------------------------------------") | ||
# print(stats_current) | ||
|
||
|