ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/DBReporter2/ReportMaker.java
(Generate patch)

Comparing projects/cms/source/reports/DBReporter2/ReportMaker.java (file contents):
Revision 1.1 by pjm2, Sat Feb 3 14:56:14 2001 UTC vs.
Revision 1.4 by pjm2, Sat Feb 3 20:47:11 2001 UTC

# Line 5 | Line 5 | import java.io.*;
5  
6   import uk.ac.ukc.iscream.util.*;
7  
8 +
9 + // ReportMaker class - used to produce each type of report for a machine.
10   public class ReportMaker {
11 <    
12 <    public ReportMaker(Statement stmt, String dateDir, long startTime, long endTime) {
11 >
12 >    // Constructor.  This takes the database Statement.    
13 >    public ReportMaker(Statement stmt, String webDir, String dateDir, long startTime, long endTime) {
14          _stmt = stmt;
15 +        _webDir = webDir;
16          _dateDir = dateDir;
17          _startTime = startTime;
18          _endTime = endTime;
19      }
20      
21 <    public void produce(ReportList reports, String machine) {
21 >    // Produce all reports in the report list for the machine.
22 >    public void produce(ReportList reports, String machine) throws SQLException {
23          
19        if (1==1)
20            return;
21        
24          System.out.println("Producing reports for " + machine + ".");
25  
26 +        // Make a list of PlotData objects to build the charts.
27 +        LinkedList plots = new LinkedList();
28          Iterator reportIt = reports.iterator();
29          while (reportIt.hasNext()) {
30 <            Report report = (Report)reportIt.next();
31 <            report.setPlotData(null);
28 <            report.setPlotData(new PlotData(_startTime, _endTime));
30 >            reportIt.next();
31 >            plots.add(new PlotData(_startTime, _endTime));
32          }
33          
34 <        String sql = "SELECT receipt_date, xml FROM ipacket WHERE machine_name='" + machine + "' ORDER BY receipt_date;";
35 <
34 >        
35 >        // Select the data we nede from the database.
36 >        String sql = "SELECT receipt_date, xml FROM ipacket WHERE machine_name='" + machine + "' AND receipt_date>=" + _startTime + " AND receipt_date<=" + _endTime + " ORDER BY receipt_date;";
37          ResultSet rs = null;
38          try {
39              rs = _stmt.executeQuery(sql);
# Line 52 | Line 56 | public class ReportMaker {
56                  pm = new XMLPacketMaker(xml);
57                  packet = pm.createXMLPacket();
58                  reportIt = reports.iterator();
59 +                Iterator plotIt = plots.iterator();
60                  while (reportIt.hasNext()) {
61 +                    PlotData plotData = (PlotData)plotIt.next();
62                      Report report = (Report)reportIt.next();
63                      String reportField = report.getReportField();
58                    PlotData plotData = report.getPlotData();
64                      long x = rs.getLong("receipt_date");
65                      double y;
66                      try {
# Line 68 | Line 73 | public class ReportMaker {
73                      plotData.addPoint(x, y);
74                  }
75              }
76 +            rs.close();
77          }
78          catch (SQLException e) {
79              System.out.println("SQLException: " + e);
# Line 75 | Line 81 | public class ReportMaker {
81          
82          System.out.println("[DEBUG]Writing graphs to disk.");
83          
84 +        // Write a chart of each report to disk.
85 +        Iterator plotIt = plots.iterator();
86          reportIt = reports.iterator();
87          while (reportIt.hasNext()) {
88              Report report = (Report)reportIt.next();
89              String reportField = report.getReportField();
90 <            PlotData plotData = report.getPlotData();
90 >            PlotData plotData = (PlotData)plotIt.next();
91              plotData.flushPoints();
92              plotData.scaleToFitX(SHTMLLayout.CHART_WIDTH, SHTMLLayout.CHART_HEIGHT);
93              IscreamChart chart = new IscreamChart(_startTime, _endTime);
# Line 89 | Line 97 | public class ReportMaker {
97              }
98              BufferedImage img = chart.drawChart(plotData, SHTMLLayout.CHART_WIDTH, SHTMLLayout.CHART_HEIGHT, 24, 10, maxY);
99              IscreamChartWriter imgWriter = new IscreamChartWriter();
100 <            imgWriter.writeChart(img, _dateDir + "_" + machine + "_" + reportField + ".gif");
101 <            System.out.println("[DEBUG]Point count: " + plotData.countPoints());
102 <            report.clearPlotData();
103 <            System.out.println("[DEBUG]Point count: " + plotData.countPoints());
100 >            IscreamFilePlacer placer = new IscreamFilePlacer(_webDir);
101 >            File destination = placer.makeDirs(_dateDir, machine, reportField);
102 >            imgWriter.writeChart(img, new File(destination, "chart.gif"));
103 >            System.out.println("[DEBUG]Point count: " + plotData.countPoints());            
104          }
105          
106      }
107      
108      private Statement _stmt = null;
109 +    private String _webDir;
110      private String _dateDir;
111      private long _startTime;
112      private long _endTime;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines