Revision: 188
http://polepos.svn.sourceforge.net/polepos/?rev=188&view=rev
Author: patrickroemer
Date: 2011-02-17 18:37:24 +0000 (Thu, 17 Feb 2011)
Log Message:
-----------
cr/pr: initial rendering for fixed time, bar direction still broken
Modified Paths:
--------------
trunk/polepos/src/org/polepos/framework/Circuit.java
trunk/polepos/src/org/polepos/framework/CircuitBase.java
trunk/polepos/src/org/polepos/framework/FixedTimeCircuitBase.java
trunk/polepos/src/org/polepos/framework/FixedTimeRacingStrategy.java
trunk/polepos/src/org/polepos/framework/FixedTimeResult.java
trunk/polepos/src/org/polepos/framework/Result.java
trunk/polepos/src/org/polepos/framework/TimedLapsCircuitBase.java
trunk/polepos/src/org/polepos/framework/TimedLapsResult.java
trunk/polepos/src/org/polepos/reporters/CustomBarPDFReporter.java
trunk/polepos/src/org/polepos/reporters/DefaultReporterFactory.java
trunk/polepos/src/org/polepos/reporters/Graph.java
trunk/polepos/src/org/polepos/reporters/PlainTextReporter.java
Added Paths:
-----------
trunk/polepos/src/org/polepos/reporters/CustomBarRendererBase.java
trunk/polepos/src/org/polepos/reporters/FixedTimeCustomBarRenderer.java
trunk/polepos/src/org/polepos/reporters/TimedLapsCustomBarRenderer.java
Removed Paths:
-------------
trunk/polepos/src/org/polepos/reporters/CustomBarRender.java
Modified: trunk/polepos/src/org/polepos/framework/Circuit.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/Circuit.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/framework/Circuit.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -45,5 +45,6 @@
public RacingStrategy racingStrategy();
+ boolean isFixedTime();
}
\ No newline at end of file
Modified: trunk/polepos/src/org/polepos/framework/CircuitBase.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/CircuitBase.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/framework/CircuitBase.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -82,6 +82,4 @@
public TurnSetup[] lapSetups(){
return _turnSetups;
}
-
-
}
Modified: trunk/polepos/src/org/polepos/framework/FixedTimeCircuitBase.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/FixedTimeCircuitBase.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/framework/FixedTimeCircuitBase.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -44,4 +44,9 @@
}
+ @Override
+ public boolean isFixedTime() {
+ return true;
+ }
+
}
Modified: trunk/polepos/src/org/polepos/framework/FixedTimeRacingStrategy.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/FixedTimeRacingStrategy.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/framework/FixedTimeRacingStrategy.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -108,11 +108,8 @@
}
- // FIXME: Change to FixedTimeResult
- // Result result = new FixedTimeResult(_circuit, _circuit.laps().get(0), team,turnSetups[i],i,iterations);
+ Result result = new FixedTimeResult(_circuit, _circuit.laps().get(0), team, setup, setupIndex, iterations);
- Result result = new TimedLapsResult(_circuit, team,_circuit.laps().get(0), setup ,setupIndex,iterations,0,0,0);
-
team.tearDown();
driver.circuitCompleted();
return result;
Modified: trunk/polepos/src/org/polepos/framework/FixedTimeResult.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/FixedTimeResult.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/framework/FixedTimeResult.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -29,7 +29,8 @@
_iterations = iterations;
}
- public long iterations(){
+ @Override
+ public long getIterations(){
return _iterations;
}
Modified: trunk/polepos/src/org/polepos/framework/Result.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/Result.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/framework/Result.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -71,6 +71,8 @@
public abstract long getTime();
+ public abstract long getIterations();
+
public abstract long getMemory();
public abstract long getDatabaseSize();
Modified: trunk/polepos/src/org/polepos/framework/TimedLapsCircuitBase.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/TimedLapsCircuitBase.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/framework/TimedLapsCircuitBase.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -27,7 +27,7 @@
/**
* a set of timed test cases that work against the same data
*/
-public abstract class TimedLapsCircuitBase extends CircuitBase implements Circuit {
+public abstract class TimedLapsCircuitBase extends CircuitBase {
public static final String NUM_RUNS_PROPERTY_ID = "POLEPOS_NUM_RUNS";
public static final String MEMORY_USAGE_PROPERTY_ID = "POLEPOS_MEMORY_USAGE";
@@ -267,6 +267,9 @@
return _laps;
}
-
+ @Override
+ public boolean isFixedTime() {
+ return false;
+ }
}
Modified: trunk/polepos/src/org/polepos/framework/TimedLapsResult.java
===================================================================
--- trunk/polepos/src/org/polepos/framework/TimedLapsResult.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/framework/TimedLapsResult.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -56,6 +56,11 @@
public long getDatabaseSize() {
return _databaseSize;
}
+
+ @Override
+ public long getIterations() {
+ return 0;
+ }
}
Modified: trunk/polepos/src/org/polepos/reporters/CustomBarPDFReporter.java
===================================================================
--- trunk/polepos/src/org/polepos/reporters/CustomBarPDFReporter.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/reporters/CustomBarPDFReporter.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -74,15 +74,13 @@
PdfTemplate tp = cb.createTemplate(chartWidth(), chartHeight());
Graphics2D graphics = tp.createGraphics(chartWidth(), chartHeight(), new DefaultFontMapper());
- int height = new CustomBarRender(graph).render(graphics);
+ int height = new TimedLapsCustomBarRenderer(graph).render(graphics);
tp = cb.createTemplate(chartWidth(), height);
graphics = tp.createGraphics(chartWidth(), height, new DefaultFontMapper());
- new CustomBarRender(graph).render(graphics);
+ (graph.circuit().isFixedTime() ? new FixedTimeCustomBarRenderer(graph) : new TimedLapsCustomBarRenderer(graph)).render(graphics);
-
-
graphics.dispose();
return new ImgTemplate(tp);
}
Deleted: trunk/polepos/src/org/polepos/reporters/CustomBarRender.java
===================================================================
--- trunk/polepos/src/org/polepos/reporters/CustomBarRender.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/reporters/CustomBarRender.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -1,327 +0,0 @@
-/*
-This file is part of the PolePosition database benchmark
-http://www.polepos.org
-
-This program is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public
-License along with this program; if not, write to the Free
-Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-MA 02111-1307, USA. */
-package org.polepos.reporters;
-
-import java.awt.*;
-import java.awt.geom.*;
-import java.util.*;
-import java.util.List;
-
-import javax.swing.*;
-
-import org.polepos.framework.*;
-
-import com.db4o.*;
-
-public class CustomBarRender {
- private Graphics graphics;
- private GraphData graphData;
- private List<TurnData> runs;
- private final Graph graph;
-
-
- static class TurnData {
- public TurnData(TurnSetup turn, long best) {
- this.turn = turn;
- this.best = best;
- }
- TurnSetup turn;
- long best;
- public List<TeamData> teams = new ArrayList<TeamData>();
- }
-
- static class TeamData {
- public TeamData(TeamCar team, double orderOfMagnitude, long time) {
- this.teamCar = team;
- this.orderOfMagnitude = orderOfMagnitude;
- this.time = time;
- }
- TeamCar teamCar;
- double orderOfMagnitude;
- long time;
-
- public Color barColor() {
- int rgb = teamCar.color();
- return new Color(rgb);
- }
-
-
- }
-
- static class GraphData {
-
- double maxTeamNameWidth = 0;
- double barHeight = 15;
- Font teamNameFont;
- Font turnLegendFont;
-
- double paddingX = 3;
-
- double maxMagnitude = 5;
-
- double paddingY = 2;
-
- double markerHeight = 5;
-
- }
-
- double stride() {
- return graphData().barHeight + graphData().paddingY;
- }
-
- double barX() {
- return graphData().maxTeamNameWidth+1;
- }
-
- double maxBarWidth() {
- return graphics.getClipBounds().getWidth() - barX() - textWidth("10000x")/2;
- }
-
- double widthPerOrderOfMagnitude() {
- return maxBarWidth() / graphData().maxMagnitude;
- }
-
-
- public static void main(String[] args) {
-
-
- EmbeddedObjectContainer db = Db4oEmbedded.openFile("graph.db4o");
-
- Graph graph = db.query(Graph.class).iterator().next();
- db.activate(graph, Integer.MAX_VALUE);
- db.close();
-
-
- final CustomBarRender renderer = new CustomBarRender(graph);
- JFrame w = new JFrame("Polepos preview") {
- private static final long serialVersionUID = 1L;
- @Override
- public void paint(Graphics g) {
- super.paint(g);
- renderer.render(g);
- }
- };
- w.setSize(522, 600);
- w.setVisible(true);
-
- w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
-
- public CustomBarRender(Graph graph) {
- this.graph = graph;
- }
-
- public int render(Graphics graphics) {
- this.graphics = graphics;
-
- graphics.setFont(graphData().teamNameFont);
-
- double y = 0;
-
- for (TurnData turnData : runs()) {
- if (y > 0) {
- y += stride();
- }
- y = renderTurn(graphics, turnData, y);
-
- }
-
- y = renderAxis(graphics, (int) y);
-
- return (int) y;
-
- }
-
- private int renderAxis(Graphics graphics, int y) {
- int axisX = (int) graphData().maxTeamNameWidth;
- graphics.setColor(Color.BLACK);
- graphics.drawLine(axisX, 0, axisX, y);
- graphics.drawLine(axisX, y, (int) graphics.getClipBounds().getWidth(), y);
-
- for(int i=0;i<=graphData().maxMagnitude;i++) {
-
- int x = (int) (i * widthPerOrderOfMagnitude()) + axisX;
-
- graphics.drawLine(x, y, x, (int) (y+graphData().markerHeight));
-
- String legend;
-
- if (i == 0) {
- graphics.setFont(graphData().turnLegendFont);
- legend = "magnitude";
- } else {
- graphics.setFont(graphData().teamNameFont);
- legend = String.format("%.0fx", Math.pow(10, i-1));
- }
-
- graphics.drawString(legend, (int)(x-textWidth(legend)/2.), (int)(y+graphData().markerHeight+textHeight(legend)));
- }
-
- y += stride()*2;
-
- return y;
-
- }
-
- private double renderTurn(Graphics graphics, TurnData turnData, double y) {
-
- String legend = CustomBarPDFReporter.legend(turnData.turn);
-
- graphics.setFont(graphData().turnLegendFont);
- graphics.setColor(Color.BLACK);
- graphics.drawString(legend, (int) (barX()+graphData().paddingX), (int) (y + graphData().barHeight-graphData().paddingY));
-
-
- y += stride();
-
- for (TeamData teamData : turnData.teams) {
-
- graphics.setFont(graphData().teamNameFont);
- graphics.setColor(Color.BLACK);
-
-
- int textY = (int) (graphData.paddingY+(float) (y + graphData().barHeight - textHeight(teamData.teamCar.name())/2));
- graphics.drawString(teamData.teamCar.name(), (int) (graphData().maxTeamNameWidth-textWidth(teamData.teamCar.name())-graphData().paddingX), textY);
-
- graphics.setColor(teamData.barColor());
-
-
- int barWidth = (int) (barUnits(teamData.orderOfMagnitude) * widthPerOrderOfMagnitude());
-
- graphics.fillRect((int)barX(), (int) y, barWidth, (int) graphData().barHeight);
-
- String magnitude = String.format("%.1fx", teamData.orderOfMagnitude);
-
- graphics.setColor(Color.BLACK);
- graphics.drawString(magnitude, (int)(barX()+barWidth+graphData().paddingX), textY);
-
- if (teamData.time > 0) {
- String absolute = teamData.time+"ms";
- graphics.setColor(Color.WHITE);
- graphics.drawString(absolute, (int)(barX()+barWidth-textWidth(absolute)-graphData().paddingX), textY);
- }
-
- y += stride();
- }
- return y;
-
- }
-
- private double textWidth(String string) {
- return textBounds(graphics, string, graphics.getFont()).getWidth();
- }
-
- private double textHeight(String string) {
- return textBounds(graphics, string, graphics.getFont()).getHeight();
- }
-
- double barUnits(double orderOfMagnitude) {
- if (orderOfMagnitude == 0) {
- return 0;
- }
- return Math.log10(orderOfMagnitude) + 1;
- }
-
- private Rectangle2D textBounds(Graphics g, String string, Font font) {
-
- FontMetrics metrics = g.getFontMetrics(font);
- int hgt = metrics.getHeight();
- int adv = metrics.stringWidth(string);
- Dimension size = new Dimension(adv+2, hgt+2);
-
- return new Rectangle(size);
- }
-
- private GraphData prepareGraphData(Graphics graphics, final Graph graph) {
-
- GraphData graphData = new GraphData();
-
- graphData.teamNameFont = new Font("Helvetica", Font.PLAIN, 9);
- graphData.turnLegendFont = new Font("Helvetica", Font.BOLD, 9);
-
- for (TeamCar teamCar : graph.teamCars()) {
- Rectangle2D textBounds = textBounds(graphics, teamCar.name(), graphData.teamNameFont);
- graphData.maxTeamNameWidth = Math.max(graphData.maxTeamNameWidth, textBounds.getWidth()+graphData.paddingX*2);
- graphData.barHeight = Math.max(graphData.barHeight, textBounds.getHeight());
- }
-
- return graphData;
- }
-
- private List<TurnData> prepareTurnsData(final Graph graph) {
- List<TurnData> runs = new ArrayList<TurnData>();
-
- final List<TurnSetup> setups = graph.setups();
- List<TeamCar> teamCars = graph.teamCars();
-
- for (final TurnSetup setup : setups) {
-
- TurnData turnData = new TurnData(setup, 0);
- long best = Long.MAX_VALUE;
- for (TeamCar teamCar : teamCars) {
- long time = graph.timeFor(teamCar, setup);
- TeamData teamData = new TeamData(teamCar, 0, time);
- if (time != 0 && time < best) {
- best = time;
- }
- turnData.teams.add(teamData);
- }
- turnData.best = best == 0 ? 1 : best;
-
- for (TeamData teamData : turnData.teams) {
- teamData.orderOfMagnitude = teamData.time / (double)turnData.best;
- }
-
- Collections.sort(turnData.teams, new Comparator<TeamData>() {
-
- @Override
- public int compare(TeamData team1, TeamData team2) {
- long time1 = graph.timeFor(team1.teamCar, setup);
- long time2 = graph.timeFor(team2.teamCar, setup);
-
- if (time1 > time2) {
- return 1;
- }
- if (time1 < time2) {
- return -1;
- }
- return 0;
- }
- });
-
- runs.add(turnData);
- }
- return runs;
- }
-
- public GraphData graphData() {
- if (graphData == null) {
- this.graphData = prepareGraphData(graphics, graph);
- }
- return graphData;
- }
-
- public List<TurnData> runs() {
- if (runs == null) {
- this.runs = prepareTurnsData(graph);
- }
- return runs;
- }
-
-}
Copied: trunk/polepos/src/org/polepos/reporters/CustomBarRendererBase.java (from rev 187, trunk/polepos/src/org/polepos/reporters/CustomBarRender.java)
===================================================================
--- trunk/polepos/src/org/polepos/reporters/CustomBarRendererBase.java (rev 0)
+++ trunk/polepos/src/org/polepos/reporters/CustomBarRendererBase.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -0,0 +1,285 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with this program; if not, write to the Free
+Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+package org.polepos.reporters;
+
+import java.awt.*;
+import java.awt.geom.*;
+import java.util.*;
+import java.util.List;
+
+import javax.swing.*;
+
+import org.polepos.framework.*;
+
+import com.db4o.*;
+
+public abstract class CustomBarRendererBase {
+
+ private Graphics graphics;
+ private GraphData graphData;
+ private List<TurnData> runs;
+ protected final Graph graph;
+
+ public CustomBarRendererBase(Graph graph) {
+ this.graph = graph;
+ }
+
+ protected static class TurnData {
+ public TurnData(TurnSetup turn, long best) {
+ this.turn = turn;
+ this.best = best;
+ }
+ TurnSetup turn;
+ long best;
+ public List<TeamData> teams = new ArrayList<TeamData>();
+ }
+
+ protected static class TeamData {
+ public TeamData(TeamCar team, double orderOfMagnitude, long val) {
+ this.teamCar = team;
+ this.orderOfMagnitude = orderOfMagnitude;
+ this.val = val;
+ }
+ TeamCar teamCar;
+ double orderOfMagnitude;
+ long val;
+
+ public Color barColor() {
+ int rgb = teamCar.color();
+ return new Color(rgb);
+ }
+
+
+ }
+
+ protected static class GraphData {
+
+ double maxTeamNameWidth = 0;
+ double barHeight = 15;
+ Font teamNameFont;
+ Font turnLegendFont;
+
+ double paddingX = 3;
+
+ double maxMagnitude = 5;
+
+ double paddingY = 2;
+
+ double markerHeight = 5;
+
+ }
+
+ public static void main(String[] args) {
+
+
+ EmbeddedObjectContainer db = Db4oEmbedded.openFile("graph.db4o");
+
+ Graph graph = db.query(Graph.class).iterator().next();
+ db.activate(graph, Integer.MAX_VALUE);
+ db.close();
+
+
+ final CustomBarRendererBase renderer = (graph.circuit().isFixedTime() ? new FixedTimeCustomBarRenderer(graph) : new TimedLapsCustomBarRenderer(graph));
+ JFrame w = new JFrame("Polepos preview") {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public void paint(Graphics g) {
+ super.paint(g);
+ renderer.render(g);
+ }
+ };
+ w.setSize(522, 600);
+ w.setVisible(true);
+
+ w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ }
+
+ double stride() {
+ return graphData().barHeight + graphData().paddingY;
+ }
+
+ double barX() {
+ return graphData().maxTeamNameWidth+1;
+ }
+
+ double maxBarWidth() {
+ return graphics.getClipBounds().getWidth() - barX() - textWidth("10000x")/2;
+ }
+
+ protected double widthPerOrderOfMagnitude() {
+ return maxBarWidth() / graphData().maxMagnitude;
+ }
+
+ public int render(Graphics graphics) {
+ this.graphics = graphics;
+
+ graphics.setFont(graphData().teamNameFont);
+
+ double y = 0;
+
+ for (TurnData turnData : runs()) {
+ if (y > 0) {
+ y += stride();
+ }
+ y = renderTurn(graphics, turnData, y);
+
+ }
+
+ y = renderAxis(graphics, (int) y);
+
+ return (int) y;
+
+ }
+
+ private int renderAxis(Graphics graphics, int y) {
+ int axisX = (int) graphData().maxTeamNameWidth;
+ graphics.setColor(Color.BLACK);
+ graphics.drawLine(axisX, 0, axisX, y);
+ graphics.drawLine(axisX, y, (int) graphics.getClipBounds().getWidth(), y);
+
+ for(int i=0;i<=graphData().maxMagnitude;i++) {
+
+ int x = (int) (i * widthPerOrderOfMagnitude()) + axisX;
+
+ graphics.drawLine(x, y, x, (int) (y+graphData().markerHeight));
+
+ String legend;
+
+ if (i == 0) {
+ graphics.setFont(graphData().turnLegendFont);
+ legend = "magnitude";
+ } else {
+ graphics.setFont(graphData().teamNameFont);
+ legend = String.format("%.0fx", Math.pow(10, i-1));
+ }
+
+ graphics.drawString(legend, (int)(x-textWidth(legend)/2.), (int)(y+graphData().markerHeight+textHeight(legend)));
+ }
+
+ y += stride()*2;
+
+ return y;
+
+ }
+
+ private double renderTurn(Graphics graphics, TurnData turnData, double y) {
+
+ String legend = CustomBarPDFReporter.legend(turnData.turn);
+
+ graphics.setFont(graphData().turnLegendFont);
+ graphics.setColor(Color.BLACK);
+ graphics.drawString(legend, (int) (barX()+graphData().paddingX), (int) (y + graphData().barHeight-graphData().paddingY));
+
+
+ y += stride();
+
+ for (TeamData teamData : turnData.teams) {
+
+ graphics.setFont(graphData().teamNameFont);
+ graphics.setColor(Color.BLACK);
+
+
+ int textY = (int) (graphData.paddingY+(float) (y + graphData().barHeight - textHeight(teamData.teamCar.name())/2));
+ graphics.drawString(teamData.teamCar.name(), (int) (graphData().maxTeamNameWidth-textWidth(teamData.teamCar.name())-graphData().paddingX), textY);
+
+ graphics.setColor(teamData.barColor());
+
+
+ int barWidth = barWidth(teamData);
+
+ graphics.fillRect((int)barX(), (int) y, barWidth, (int) graphData().barHeight);
+
+ String magnitude = String.format("%.1fx", teamData.orderOfMagnitude);
+
+ graphics.setColor(Color.BLACK);
+ graphics.drawString(magnitude, (int)(barX()+barWidth+graphData().paddingX), textY);
+
+ if (teamData.val > 0) {
+ String absolute = teamData.val+"ms";
+ graphics.setColor(Color.WHITE);
+ graphics.drawString(absolute, (int)(barX()+barWidth-textWidth(absolute)-graphData().paddingX), textY);
+ }
+
+ y += stride();
+ }
+ return y;
+
+ }
+
+ protected abstract int barWidth(TeamData teamData);
+
+ private double textWidth(String string) {
+ return textBounds(graphics, string, graphics.getFont()).getWidth();
+ }
+
+ private double textHeight(String string) {
+ return textBounds(graphics, string, graphics.getFont()).getHeight();
+ }
+
+ protected double barUnits(double orderOfMagnitude) {
+ if (orderOfMagnitude == 0) {
+ return 0;
+ }
+ return Math.log10(orderOfMagnitude) + 1;
+ }
+
+ private Rectangle2D textBounds(Graphics g, String string, Font font) {
+
+ FontMetrics metrics = g.getFontMetrics(font);
+ int hgt = metrics.getHeight();
+ int adv = metrics.stringWidth(string);
+ Dimension size = new Dimension(adv+2, hgt+2);
+
+ return new Rectangle(size);
+ }
+
+ private GraphData prepareGraphData(Graphics graphics, final Graph graph) {
+
+ GraphData graphData = new GraphData();
+
+ graphData.teamNameFont = new Font("Helvetica", Font.PLAIN, 9);
+ graphData.turnLegendFont = new Font("Helvetica", Font.BOLD, 9);
+
+ for (TeamCar teamCar : graph.teamCars()) {
+ Rectangle2D textBounds = textBounds(graphics, teamCar.name(), graphData.teamNameFont);
+ graphData.maxTeamNameWidth = Math.max(graphData.maxTeamNameWidth, textBounds.getWidth()+graphData.paddingX*2);
+ graphData.barHeight = Math.max(graphData.barHeight, textBounds.getHeight());
+ }
+
+ return graphData;
+ }
+
+ public GraphData graphData() {
+ if (graphData == null) {
+ this.graphData = prepareGraphData(graphics, graph);
+ }
+ return graphData;
+ }
+
+ public List<TurnData> runs() {
+ if (runs == null) {
+ this.runs = prepareTurnsData(graph);
+ }
+ return runs;
+ }
+
+ protected abstract List<TurnData> prepareTurnsData(final Graph graph);
+
+}
\ No newline at end of file
Modified: trunk/polepos/src/org/polepos/reporters/DefaultReporterFactory.java
===================================================================
--- trunk/polepos/src/org/polepos/reporters/DefaultReporterFactory.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/reporters/DefaultReporterFactory.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -32,6 +32,7 @@
new CSVReporter(defaultReporterOutputPath()),
new HTMLReporter(subfolderPath(defaultReporterOutputPath(), "html")),
new XLSReporter(defaultReporterOutputPath()),
+ new PersistGraphReporter(defaultReporterOutputPath()),
};
}
Added: trunk/polepos/src/org/polepos/reporters/FixedTimeCustomBarRenderer.java
===================================================================
--- trunk/polepos/src/org/polepos/reporters/FixedTimeCustomBarRenderer.java (rev 0)
+++ trunk/polepos/src/org/polepos/reporters/FixedTimeCustomBarRenderer.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -0,0 +1,86 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with this program; if not, write to the Free
+Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+
+package org.polepos.reporters;
+
+import java.util.*;
+
+import org.polepos.framework.*;
+
+public class FixedTimeCustomBarRenderer extends CustomBarRendererBase {
+
+ public FixedTimeCustomBarRenderer(Graph graph) {
+ super(graph);
+ }
+
+ @Override
+ protected List<TurnData> prepareTurnsData(final Graph graph) {
+ List<TurnData> runs = new ArrayList<TurnData>();
+
+ final List<TurnSetup> setups = graph.setups();
+ List<TeamCar> teamCars = graph.teamCars();
+
+ for (final TurnSetup setup : setups) {
+
+ TurnData turnData = new TurnData(setup, 0);
+ long best = 0;
+ for (TeamCar teamCar : teamCars) {
+ long iterations = graph.iterationsFor(teamCar, setup);
+ System.err.println("ITER: " + iterations);
+ TeamData teamData = new TeamData(teamCar, 0, iterations);
+ if (iterations != 0 && iterations > best) {
+ best = iterations;
+ }
+ turnData.teams.add(teamData);
+ }
+ turnData.best = best == 0 ? 1 : best;
+
+ for (TeamData teamData : turnData.teams) {
+ teamData.orderOfMagnitude = teamData.val / (double)turnData.best;
+ }
+
+ Collections.sort(turnData.teams, new Comparator<TeamData>() {
+
+ @Override
+ public int compare(TeamData team1, TeamData team2) {
+ long iterations1 = graph.iterationsFor(team1.teamCar, setup);
+ long iterations2 = graph.iterationsFor(team2.teamCar, setup);
+
+ if (iterations1 < iterations2) {
+ return 1;
+ }
+ if (iterations1 > iterations2) {
+ return -1;
+ }
+ return 0;
+ }
+ });
+
+ runs.add(turnData);
+ }
+ return runs;
+ }
+
+ @Override
+ protected int barWidth(TeamData teamData) {
+ return (int)((4 - barUnits(teamData.orderOfMagnitude)) * widthPerOrderOfMagnitude());
+ }
+
+}
Modified: trunk/polepos/src/org/polepos/reporters/Graph.java
===================================================================
--- trunk/polepos/src/org/polepos/reporters/Graph.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/reporters/Graph.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -107,6 +107,18 @@
}
return res.getTime();
}
+
+ public final long iterationsFor(TeamCar teamCar, TurnSetup setup) {
+ return iterationsFor(new TurnCombination(teamCar,setup));
+ }
+
+ public long iterationsFor(TurnCombination turnCombination) {
+ Result res = results.get(turnCombination);
+ if(res == null){
+ return 0;
+ }
+ return res.getIterations();
+ }
public final long memoryFor(TeamCar teamCar, TurnSetup setup) {
Result res = results.get(new TurnCombination(teamCar,setup));
Modified: trunk/polepos/src/org/polepos/reporters/PlainTextReporter.java
===================================================================
--- trunk/polepos/src/org/polepos/reporters/PlainTextReporter.java 2011-02-17 18:36:49 UTC (rev 187)
+++ trunk/polepos/src/org/polepos/reporters/PlainTextReporter.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -120,7 +120,7 @@
if(result instanceof TimedLapsResult){
mOut.println("[" + result.getIndex() + "] " + ((TimedLapsResult)result).getTime() + "ms ");
} else if (result instanceof FixedTimeResult){
- mOut.println("[" + result.getIndex() + "] " + ((FixedTimeResult)result).iterations() + "iterations ");
+ mOut.println("[" + result.getIndex() + "] " + ((FixedTimeResult)result).getIterations() + "iterations ");
}
}
Added: trunk/polepos/src/org/polepos/reporters/TimedLapsCustomBarRenderer.java
===================================================================
--- trunk/polepos/src/org/polepos/reporters/TimedLapsCustomBarRenderer.java (rev 0)
+++ trunk/polepos/src/org/polepos/reporters/TimedLapsCustomBarRenderer.java 2011-02-17 18:37:24 UTC (rev 188)
@@ -0,0 +1,81 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with this program; if not, write to the Free
+Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+package org.polepos.reporters;
+
+import java.util.*;
+
+import org.polepos.framework.*;
+
+public class TimedLapsCustomBarRenderer extends CustomBarRendererBase {
+ public TimedLapsCustomBarRenderer(Graph graph) {
+ super(graph);
+ }
+
+ protected List<TurnData> prepareTurnsData(final Graph graph) {
+ List<TurnData> runs = new ArrayList<TurnData>();
+
+ final List<TurnSetup> setups = graph.setups();
+ List<TeamCar> teamCars = graph.teamCars();
+
+ for (final TurnSetup setup : setups) {
+
+ TurnData turnData = new TurnData(setup, 0);
+ long best = Long.MAX_VALUE;
+ for (TeamCar teamCar : teamCars) {
+ long time = graph.timeFor(teamCar, setup);
+ TeamData teamData = new TeamData(teamCar, 0, time);
+ if (time != 0 && time < best) {
+ best = time;
+ }
+ turnData.teams.add(teamData);
+ }
+ turnData.best = best == 0 ? 1 : best;
+
+ for (TeamData teamData : turnData.teams) {
+ teamData.orderOfMagnitude = teamData.val / (double)turnData.best;
+ }
+
+ Collections.sort(turnData.teams, new Comparator<TeamData>() {
+
+ @Override
+ public int compare(TeamData team1, TeamData team2) {
+ long time1 = graph.timeFor(team1.teamCar, setup);
+ long time2 = graph.timeFor(team2.teamCar, setup);
+
+ if (time1 > time2) {
+ return 1;
+ }
+ if (time1 < time2) {
+ return -1;
+ }
+ return 0;
+ }
+ });
+
+ runs.add(turnData);
+ }
+ return runs;
+ }
+
+ @Override
+ protected int barWidth(TeamData teamData) {
+ return (int) (barUnits(teamData.orderOfMagnitude) * widthPerOrderOfMagnitude());
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|