KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > polepos > reporters > CSVReporter


1 /*
2 This file is part of the PolePosition database benchmark
3 http://www.polepos.org
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
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
27 public class CSVReporter extends GraphReporter {
28     
29     private final static String JavaDoc TAB = "\t";
30     private final static String JavaDoc FOLDER = "doc/results";
31
32     protected void report(Graph graph){
33         new File(FOLDER).mkdirs();
34         
35         String JavaDoc fileName = FOLDER + "/" + graph.circuit().name() + "_" + graph.lap().name() + ".f1graph";
36         new File(fileName).delete();
37         
38         PrintStream ps = null;
39         try {
40             ps = new PrintStream( new FileOutputStream( new File(fileName), false));
41         } catch (FileNotFoundException e) {
42             e.printStackTrace();
43         }
44         
45         ps.print(graph.circuit().name());
46         ps.print(" ");
47         ps.print(graph.lap().name());
48         renderTableHeader(graph, ps);
49         renderTableBody(graph, ps);
50         
51         ps.flush();
52         ps.close();
53     }
54
55     private void renderTableHeader(Graph graph, PrintStream ps) {
56         for(TurnSetup setup : graph.setups()) {
57             ps.print(TAB);
58             boolean first = true;
59             for(SetupProperty sp : setup.properties()){
60                 if(! first){
61                     ps.print(" ");
62                 }
63                 ps.print(sp.name());
64                 ps.print(":");
65                 ps.print(sp.value());
66                 first = false;
67             }
68         }
69         ps.println();
70     }
71
72     private void renderTableBody(Graph graph, PrintStream ps) {
73         for(TeamCar teamCar : graph.teamCars()) {
74             ps.print(teamCar);
75             for(TurnSetup setup : graph.setups()) {
76                 ps.print(TAB);
77                 ps.print(graph.timeFor(teamCar,setup));
78             }
79             ps.println();
80         }
81     }
82
83     protected void finish() {
84     }
85
86 }
87
Popular Tags