1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """ Reports.py - Classes and functions to generate text, html and latex reports
23
24 logilab.common have some classes for reporting in text, html, docbook.
25 we might use their stuff here....
26
27 """
28
29 __all__ = ['ImpedanceMaximaListing', 'ImpedanceMaximaComparison',
30 'MeasurementDataDescription','WebPage']
31
32 import numpy
33
36 print >>f, "\\begin{table}[ht]"
37 print >>f, "\\caption{%s}"%self.title
38 print >>f, "\\begin{tabular}{|r|r|r|r|r|r|r|}"
39 print >>f, "\hline"
40
42 print >>f, "\hline"
43 print >>f, "\\end{tabular}"
44 print >>f, "\\end{table}"
45
46 - def _write_table_data(self, f):
47 for row in self.data:
48 i = 0
49 for cell in row:
50 if i != 0:
51 f.write(" & ")
52 if type(cell) is numpy.float64:
53 f.write("%.2f"%cell)
54 else:
55 f.write("%s"%cell)
56 i = i + 1
57 f.write("\\\\\n")
58
59 - def latex_export(self, f):
64
65 td = "<td align=\"right\" >"
66
69 print >>f, "<table frame=\"box\" rules=\"group\">"
70 print >>f, "<caption><em>%s</em></caption>"%self.title
71
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
95
96
97
100 self.title = title
101 self.data = data
102
104 print >>f, "<tr><th>Maxima frequency [Hz] <th>Maxima magnitude",\
105 "<th> Frequency ratio fn/f1"
106
108 fudamental_frequency = self.data[0][0]
109 for f1, A1 in self.data:
110 print >>f, "<tr>" + td + "%.2f"%f1 + td +"%.2f"%A1 + td +\
111 "%.3f"%f1/fudamental_frequency
112
113
114
115
116
117
118
121 self.title = title
122 self.data = comparison
123
125 print >>f, "<tr><th colspan=\"2\">Maxima frequency [Hz] (Ratio fn/f1)",\
126 "<th rowspan=\"2\"> Interval [cents] <th colspan=\"2\">",\
127 "Maxima magnitudes <th rowspan=\"2\"> Ratio [db]"
128 print >>f, "<tr><th>Theoretical <th>Experimental <th> Theoretical",\
129 "<th>Experimental"
130
132 print >>f, "\\multicolumn{2}{|c|}{Maxima frequency [Hz] (fn/f1)} &",\
133 " Interval [cents] &",\
134 " \\multicolumn{3}{|c|}{Maxima magnitudes} & \\\\"
135 print >>f, "\\cline{1-2}\\cline{4-5}"
136 print >>f, "Theoretical & Experimental & & Theoretical &",\
137 " Experimental & Ratio [db] & \\\\"
138 print >>f, "\\hline \\hline"
139
141 for f1,f2,cents,A1,A2,dB,r1,r2 in self.data:
142 print >>f, "<tr>" + td + "%.2f (%.3f)"%(f1,r1) + td +\
143 "%.2f (%.3f)"%(f2,r2) + td + "%.2f"%cents + td +\
144 "%.2f"%A1 + td + "%.2f"%A2 + td + "%.2f"%dB
145
146
149 self.title = title
150 self.data = objects
151
154
156 for d in self.data:
157 print >>f, "<tr>"
158 for i in d:
159 print >>f, "<td align=\"right\" >", i
160
161
162
163
164
166 - def __init__(self, filename):
167 self.file = open(filename, 'w')
168
169 - def add_link(self, path, string):
170 self.write("<a href=\"%s\">%s</a>"%(path, string))
171
172 - def add_image(self, path, string):
173 self.write("<img href=\"%s\">%s</a>"%(path, string))
174
175 - def add_rule(self):
177
178 - def add_anchor(self, name):
179 self.write("<a name=\"%s\"></a>"%name)
180
181 - def write(self, string):
182 print >>self.file, string
183
186