-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatisticsChart.java
More file actions
215 lines (173 loc) · 6.01 KB
/
StatisticsChart.java
File metadata and controls
215 lines (173 loc) · 6.01 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package Jvakt;
/*
* 2022-06-23 V.54 Michael Ekdal Added getVersion() to get at consistent version throughout all classes.
*/
import java.awt.*;
import java.io.BufferedReader;
//import java.io.BufferedWriter;
import java.io.File;
//import java.io.FileOutputStream;
import java.io.FileReader;
//import java.io.IOException;
//import java.io.OutputStreamWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import org.jfree.chart.*;
//import org.jfree.chart.axis.CategoryAxis;
//import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
//import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.chart.ui.*;
public class StatisticsChart extends ApplicationFrame
{
static String statF;
static File statIn;
static Vector<String> map = new Vector<String>(100,100);
static String from = "2021-09-28 00:00:00";
static String tom = "2021-09-28 24:00:00";
static String[] tab = new String [1];
static String chdat = new String("yyyy-MM-dd HH:mm:ss");
static SimpleDateFormat dat_form;
static Date now;
static Date then;
public static void main(String args[])
{
dat_form = new SimpleDateFormat(chdat);
now = new Date();
then = new Date();
then.setTime(now.getTime()-86400000);
now.setTime(now.getTime()+86400000); // add 24 hours
tom = dat_form.format(now);
from= dat_form.format(then);
// System.out.println("Now :"+now);
// System.out.println("Then :"+then);
if (args.length < 1) {
System.out.println("\n\nStatisticsChart 2022-01-24. The parameters and their meaning are:\n"+
"\n-statf \tThe input file to analyze. Like: \"-dir c:\\Temp\\monHttp-test.csv\" "+
"\n-from \tDate and time in format yyyy-MM-dd HH:mm:ss. The default is 24 hours in the past."+
"\n-to \tDate and time in format yyyy-MM-dd HH:mm:ss. The default is 24 hours in the future."
);
System.exit(4);
}
// reads command line arguments
for ( int i = 0; i < args.length; i++) {
// if (args[i].equalsIgnoreCase("-from")) from = args[++i];
// if (args[i].equalsIgnoreCase("-to")) tom = args[++i];
// if (args[i].equalsIgnoreCase("-statf")) statF = args[++i];
if (args[i].equalsIgnoreCase("-from")) {
from = args[++i];
from = from.replace('?',' ');
}
if (args[i].equalsIgnoreCase("-to")) {
tom = args[++i];
tom = tom.replace('?',' ');
}
if (args[i].equalsIgnoreCase("-statf")) {
statF = args[++i];
statF = statF.replace('?',' ');
}
}
System.out.println("statF: " + statF);
statIn = new File(statF);
// StatisticsChart PCategory = new StatisticsChart(statIn.getName());
StatisticsChart PCategory = new StatisticsChart("Jvakt.StatisticsChart renderer "+getVersion()+".54");
PCategory.pack();
PCategory.setVisible(true);
// System.out.println("Slut i rutan!");
}
private static final long serialVersionUID = 1L;
public StatisticsChart(String s)
{
super(s);
JPanel jpanel = createDemoPanel();
jpanel.setPreferredSize(new Dimension(1700, 800));
setContentPane(jpanel);
ImageIcon img = new ImageIcon("console.png");
setIconImage(img.getImage());
}
public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
ChartPanel chartpanel = new ChartPanel(jfreechart);
chartpanel.setMouseWheelEnabled(true);
return chartpanel;
}
private static JFreeChart createChart(CategoryDataset categorydataset)
{
JFreeChart jfreechart = ChartFactory.createLineChart("Response times of "+statIn.getName(), "time", "ms", categorydataset, PlotOrientation.VERTICAL, true, true, false);
jfreechart.addSubtitle(new TextTitle("From: "+from+" to: "+tom));
CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot();
// Set font for category labels.
categoryplot.getDomainAxis().setTickLabelsVisible(false);
categoryplot.getDomainAxis().setTickMarksVisible(false);
categoryplot.getDomainAxis().setLowerMargin(0);
categoryplot.getDomainAxis().setUpperMargin(0);
ChartUtils.applyCurrentTheme(jfreechart);
return jfreechart;
}
private static CategoryDataset createDataset()
{
String s;
double rowCount = 0;
double average = 0;
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
try {
BufferedReader in = new BufferedReader(new FileReader(statIn));
while ((s = in.readLine()) != null) {
boolean swComment=false;
// System.out.println(s);
if (s.length() == 0) swComment=true;
if (s.startsWith("#")) swComment=true;
tab = s.split(";" , 2);
if (!swComment && from.compareTo(tab[0])<=0 && tom.compareTo(tab[0])>=0) {
map.add(s);
average += Integer.parseInt(tab[1]);
rowCount++;
}
}
in.close();
} catch (Exception ex) {
System.out.println("-- Exeption when open the statistical file "+statIn);
ex.printStackTrace();
}
System.out.println("rowCount : " + rowCount);
System.out.println("mapSize : "+map.size());
rowCount=0;
for (int i = 0; i < map.size(); i++) {
boolean swComment=false;
// System.out.println(s);
s = map.get(i);
if (!swComment) {
tab = s.split(";" , 2);
if (rowCount<=14400) {
defaultcategorydataset.addValue(Integer.parseInt(tab[1]),"Response time", tab[0].trim());
if (Integer.parseInt(tab[1])>0) rowCount++;
}
}
if (rowCount > 14400) break;
}
System.out.println("rowCount : " + rowCount);
System.out.println("average : " + (average/rowCount));
map.clear();
return defaultcategorydataset;
}
static private String getVersion() {
String version = "0";
try {
Class<?> c1 = Class.forName("Jvakt.Version",false,ClassLoader.getSystemClassLoader());
Version ver = new Version();
version = ver.getVersion();
}
catch (java.lang.ClassNotFoundException ex) {
version = "?";
}
return version;
}
}