[jboss-svn-commits] JBL Code SVN: r31856 - labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/benchmark/statistic.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Feb 27 04:10:45 EST 2010


Author: ge0ffrey
Date: 2010-02-27 04:10:45 -0500 (Sat, 27 Feb 2010)
New Revision: 31856

Modified:
   labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/benchmark/statistic/BestScoreStatistic.java
Log:
tune jfreechart's output to get something nice

Modified: labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/benchmark/statistic/BestScoreStatistic.java
===================================================================
--- labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/benchmark/statistic/BestScoreStatistic.java	2010-02-27 05:05:25 UTC (rev 31855)
+++ labs/jbossrules/trunk/drools-planner/drools-planner-core/src/main/java/org/drools/planner/benchmark/statistic/BestScoreStatistic.java	2010-02-27 09:10:45 UTC (rev 31856)
@@ -22,9 +22,14 @@
 import org.apache.commons.io.IOUtils;
 import org.jfree.chart.ChartFactory;
 import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.NumberAxis;
 import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.chart.renderer.xy.XYItemRenderer;
+import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
 import org.jfree.data.xy.XYSeries;
 import org.jfree.data.xy.XYSeriesCollection;
+import org.jfree.ui.RectangleInsets;
 
 /**
  * @author Geoffrey De Smet
@@ -120,7 +125,7 @@
                     writer.append(",");
                     Score score = timeToBestScoresLine.getConfigNameToScoreMap().get(configName);
                     if (score != null) {
-                        Number scoreAlias = extractScoreAlias(score);
+                        Integer scoreAlias = extractScoreAlias(score);
                         if (scoreAlias != null) {
                             writer.append(scoreAlias.toString());
                         }
@@ -136,8 +141,6 @@
     }
 
     private void writeGraphStatistic(File solverStatisticFilesDirectory, String baseName) {
-        File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "Statistic.png");
-
         XYSeriesCollection seriesCollection = new XYSeriesCollection();
         for (Map.Entry<String, BestScoreStatisticListener> listenerEntry : bestScoreStatisticListenerMap.entrySet()) {
             String configName = listenerEntry.getKey();
@@ -147,16 +150,24 @@
             for (BestScoreStatisticPoint statisticPoint : statisticPointList) {
                 long timeMillisSpend = statisticPoint.getTimeMillisSpend();
                 Score score = statisticPoint.getScore();
-                Number scoreAlias = extractScoreAlias(score);
-                configSeries.add(timeMillisSpend, scoreAlias);
+                Integer scoreAlias = extractScoreAlias(score);
+                if (scoreAlias != null) {
+                    configSeries.add(timeMillisSpend, scoreAlias);
+                }
             }
             seriesCollection.addSeries(configSeries);
         }
-        JFreeChart chart = ChartFactory.createXYLineChart(
-                baseName + " best score statistic", "Time millis spend", "Score",
-                seriesCollection, PlotOrientation.VERTICAL,
-                true, true, false);
+        NumberAxis xAxis = new NumberAxis("Time millis spend");
+        xAxis.setAutoRangeIncludesZero(false);
+        NumberAxis yAxis = new NumberAxis("Score");
+        yAxis.setAutoRangeIncludesZero(false);
+        XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
+        XYPlot plot = new XYPlot(seriesCollection, xAxis, yAxis, renderer);
+        plot.setOrientation(PlotOrientation.VERTICAL);
+        JFreeChart chart = new JFreeChart(baseName + " best score statistic",
+                JFreeChart.DEFAULT_TITLE_FONT, plot, true);
         BufferedImage chartImage = chart.createBufferedImage(800, 600);
+        File graphStatisticFile = new File(solverStatisticFilesDirectory, baseName + "Statistic.png");
         OutputStream out = null;
         try {
             out = new FileOutputStream(graphStatisticFile);
@@ -168,8 +179,9 @@
         }
     }
 
-    private Number extractScoreAlias(Score score) {
-        Number scoreAlias;
+    private Integer extractScoreAlias(Score score) {
+        // TODO Plugging in other Score implementations instead of SimpleScore and HardAndSoftScore should be possible
+        Integer scoreAlias;
         if (score instanceof SimpleScore) {
             SimpleScore simpleScore = (SimpleScore) score;
             scoreAlias = simpleScore.getScore();



More information about the jboss-svn-commits mailing list