01: /*
02: This file is part of the PolePosition database benchmark
03: http://www.polepos.org
04:
05: This program is free software; you can redistribute it and/or
06: modify it under the terms of the GNU General Public License
07: as published by the Free Software Foundation; either version 2
08: of the License, or (at your option) any later version.
09:
10: This program is distributed in the hope that it will be useful,
11: but WITHOUT ANY WARRANTY; without even the implied warranty of
12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: GNU General Public License for more details.
14:
15: You should have received a copy of the GNU General Public
16: License along with this program; if not, write to the Free
17: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18: MA 02111-1307, USA. */
19:
20: package org.polepos.reporters;
21:
22: import java.io.*;
23:
24: import org.polepos.framework.*;
25:
26: public class CSVReporter extends GraphReporter {
27:
28: private final static String TAB = "\t";
29: private final static String FOLDER = "doc/results";
30:
31: protected void report(Graph graph) {
32: new File(FOLDER).mkdirs();
33:
34: String fileName = FOLDER + "/" + graph.circuit().name() + "_"
35: + graph.lap().name() + ".f1graph";
36: new File(fileName).delete();
37:
38: PrintStream ps = null;
39: try {
40: ps = new PrintStream(new FileOutputStream(
41: new File(fileName), false));
42: } catch (FileNotFoundException e) {
43: e.printStackTrace();
44: }
45:
46: ps.print(graph.circuit().name());
47: ps.print(" ");
48: ps.print(graph.lap().name());
49: renderTableHeader(graph, ps);
50: renderTableBody(graph, ps);
51:
52: ps.flush();
53: ps.close();
54: }
55:
56: private void renderTableHeader(Graph graph, PrintStream ps) {
57: for (TurnSetup setup : graph.setups()) {
58: ps.print(TAB);
59: boolean first = true;
60: for (SetupProperty sp : setup.properties()) {
61: if (!first) {
62: ps.print(" ");
63: }
64: ps.print(sp.name());
65: ps.print(":");
66: ps.print(sp.value());
67: first = false;
68: }
69: }
70: ps.println();
71: }
72:
73: private void renderTableBody(Graph graph, PrintStream ps) {
74: for (TeamCar teamCar : graph.teamCars()) {
75: ps.print(teamCar);
76: for (TurnSetup setup : graph.setups()) {
77: ps.print(TAB);
78: ps.print(graph.timeFor(teamCar, setup));
79: }
80: ps.println();
81: }
82: }
83:
84: protected void finish() {
85: }
86:
87: }
|