@@ -24,7 +24,7 @@ def parties(df):
24
24
def utxo (df ):
25
25
return df .set_index ("UTxO" )
26
26
27
- def compare_to_md (f , old , new ):
27
+ def compare (f , old , new ):
28
28
# New should be better, so we compare to that.
29
29
df = f (new ) - f (old )
30
30
@@ -34,6 +34,9 @@ def compare_to_md(f, old, new):
34
34
# Round everything to 2 decimals
35
35
df = df .round (2 )
36
36
37
+ return df
38
+
39
+ def to_markdown (df ):
37
40
# Add colour
38
41
def update_colour (x ):
39
42
if x == 0 :
@@ -51,30 +54,37 @@ def update_colour(x):
51
54
52
55
return df .to_markdown ()
53
56
54
- print ("Transaction cost differences" )
55
57
56
- # First is the script size
58
+ # We ignore the first table, namely the metadata, that's why the base/branch
59
+ # index starts at 1.
60
+
61
+ diffs = [
62
+ # First is the script size
63
+ (headers [0 ], compare ( script_size , base [1 ], branch [1 ]))
64
+ # Then Init,
65
+ , (headers [1 ], compare ( parties , base [2 ], branch [2 ]))
66
+ # Then Commit is different; it doesn't have a "Parties" column
67
+ , (headers [2 ], compare ( utxo , base [3 ], branch [3 ]))
68
+ ]
57
69
58
- print (f"## { headers [0 ]} " )
59
- print ("" )
60
- print ( compare_to_md ( script_size , base [1 ], branch [1 ]) )
70
+ # Then the remaining are all the same.
71
+ for i in range (4 , 9 + 1 ):
72
+ diffs .append (( headers [i - 1 ]
73
+ , compare ( parties , base [i ], branch [i ] )
74
+ ))
61
75
62
- # Then Init,
63
- print ("" )
64
- print (f"## { headers [1 ]} " )
65
- print ("" )
66
- print ( compare_to_md (parties , base [2 ], branch [2 ]) )
76
+ # Check that ther was _some_ difference, at least.
77
+ some_change = any ( df .to_numpy ().sum () != 0 for _ , df in diffs )
67
78
68
- # Then Commit is different; it doesn't have a "Parties" column
79
+ print ( "# Transaction cost differences" )
69
80
70
- print ("" )
71
- print (f"## { headers [2 ]} " )
72
- print ("" )
73
- print ( compare_to_md (utxo , base [3 ], branch [3 ]) )
81
+ if not (some_change ):
82
+ print ("No cost or size differences found" )
83
+ exit (0 )
74
84
75
- # The remaining are all the same as Init.
76
- for i in range (4 , 9 + 1 ):
85
+ for (header , df ) in diffs :
77
86
print ("" )
78
- print (f"## { headers [ i - 1 ] } " )
87
+ print (f"## { header } " )
79
88
print ("" )
80
- print ( compare_to_md (parties , base [i ], branch [i ]) )
89
+ diff = to_markdown (df )
90
+ print (diff )
0 commit comments