make_table.py 6.01 KB
Newer Older
Stefan Jaax's avatar
Stefan Jaax committed
1
2
3
import sys
import pandas as pd

4
5
6
7
prop_steps = {}
prop_steps['termination'] = '$|\mathcal{P}|$'
prop_steps['consensus']   = '$|R|$'
prop_steps['correctness'] = '$|R|$'
Stefan Jaax's avatar
Stefan Jaax committed
8
9
10
11

max_params = 2

long_table = True
12
13
short_table = False

14
15
results_file = 'results/results.csv'

Stefan Jaax's avatar
Stefan Jaax committed
16
17
if len(sys.argv) >= 2:
    for arg in sys.argv[1:]:
18
19
20
21
22
23
24
25
26
27
        if arg[0] == '-':
            if arg == '-s':
                long_table = False
                short_table = True
            elif arg == '-l':
                long_table = True
                short_table = False
            else:
                print("unknown argument: %s" % arg, file=sys.stderr)
                sys.exit(-1)
Stefan Jaax's avatar
Stefan Jaax committed
28
        else:
29
            results_file = sys.argv[1]
Stefan Jaax's avatar
Stefan Jaax committed
30
31
32
33
34

# long table

if long_table:

35
36
37
    results = pd.read_csv(results_file)

    properties = list(map(lambda s: s[:-7], filter(lambda s: s[-7:] == "_result", results.columns.values, )))
Stefan Jaax's avatar
Stefan Jaax committed
38
39
40
41
42
43
44
45
46
47
48
49

    alignrow = "\\begin{longtable}{l"
    for i in range(max_params):
        alignrow += 'l'
    alignrow += 'rr'
    for prop in properties:
        alignrow += 'rr'
    alignrow += 'r}'
    print(alignrow)
    print("\\toprule")

    headerrow = "protocol & \\multicolumn{%d}{c}{params} & $|Q|$ & $|T|$" % max_params
50
51
    for prop in properties:
        headerrow +=  " & %s & %s" % (prop, prop_steps[prop])
Stefan Jaax's avatar
Stefan Jaax committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    headerrow += " & total \\\\"
    print(headerrow)

    last_protocol = ''
    last_params = []
    for i in range(max_params):
        last_params.append('')

    for result in results.iterrows():
        row = result[1]
        row_string = ''

        protocol = row['protocol']
        filename = row['file']

        protocol_changed = False
        if protocol != last_protocol:
            protocol_changed = True
            print("\\midrule")
            row_string = "%s" % protocol
            last_protocol = protocol
            for i in range(max_params):
                last_params[i] = ''
        else:
            row_string = ""

78
        params = [ p for p in filename[len(protocol):].split('.')[0].split('_') if len(p) >= 2 ]
Stefan Jaax's avatar
Stefan Jaax committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

        for i in range(len(params)):
            var = params[i][0]
            val = params[i][1:]
            param_string = "$%s = %s$" % (var, val)
            if last_params[i] != param_string:
                #if i == 0 and len(params) > 1 and not protocol_changed:
                #    print("\\cline{2-%d}" % (4 + max_params + 2*len(properties)))
                last_params[i] = param_string
                row_string += " & %s" % param_string
                for j in range(i+1, max_params):
                    last_params[j] = ''
            else:
                row_string += " &"
        for i in range(len(params), max_params):
            row_string += " &"

96
        n_states = row['states']
Stefan Jaax's avatar
Stefan Jaax committed
97
        n_transitions = row['transitions']
98
        row_string += ' & %d & %d' % (n_states, n_transitions)
Stefan Jaax's avatar
Stefan Jaax committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138

        total_time = 0.0
        total_timeout = False

        for prop in properties:
            prop_result = row[prop + '_result']
            prop_time = row[prop + '_time'] / 10**9
            prop_refinements = row[prop + '_refinements']
            prop_string = ''
            if prop_result == 'positive':
                prop_string = "%.2f" % prop_time
            elif prop_result == 'dontknow':
                prop_string = "%.2f (?)" % prop_time
            elif prop_result == 'timeout':
                prop_string = 'timeout'
                total_timeout = True
            else:
                prop_string = 'error'
            try:
                refinement_string = str(int(prop_refinements))
            except ValueError:
                refinement_string ='-'
            row_string += " & %s & %s" % (prop_string, refinement_string)
            total_time += prop_time

        row_string += " & "
        if total_timeout:
            row_string += "timeout"
        else:
            row_string += "%.2f" % total_time
        row_string += " \\\\"

        print(row_string)

    print("\\bottomrule")
    print("\\end{longtable}")

# short table

if short_table:
139
    results_file='results.csv'
Stefan Jaax's avatar
Stefan Jaax committed
140

141
142
143
    results = pd.read_csv(results_file)

    properties = list(map(lambda s: s[:-7], filter(lambda s: s[-7:] == "_result", results.columns.values, )))
Stefan Jaax's avatar
Stefan Jaax committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

    last_protocol = ''
    last_params = []
    for i in range(max_params):
        last_params.append('')

    for result in results.iterrows():
        row = result[1]
        row_string = ''

        protocol = row['protocol']
        filename = row['file']

        protocol_changed = False
        if protocol != last_protocol:
            protocol_changed = True
            if last_protocol != '':
                print("\\bottomrule")
                print("\\end{tabular}")
            last_protocol = protocol
            print("\\begin{tabular}{rrrr}")
            print("\\toprule")
            print("\multicolumn{3}{c}{%s} \\\\" % protocol)
            print("\\midrule")
            print("$m$ & $|Q|$ & $|T|$ & Time\,(s) \\\\")
            print("\\midrule")

171
        params = [ p for p in filename[len(protocol):].split('.')[0].split('_') if len(p) >= 2 ]
Stefan Jaax's avatar
Stefan Jaax committed
172
173
174
175
176

        if len(params) > 0:
            val = params[0][1:]
            row_string += "%s " % val

177
        n_states = row['states']
Stefan Jaax's avatar
Stefan Jaax committed
178
        n_transitions = row['transitions']
179
        row_string += ' & %d & %d' % (n_states, n_transitions)
Stefan Jaax's avatar
Stefan Jaax committed
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

        total_time = 0.0
        total_timeout = False
        total_error = False

        for prop in properties:
            prop_result = row[prop + '_result']
            if prop_result == 'positive':
                prop_time = row[prop + '_time'] / 10**9
                total_time += prop_time
            elif prop_result == 'timeout':
                total_timeout = True
            else:
                total_error = True

        row_string += " & "
        if total_timeout:
            row_string += "timeout"
        elif total_error:
            row_string += "error"
        else:
            row_string += "%.1f" % total_time
        row_string += " \\\\"

        print(row_string)

    if last_protocol != '':
        print("\\bottomrule")
        print("\\end{tabular}")