-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDisplayChart.java
139 lines (124 loc) · 4.49 KB
/
DisplayChart.java
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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.awt.Color;
import java.awt.BasicStroke;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
public class DisplayChart extends ApplicationFrame {
private static String fName;
private static String[][] results;
public DisplayChart( String applicationTitle, String chartTitle, String[][] resData) {
super(applicationTitle);
results=resData;
JFreeChart xylineChart = ChartFactory.createXYLineChart(
chartTitle ,
"Set Size" ,
"Page Faults" ,
createDataset() ,
PlotOrientation.VERTICAL ,
true , true , false);
ChartPanel chartPanel = new ChartPanel( xylineChart );
chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) );
final XYPlot plot = xylineChart.getXYPlot( );
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer( );
renderer.setSeriesPaint( 0 , Color.RED );
renderer.setSeriesPaint( 1 , Color.GREEN );
renderer.setSeriesPaint( 2 , Color.YELLOW );
renderer.setSeriesStroke( 0 , new BasicStroke( 4.0f ) );
renderer.setSeriesStroke( 1 , new BasicStroke( 3.0f ) );
renderer.setSeriesStroke( 2 , new BasicStroke( 2.0f ) );
plot.setRenderer( renderer );
setContentPane( chartPanel );
}
private XYDataset createDataset( ) {
final XYSeries random = new XYSeries( "Random Algorithm" );
final XYSeries lrua = new XYSeries( "LRUA" );
final XYSeries optimal = new XYSeries( "Optimal" ); int x=0;int y=0;int z=0;
for(int i = 0; i<results.length;i++)
{
System.out.println(results[i][0]);
/*
* Memorandum: figure out why it is that == isn't working as a comparison operator here.
*/
if(results[i][0].equals("Optimal")){
optimal.add(Double.parseDouble(results[i][2]),
Double.parseDouble(results[i][3]));x++;
}else if(results[i][0].equals("LRUA")){
lrua.add(Double.parseDouble(results[i][2]),
Double.parseDouble(results[i][3]));y++;
}else{
random.add(Double.parseDouble(results[i][2]),
Double.parseDouble(results[i][3]));z++;
}
}
final XYSeriesCollection dataset = new XYSeriesCollection( );
dataset.addSeries(random);
dataset.addSeries(lrua);
dataset.addSeries(optimal);
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println(results.length);
return dataset;
}
public static String[][] procData(List<String> data)
{
String[][] parsedData=new String[data.size()][4];
for(int i=0;i<data.size();i++)
{
String[] temp = data.get(i).split(",|:");
temp[0]=temp[0].replaceAll("\\s+","");
temp[1]=temp[1].replaceAll("\\s+","");
temp[2]=temp[2].replaceAll("\\s+","");
temp[2]=temp[2].substring(7);
temp[3]=temp[3].replaceAll("\\s+","");
parsedData[i]=temp;
}
return parsedData;
}
public static ArrayList<String> readFile() throws IOException
{
List<String> data=new ArrayList<String>();
BufferedReader br = new BufferedReader(new FileReader(fName));
String line;
while ((line = br.readLine()) != null) {
if(line.length()!=0)
data.add(line);
}
return (ArrayList<String>) data;
}
public static void setFile(String file){
fName=file;
}
public static void main( String[ ] args ) throws IOException
{
String fName="Tests.txt";
setFile(fName);
List<String> data=readFile();
String[][] parsedData=procData(data);
DisplayChart dC=new DisplayChart("AlgorithmRes", "Results", parsedData);
dC.pack( );
RefineryUtilities.centerFrameOnScreen(dC);
dC.setVisible( true );
// for(int i=0;i<data.size();i++){
// System.out.print("*");
// for(int j=0;j<4;j++){
// System.out.print(parsedData[i][j]);
// System.out.print("*");
// }
// System.out.println();
// }
}
}