sum.py 4.38 KB
Newer Older
1
#!/usr/bin/env python3
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
## -*- coding: utf-8 -*-
## Copyright (C) 2013 Laboratoire de Recherche et Développement de
## l'Epita (LRDE).
##
## This file is part of Spot, a model checking library.
##
## Spot is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
##
## Spot is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
## License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
import argparse

def latex_escape_char(ch):
  if ch in '#$%&_{}':
    return '\\' + ch
  elif ch in '~^':
    return '\\' + ch + '{}'
  elif ch == '\\':
    return '\\textbackslash'
  else:
    return ch

def latex_escape(x):
  if type(x) == str:
    return ''.join(latex_escape_char(ch) for ch in x)
  return map(latex_escape, x)

def rot(x):
  if type(x) == str:
    return '\\rot{' + x + '}'
  return map(rot, x)


def process_file(filename):
  data = json.load(open(filename))

  ncols = len(data['fields'])
49
  ntools = len(data['tool'])
50
  datacols = range(4, ncols)
51
52
  fields = { name:index for index,name in enumerate(data["fields"]) }
  toolcol = fields['tool']
53
  inputcol = fields['formula']
54
  statescol = fields['states']
55

56
  inputs = data["inputs"]
57
58
59
60

  # Index results by tool, then input
  results = { t:{} for t in range(0, ntools) }
  for l in data["results"]:
61
62
    if l[statescol] == None:
      continue
63
64
65
66
    results[l[toolcol]][l[inputcol]] = l

  for i in range(0, ntools):
    # Remove any leading directory, and trailing %...
67
    name = data["tool"][i]
68
    name = name[name.rfind('/', 0, name.find(' ')) + 1:]
69
    data["tool"][i] = latex_escape(name[0:(name+'%').find('%')])
70

71
72
  timecol = fields['time']

73
74
  print(r'''
\section*{\texttt{%s}}
75
\subsection*{Cumulative summary}''' % latex_escape(filename))
76

77
  print('\\noindent\\begin{tabular}{l' + ('r' * (ncols - 1)) + '}\n',
78
        " & ".join(rot(latex_escape(["tool", "count"] + data["fields"][4:]))),
79
80
81
        "\\\\")
  for i in range(0, ntools):
    # Compute sums over each column.
82
    sums = [("%6.2f" if j == timecol else "%6d") %
83
84
85
            (sum([x[j] for x in results[i].values()]))
            for j in datacols]
    print("\\texttt{%-18s} & %3d & "
86
          % (data["tool"][i], len(results[i])), " & ".join(sums), "\\\\")
87
88
89
90
91
92
93
94
95
96
  print(r'\end{tabular}')

  print(r'''\subsection*{Cross comparison}

How many times did the left tool produce an automaton strictly bigger
than the top tool?  Bigger means more states, or equal number of
states and more transitions.

''')

97
  header = '\\noindent{\\small\\begin{tabular}{l'
98
  for i in data["tool"]:
99
100
101
102
103
104
    header += 'c'
  header += '}'

  transcol = fields['transitions']

  print(header)
105
  for left in data["tool"]:
106
107
108
    print("&", rot("\\texttt{%s}" % left), end=' ')
  print(r'\\')
  for left in range(0, ntools):
109
    print("\\texttt{%-18s}" % data["tool"][left], end=' ')
110
111
112
113
114
115
116
117
118
119
120
    for top in range(0, ntools):
      x = 0
      for k,ct in results[top].items():
        if k in results[left]:
          cl = results[left][k]
          if (cl[statescol] > ct[statescol]
              or (cl[statescol] == ct[statescol]
                  and cl[transcol] > ct[transcol])):
            x += 1
      print("&", x, end=' ')
    print(r"\\")
121
  print(r'\end{tabular}}')
122
123
124
125
126
127
128
129
130
131
132
133
134
135


def main():
  p = argparse.ArgumentParser(description="Process ltlcross' output",
                              epilog="Report bugs to <spot@lrde.epita.fr>.")
  p.add_argument('filenames',
                 help="name of the JSON file to read",
                 nargs='+')
  p.add_argument('--intro',
                 help="introductory text for the LaTeX output",
                 default='')
  args = p.parse_args()

  print(r'''\documentclass{article}
136
\usepackage[a4paper,landscape,margin=1cm]{geometry}
137
138
139
140
141
142
143
144
\usepackage{adjustbox}
\usepackage{array}

\newcolumntype{R}[2]{%
    >{\adjustbox{angle=#1,lap=\width-(#2)}\bgroup}%
    l%
    <{\egroup}%
}
145
\newcommand*\rot{\multicolumn{1}{R{90}{0em}}}% no optional argument here, please!
146
147
148
149
150
151
152
153
154
155

\begin{document}
''')
  print(args.intro)
  for filename in args.filenames:
    process_file(filename)
  print(r'\end{document}')


main()