1 6 7 package com.sun.japex.report; 8 9 import org.jfree.chart.ChartFactory; 10 import org.jfree.chart.ChartPanel; 11 import org.jfree.chart.ChartUtilities; 12 import org.jfree.chart.JFreeChart; 13 import org.jfree.chart.axis.DateAxis; 14 import org.jfree.chart.plot.XYPlot; 15 import org.jfree.chart.renderer.xy.XYItemRenderer; 16 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 17 import org.jfree.data.time.Month; 18 import org.jfree.data.time.Week; 19 import org.jfree.data.time.Day; 20 import org.jfree.data.time.TimeSeries; 21 import org.jfree.data.time.TimeSeriesCollection; 22 import org.jfree.data.xy.XYDataset; 23 import org.jfree.ui.ApplicationFrame; 24 import org.jfree.ui.RectangleInsets; 25 import org.jfree.ui.RefineryUtilities; 26 import org.jfree.ui.Spacer; 27 import org.jfree.util.UnitType; 28 29 import java.io.File ; 30 import java.util.Date ; 31 import java.util.Calendar ; 32 import java.util.GregorianCalendar ; 33 import java.util.Map ; 34 import java.util.ArrayList ; 35 36 public class TrendDataset { 37 static final String FIDRIVER = "TestFIDriver"; 38 static final String XMLDRIVER ="TestXMLDriver"; 39 TimeSeriesCollection _dataset; 40 41 42 public TrendDataset(TrendReportParams params, ParseReports testReports) { 43 Map [] reports = testReports.getReports(); 44 if (reports != null) { 45 Date [] dates = testReports.getDates(); 46 getDataset(params, reports, dates); 47 } 48 } 49 void getMeansDataset(ArrayList drivers, Map [] reports, Date [] dates) { 50 TimeSeries aritMeans, geomMeans, harmMeans; 51 ResultPerDriver result = null; 52 GregorianCalendar cal = new GregorianCalendar (); 53 for (int ii = 0; ii< drivers.size(); ii++) { 54 aritMeans = new TimeSeries("Arithmetic Means", Day.class); 56 geomMeans = new TimeSeries("Geometric Means", Day.class); 57 harmMeans = new TimeSeries("Harmonic Means", Day.class); 58 for (int i = 0; i < reports.length; i++) { 59 cal.setTime(dates[i]); 60 int day = cal.get(cal.DAY_OF_MONTH); 61 int month = cal.get(cal.MONTH) + 1; int year = cal.get(cal.YEAR); 63 result = (ResultPerDriver)reports[i].get(drivers.get(ii)); 65 aritMeans.add(new Day(day, month, year), result.getAritMean()); 69 geomMeans.add(new Day(day, month, year), result.getGeomMean()); 70 harmMeans.add(new Day(day, month, year), result.getHarmMean()); 71 } 72 _dataset.addSeries(aritMeans); 73 _dataset.addSeries(geomMeans); 74 _dataset.addSeries(harmMeans); 75 } 76 77 } 78 void getTestsDataset(ArrayList drivers, TrendReportParams params, 79 Map [] reports, Date [] dates) { 80 TimeSeries[] testcases; 81 GregorianCalendar cal = new GregorianCalendar (); 82 ResultPerDriver result = null; 83 String [] tests = params.test(); 84 85 for (int ii = 0; ii< drivers.size(); ii++) { 86 ArrayList ts = new ArrayList (); 87 for(int i=0; i<tests.length; i++) { 88 ts.add(new TimeSeries(tests[i], Day.class)); 89 } 90 testcases = new TimeSeries[ts.size()]; 91 ts.toArray(testcases); 92 for (int i = 0; i < reports.length; i++) { 94 cal.setTime(dates[i]); 95 int day = cal.get(cal.DAY_OF_MONTH); 96 int month = cal.get(cal.MONTH) + 1; int year = cal.get(cal.YEAR); 98 result = (ResultPerDriver)reports[i].get(drivers.get(ii)); 99 for(int j=0; j<tests.length; j++) { 100 if (result.getResult(tests[j])!=0) testcases[j].add(new Day(day, month, year), result.getResult(tests[j])); 101 } 102 } 103 for(int j=0; j<tests.length; j++) { 104 _dataset.addSeries(testcases[j]); 105 } 106 } 107 108 } 109 void getDataset(TrendReportParams params, Map [] reports, Date [] dates) { 110 ArrayList drivers = new ArrayList (); 111 TimeSeries[] testcases; 112 if (!params.isDriverSpecified()) { 114 drivers.add(FIDRIVER); 115 drivers.add(XMLDRIVER); 116 } else { 117 drivers.add(params.driver()); 118 } 119 _dataset = new TimeSeriesCollection(); 120 if (!params.isTestSpecified()) { 121 getMeansDataset(drivers, reports, dates); 122 } else { 123 getTestsDataset(drivers, params, reports, dates); 124 } 125 126 _dataset.setDomainIsPointsInTime(true); 127 128 } 129 public XYDataset getDataset() { 130 return _dataset; 131 } 132 } 133 | Popular Tags |