Package wiat :: Module Reports
[hide private]
[frames] | no frames]

Source Code for Module wiat.Reports

  1  # Copyright 2008 Antoine Lefebvre 
  2  # 
  3  # This file is part of "The Wind Instrument Acoustic Toolkit". 
  4  # 
  5  # "The Wind Instrument Acoustic Toolkit" is free software: 
  6  # you can redistribute it and/or modify it under the terms of 
  7  # the GNU General Public License as published by the 
  8  # Free Software Foundation, either version 3 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # "The Wind Instrument Acoustic Toolkit" is distributed in the hope 
 12  # that it will be useful, but WITHOUT ANY WARRANTY; without even 
 13  # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 14  # See the GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with "The Wind Instrument Acoustic Toolkit". 
 18  # If not, see <http://www.gnu.org/licenses/>. 
 19  # 
 20  # All rights reserved. 
 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   
34 -class LatexTable:
35 - def _write_table_beginning(self,f):
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
41 - def _write_table_ending(self,f):
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
67 -class HtmlTable:
68 - def _write_table_beginning(self, f):
69 print >>f, "<table frame=\"box\" rules=\"group\">" 70 print >>f, "<caption><em>%s</em></caption>"%self.title
71
72 - def _write_table_ending(self, f):
73 print >>f, "</table>"
74 75 76 # def tableData(self,f): 77 # for d in self.data: 78 # td = "<td align=\"right\" >" 79 # for (f1, f2, cents, A1, A2, dB, r1, r2) in self.data: 80 # print >>f, "<tr>" + td + "%.2f (%.3f)"%(f1,r1) + td + 81 # "%.2f (%.3f)"%(f2,r2) + td + "%.2f"%cents + td + "%.2f"%A1 + td + 82 # "%.2f"%A2 + td + "%.2f"%dB 83 84 # for i in d: 85 # if type(i) is numpy.float64 or float: 86 # print >>f, "<td align=\"right\" >", "%.2f"%i 87 # else: 88 # print >>f, "<td align=\"right\" >", i 89
90 - def html_export(self, f):
95 96 97
98 -class ImpedanceMaximaListing(HtmlTable):
99 - def __init__(self, title, data):
100 self.title = title 101 self.data = data #ProcessMaximas( object.getMaximaData() )
102
103 - def _write_htmltable_titles(self, f):
104 print >>f, "<tr><th>Maxima frequency [Hz] <th>Maxima magnitude",\ 105 "<th> Frequency ratio fn/f1"
106
107 - def _write_table_data(self, f):
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 # if type(i) is numpy.float64 or float: 114 # print >>f, "<td align=\"right\" >", "%.2f"%i 115 # else: 116 # print >>f, "<td align=\"right\" >", i 117 118
119 -class ImpedanceMaximaComparison(HtmlTable, LatexTable):
120 - def __init__(self, title, comparison):
121 self.title = title 122 self.data = comparison
123
124 - def _write_htmltable_titles(self, f):
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
131 - def _write_latextable_titles(self, f):
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
140 - def _write_table_data(self, f):
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
147 -class MeasurementDataDescription(HtmlTable):
148 - def __init__(self, title, objects):
149 self.title = title 150 self.data = objects
151
152 - def _write_htmltable_titles(self, f):
153 return
154
155 - def _write_table_data(self, f):
156 for d in self.data: 157 print >>f, "<tr>" 158 for i in d: 159 print >>f, "<td align=\"right\" >", i
160 # if type(i) is numpy.float64 or float: 161 # print >>f, "<td align=\"right\" >", "%.2f"%i 162 # else: 163 # print >>f, "<td align=\"right\" >", i 164
165 -class WebPage:
166 - def __init__(self, filename):
167 self.file = open(filename, 'w')
168 171
172 - def add_image(self, path, string):
173 self.write("<img href=\"%s\">%s</a>"%(path, string))
174
175 - def add_rule(self):
176 self.write("<hr />")
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
184 - def close(self):
185 self.file.close()
186