github.com/pdaian/flashboys2@v0.0.0-20190718175736-b101c35361f0/get_bq_summarystats.py (about) 1 import csv, csv_hack, sys 2 3 infile = sys.argv[1] 4 outfile = sys.argv[2] 5 6 def init_zero_dict(dict, val): 7 if not val in dict: 8 dict[val] = 0 9 10 total_gwei_bid = {} 11 total_gwei_used = {} 12 total_gas_bid = {} 13 total_gas_used = {} 14 15 BINWIDTH = 10000 16 num_txs = 0 17 18 bidsdict = csv.DictReader(open(infile)) 19 for bid in bidsdict: 20 if len(bid['input']) < 8: 21 continue 22 num_txs += 1 23 blocknum = int(bid['block_number']) 24 price_bid = int(bid['gas_price']) 25 gas_bid = int(bid['gas']) 26 gas_used = int(bid['receipt_gas_used']) 27 init_zero_dict(total_gwei_bid, blocknum) 28 init_zero_dict(total_gwei_used, blocknum) 29 init_zero_dict(total_gas_bid, blocknum) 30 init_zero_dict(total_gas_used, blocknum) 31 total_gwei_bid[blocknum] += (price_bid * float(gas_bid)) / (10 ** 9) 32 total_gwei_used[blocknum] += (price_bid * float(gas_used)) / (10 ** 9) 33 total_gas_bid[blocknum] += gas_bid 34 total_gas_used[blocknum] += gas_used 35 36 print("Block range", min(total_gwei_bid.keys()), max(total_gwei_bid.keys())) 37 print("Num txs", num_txs) 38 print("Total gwei bid", sum(total_gwei_bid.values())) 39 print("Total gwei used", sum(total_gwei_used.values())) 40 print("Total gas bid", sum(total_gas_bid.values())) 41 42 blockstats = [0, 0] 43 data = [] 44 for blocknum in range(min(total_gwei_bid.keys()), max(total_gwei_bid.keys()) + 1, BINWIDTH): 45 start = blocknum 46 end = min(blocknum + BINWIDTH, max(total_gwei_bid.keys()) + 1) 47 total_gwei_bid_range = 0 48 total_gwei_used_range = 0 49 total_gas_bid_range = 0 50 total_gas_used_range = 0 51 for i in range(start, end): 52 if i in total_gwei_bid: 53 blockstats[0] += 1 54 total_gwei_bid_range += total_gwei_bid[i] 55 total_gwei_used_range += total_gwei_used[i] 56 total_gas_bid_range += total_gas_bid[i] 57 total_gas_used_range += total_gas_used[i] 58 else: 59 blockstats[1] += 1 60 61 data.append([start, end, total_gwei_bid_range, total_gwei_used_range, total_gas_bid_range, total_gas_used_range]) 62 63 print("Yes/no", blockstats) 64 65 open(outfile, 'w').write(str(data)) 66 67