-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGenerateReport.java
More file actions
152 lines (104 loc) · 4.54 KB
/
GenerateReport.java
File metadata and controls
152 lines (104 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package support;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
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.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import java.awt.*;
import java.io.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by du on 06/04/17.
*/
public class GenerateReport {
private static final String REPORT_FOLDER = "reportFiles/";
private static List<ChartFrame> chartFrames;
public static void main(String args[]){
chartFrames = new ArrayList<>();
File directory = new File(REPORT_FOLDER);
File[] contents = directory.listFiles();
List<File> files = Arrays.stream(contents).filter(file -> !file.getName().equals(".DS_Store")).collect(Collectors.toList());
files.stream().forEach( file -> {
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader(file));
String sResult = bufferedReader.readLine();
Gson gson = new Gson();
Type listType = new TypeToken<Graph>(){}.getType();
Graph graph = gson.fromJson(sResult, listType);
createChart(graph, graph.title);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
});
}
private static ChartFrame createChart(Graph graph, String title){
XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
graph.results.stream().forEach(result -> {
List<XYSeries> xySeries = xySeriesCollection.getSeries();
List<XYSeries> foundSerie = xySeries.stream().filter(xy -> xy.getKey().equals(result.variableName)).collect(Collectors.toList());
if(foundSerie.size() > 0){
foundSerie.get(0).add((double)result.x, (double)result.y);
}
else{
XYSeries serie = new XYSeries(result.variableName);
serie.add((double)result.x, (double)result.y);
xySeriesCollection.addSeries(serie);
}
});
XYSeries experimentAverage = new XYSeries("Experiments' Average");
for (double i=1; i <= 900; i++){
double finalI = i;
List<Result> timeResult = graph.results.stream().filter(result -> ((double)result.x) == finalI).collect(Collectors.toList());
final double[] meanY = {0};
timeResult.stream().forEach(result -> {
meanY[0] += (double)result.y;
});
experimentAverage.add(i, meanY[0]/timeResult.size());
}
xySeriesCollection.addSeries(experimentAverage);
final JFreeChart chart = ChartFactory.createXYLineChart(
title,
graph.xTitle,
graph.yTitle,
xySeriesCollection,
PlotOrientation.VERTICAL,
true,
true,
false
);
//TimeSeries dataset3 = MovingAverage.createMovingAverage(t1, "LT", 49, 49);
//XYDataset experimentAverage = MovingAverage.createMovingAverage(xySeriesCollection, "Experiment Average", 50, 0);
XYPlot xyPlot = (XYPlot) chart.getPlot();
//xyPlot.setDataset(0, experimentAverage);
xyPlot.setDomainCrosshairVisible(true);
xyPlot.setRangeCrosshairVisible(true);
XYLineAndShapeRenderer xyLineAndShapeRenderer = (XYLineAndShapeRenderer)xyPlot.getRenderer();
xyLineAndShapeRenderer.setBaseShapesVisible(false);
Font font3 = new Font("Dialog", Font.PLAIN, 20);
xyPlot.getDomainAxis().setLabelFont(font3);
xyPlot.getRangeAxis().setLabelFont(font3);
NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
domain.setRange(0.00, 900);
xyPlot.setBackgroundPaint(Color.lightGray);
xyPlot.setDomainGridlinePaint(Color.white);
xyPlot.setRangeGridlinePaint(Color.white);
chart.setBackgroundPaint(Color.lightGray);
ChartFrame frame = new ChartFrame(title, chart);
frame.pack();
frame.setVisible(true);
return frame;
}
}