Skip to content

Commit 2d963a3

Browse files
committed
new code
1 parent 32ab85e commit 2d963a3

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test1.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def calculate_tx_num_sum(filename, start_height, end_height):
2+
total_tx_num = 0
3+
in_target_range = False
4+
5+
with open(filename, 'r') as file:
6+
for line in file:
7+
if 'ProposeBlockTxs:' in line:
8+
if 'block.height =' in line:
9+
parts = line.split('block.height =')
10+
if len(parts) > 1:
11+
height_str = parts[1].split()[0].strip()
12+
try:
13+
height = int(height_str)
14+
if start_height <= height <= end_height:
15+
in_target_range = True
16+
else:
17+
in_target_range = False
18+
except ValueError:
19+
pass
20+
21+
if in_target_range and 'tx num =' in line:
22+
parts = line.split('tx num =')
23+
if len(parts) > 1:
24+
tx_num_str = parts[1].strip()
25+
try:
26+
tx_num = int(tx_num_str)
27+
total_tx_num += tx_num
28+
except ValueError:
29+
pass
30+
31+
return total_tx_num
32+
33+
34+
filename = 'output.log'
35+
start_height = 36
36+
end_height = 79
37+
sum_tx_num = calculate_tx_num_sum(filename, start_height, end_height)
38+
print(
39+
f"Sum of tx num from block.height {start_height} to {end_height}: {sum_tx_num}")

0 commit comments

Comments
 (0)