KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > japex > report > TrendDataset


1 /*
2  * TrendDataset.java
3  *
4  * Created on April 8, 2005, 3:06 PM
5  */

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 JavaDoc;
30 import java.util.Date JavaDoc;
31 import java.util.Calendar JavaDoc;
32 import java.util.GregorianCalendar JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.ArrayList JavaDoc;
35
36 public class TrendDataset {
37     static final String JavaDoc FIDRIVER = "TestFIDriver";
38     static final String JavaDoc XMLDRIVER ="TestXMLDriver";
39     TimeSeriesCollection _dataset;
40     
41     /** Creates a new instance of TrendDataset */
42     public TrendDataset(TrendReportParams params, ParseReports testReports) {
43         Map JavaDoc[] reports = testReports.getReports();
44         if (reports != null) {
45             Date JavaDoc[] dates = testReports.getDates();
46             getDataset(params, reports, dates);
47         }
48     }
49     void getMeansDataset(ArrayList JavaDoc drivers, Map JavaDoc[] reports, Date JavaDoc[] dates) {
50         TimeSeries aritMeans, geomMeans, harmMeans;
51         ResultPerDriver result = null;
52         GregorianCalendar JavaDoc cal = new GregorianCalendar JavaDoc();
53         for (int ii = 0; ii< drivers.size(); ii++) {
54             //if [testcase] is not specified, output means
55
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; //month starts at 0!
62
int year = cal.get(cal.YEAR);
63 // System.out.println(day + "-" + month + "-" + year);
64
result = (ResultPerDriver)reports[i].get(drivers.get(ii));
65 // System.out.println("AritMean="+result.getAritMean());
66
// System.out.println("GeomMean="+result.getGeomMean());
67
// System.out.println("HarmMean="+result.getHarmMean());
68
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 JavaDoc drivers, TrendReportParams params,
79             Map JavaDoc[] reports, Date JavaDoc[] dates) {
80         TimeSeries[] testcases;
81         GregorianCalendar JavaDoc cal = new GregorianCalendar JavaDoc();
82         ResultPerDriver result = null;
83         String JavaDoc[] tests = params.test();
84         
85         for (int ii = 0; ii< drivers.size(); ii++) {
86             ArrayList JavaDoc ts = new ArrayList JavaDoc();
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             //testcases = (TimeSeries[])ts.toArray();
93
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; //month starts at 0!
97
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 JavaDoc[] reports, Date JavaDoc[] dates) {
110         ArrayList JavaDoc drivers = new ArrayList JavaDoc();
111         TimeSeries[] testcases;
112         //if [driver] is not specified, output both drivers
113
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