001: /*
002: This file is part of the PolePosition database benchmark
003: http://www.polepos.org
004:
005: This program is free software; you can redistribute it and/or
006: modify it under the terms of the GNU General Public License
007: as published by the Free Software Foundation; either version 2
008: of the License, or (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public
016: License along with this program; if not, write to the Free
017: Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
018: MA 02111-1307, USA. */
019:
020: package org.polepos.reporters;
021:
022: import java.io.*;
023: import java.util.*;
024:
025: import org.polepos.framework.*;
026:
027: public class PlainTextReporter extends Reporter {
028:
029: protected PrintStream mOut;
030: private boolean mSetupReported;
031:
032: @Override
033: public void startSeason() {
034:
035: if (!append()) {
036: new File(file()).delete();
037: }
038: try {
039: mOut = new PrintStream(new FileOutputStream(file(),
040: append()));
041: } catch (IOException ioex) {
042: ioex.printStackTrace();
043: }
044:
045: mOut.println();
046: mOut
047: .println("===========================================================================================");
048: mOut.println("Season started at " + new Date().toString());
049: mOut
050: .println("===========================================================================================");
051: }
052:
053: @Override
054: public boolean append() {
055: return true;
056: }
057:
058: @Override
059: public String file() {
060: return "doc/results/F1Season.log";
061: }
062:
063: @Override
064: public void noDriver(Team team, Circuit circuit) {
065: mOut.println("*** No driver for team " + team.name() + " in "
066: + circuit.name());
067: }
068:
069: @Override
070: public void sendToCircuit(Circuit circuit) {
071: super .sendToCircuit(circuit);
072: mOut.println();
073: mOut
074: .println("-------------------------------------------------------------------------------------------");
075: mOut.println(circuit.name());
076: mOut.println(circuit.description());
077: mOut
078: .println("-------------------------------------------------------------------------------------------");
079: mOut.println();
080: }
081:
082: @Override
083: public void reportTaskName(int number, String name) {
084: mOut.println("[" + number + "] " + name);
085: }
086:
087: @Override
088: public void reportTeam(Team team) {
089: mOut.println();
090: mOut.println("- " + team.name());
091: }
092:
093: @Override
094: public void reportCar(Car car) {
095: mOut.println("--- " + car.name());
096: mOut.println();
097: }
098:
099: @Override
100: public void beginResults() {
101: mOut.println();
102: mSetupReported = false;
103: }
104:
105: @Override
106: public void reportResult(Result result) {
107: if (!mSetupReported) {
108: mSetupReported = true;
109: TurnSetup setup = result.getSetup();
110: for (SetupProperty sp : setup.properties()) {
111: mOut.print(sp.name());
112: mOut.print(":");
113: mOut.print(sp.value());
114: mOut.print(" ");
115: }
116: mOut.println();
117: }
118: mOut.println("[" + result.getIndex() + "] " + result.getTime()
119: + "ms");
120: }
121:
122: public void endSeason() {
123: mOut.flush();
124: mOut.close();
125: }
126: }
|