-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDataAnalyzerBackup.txt
More file actions
3395 lines (3021 loc) · 150 KB
/
DataAnalyzerBackup.txt
File metadata and controls
3395 lines (3021 loc) · 150 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dataanalyzer;
import dataanalyzer.dialog.VehicleDataDialog;
import dataanalyzer.dialog.AskVehicleDialog;
import dataanalyzer.dialog.MathChannelDialog;
import dataanalyzer.dialog.MarkerNotesDialog;
import dataanalyzer.dialog.LapDataDialog;
import com.arib.categoricalhashtable.*;
import com.arib.toast.Toast;
import com.hareesh.progressbar.ProgressBar;
import com.sun.glass.events.KeyEvent;
import dataanalyzer.dialog.ApplyFilteringDialog;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Panel;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileWriter;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JFileChooser;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.ListModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartMouseEvent;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.panel.CrosshairOverlay;
import org.jfree.chart.plot.Crosshair;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.ValueMarker;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYSplineRenderer;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleEdge;
/**
*
* @author aribdhuka
*/
public class DataAnalyzerBackup extends javax.swing.JFrame implements ChartMouseListener {
// Chartpanel object exists so that it can be accessed in the chartmouselistener methods.
ChartPanel chartPanel;
// X and Y crosshairs
Crosshair xCrosshair;
Crosshair yCrosshair;
// X and Y vals
public double xCor = 0;
public double yCor = 0;
//Crosshair
CrosshairOverlay overlay;
// Stores the data set for each data type ( RPM vs Time, Distance vs Time....)
CategoricalHashMap dataMap;
//Stores all the static markers the user has created
CategoricalHashTable<CategorizedValueMarker> staticMarkers;
//Stores the vehicle data
VehicleData vehicleData;
//Stores the array of String in the listview of tags
String[] titles;
//holds the currently selected laps
int[] selectedLaps;
//Stores the current filepath
private String openedFilePath;
//stores the laps breaker
private ArrayList<Lap> lapBreaker;
//status of lapBreakerTool
int lapBreakerActive;
//lap that will be created and applied to lapBreaker list
Lap newLap;
//holds if file operations are currently ongoing
private boolean openingAFile;
//holds the default positions of the chartFrame
private int frameLocX;
private int frameLocY;
//String array that populates the categories list
//TODO: add tags to each list element.
AnalysisCategory[] analysisCategories = new AnalysisCategory[] { s
new AnalysisCategory("Brakes").addTag("Time,BrakePressureFront").addTag("Time,BrakePressureRear").addTag("Time,xAccel").addTag("Time,yAccel").addTag("Time,zAccel"),
new AnalysisCategory("Brake Balance").addTag("Time,BrakePressureFront").addTag("Time,BrakePressureRear").addTag("Time,BrakeBalance"),
new AnalysisCategory("Coolant").addTag("Time,Coolant").addTag("Time,RadiatorInlet"),
new AnalysisCategory("Acceleration").addTag("Time,xAccel").addTag("Time,yAccel").addTag("Time,zAccel").addTag("Time,RPM").addTag("Time,WheelspeedFront").addTag("Time,WheelspeedRear"),
new AnalysisCategory("Endurance").addTag("Time,RPM"),
new AnalysisCategory("Skidpad")};
public DataAnalyzerBackup() {
initComponents();
//Set the title of the frame
this.setTitle("DataAnalyzer");
//set window listener
DataAnalyzer curr = this;
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
int promptResult = JOptionPane.showConfirmDialog(curr,
"Would you like to save before closing this window?", "Save Before Close?",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE);
switch(promptResult) {
case JOptionPane.YES_OPTION : saveFile(openedFilePath); curr.dispose(); break;
case JOptionPane.NO_OPTION : curr.dispose(); break;
case JOptionPane.CANCEL_OPTION : break;
}
}
});
//start with not currently opening a file
openingAFile = false;
//disable the layout manager which essentially makes the frame an absolute positioning frame
this.setLayout(null);
// Create a new hash map
dataMap = new CategoricalHashMap();
//create a new instance of the vehicle data
vehicleData = new VehicleData();
//start with empty lap data
lapBreaker = new ArrayList<>();
//start with the lapBreaker disables
lapBreakerActive = -1;
//initialize new Lap
newLap = new Lap();
//start with no laps selected
selectedLaps = null;
//on new element entry of dataMap, update the view
dataMap.addTagSizeChangeListener(new HashMapTagSizeListener() {
@Override
public void sizeUpdate() {
fillDataList(dataMap.tags);
if(!openingAFile)
Lap.applyToDataset(dataMap, lapBreaker);
}
});
//init the arraylist of static markers
staticMarkers = new CategoricalHashTable<>();
// Init the graph with some dummy data until there is data given to read
showEmptyGraph();
//extend the statistics panel to the edge
//get the screen size
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//get xCordinate of the statisticsPanel
statisticsPanel.setSize(screenSize.width - statisticsPanel.getX(), statisticsPanel.getHeight());
// Create the global object crosshairs
overlay = new CrosshairOverlay();
this.xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
this.xCrosshair.setLabelVisible(true);
this.yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f));
this.yCrosshair.setLabelVisible(true);
overlay.addDomainCrosshair(xCrosshair);
overlay.addRangeCrosshair(yCrosshair);
chartPanel.addOverlay(overlay);
//init the array
titles = new String[10];
//set the opened file path to empty string to prevent null pointer exceptions
openedFilePath = "";
//populate category list
String[] categoryListData = new String[analysisCategories.length];
for(int i = 0; i < analysisCategories.length; i++) {
categoryListData[i] = analysisCategories[i].getTitle();
}
categoryList.setListData(categoryListData);
//set default locations of the chartFrame
frameLocX = chartFrame.getX();
frameLocY = chartFrame.getY();
}
private void showEmptyGraph() {
final XYSeriesCollection data = new XYSeriesCollection();
// Add values of (Age, Happiness)
final XYSeries series = new XYSeries("Me");
Random rand = new Random();
series.add(0, rand.nextInt(100));
series.add(5, rand.nextInt(100));
series.add(10, rand.nextInt(100));
series.add(16, rand.nextInt(100));
series.add(18, rand.nextInt(100));
series.add(20, rand.nextInt(100));
series.add(22, rand.nextInt(100));
series.add(25, rand.nextInt(100));
series.add(30, rand.nextInt(100));
data.addSeries(series);
// Create a JFreeChart from the Factory, given parameters (Chart Title, Domain name, Range name, series collection, PlotOrientation, show legend, show tooltips, show url)
JFreeChart chart = ChartFactory.createXYLineChart(
"Happiness vs Age",
"Age",
"Happiness",
data,
PlotOrientation.VERTICAL,
true,
true,
false
);
// Instantiate chart panel object from the object created from ChartFactory
chartPanel = new ChartPanel(chart);
// Set the size of the panel
chartPanel.setSize(new java.awt.Dimension(899, 589));
// Mouse listener
chartPanel.addChartMouseListener(this);
// The form has a subframe inside the mainframe
// Set the subframe's content to be the chartpanel
chartFrame.setContentPane(chartPanel);
}
private void showHistogram() {
String title = chartPanel.getChart().getTitle().getText();
String[] titleSplit = title.split(" vs ");
String[] tags = new String[titleSplit.length - 1];
for (int i = 0; i < titleSplit.length - 1; i++) {
tags[i] = titleSplit[titleSplit.length - 1] + "," + titleSplit[i];
}
//update laps
XYSeriesCollection data = getHistogramDataCollection(tags, selectedLaps);
// Gets the independent variable from the title of the data
String yAxis = "Milliseconds";
// Gets the dependent variable from the title of the data
String xAxis = title.split(" vs ")[0]; //split title by vs, we get ["RPM", "Time"] or something like that
//create histogram
JFreeChart chart = ChartFactory.createHistogram(
title,
xAxis,
yAxis,
data,
PlotOrientation.VERTICAL,
true,
true,
false
);
//apply histogram to chart panel
chartPanel = new ChartPanel(chart);
//set size
chartPanel.setSize(new java.awt.Dimension(800, 600));
//set frame content
chartFrame.setContentPane(chartPanel);
//update statistics panel
updateStatistics(tags, selectedLaps);
}
// Displays the data for all selected data types
private void setChart(String[] tags, int[] laps) {
// Gets the specific data based on what kind of data we want to show for which
XYSeriesCollection[] seriesCollection;
if(laps == null || laps.length == 0) {
seriesCollection = new XYSeriesCollection[tags.length];
} else {
seriesCollection = new XYSeriesCollection[tags.length * laps.length];
}
String title = "";
// Store data for each data type in different XYSeriesCollection
// New title for all the Y-Axis labels added together
for(int i = 0; i < tags.length; i++){
seriesCollection[i] = getDataCollection(tags[i], laps);
title += tags[i].split(",")[1] + " vs ";
}
//add domain
title += tags[0].split(",")[0];
// Use XYPlot in JFreeChart to draw the data
XYPlot plot = new XYPlot();
for(int i = 0; i < tags.length; i++){
// Assign each dataset at some index
plot.setDataset(i, seriesCollection[i]);
// Label the Y-Axis for specific data set
plot.setRangeAxis(i, new NumberAxis(tags[i].split(",")[1]));
// Give the line a different color
plot.setRenderer(i, getNewRenderer(i));
// Makes sure that the Y-values for each dataset are proportional to the data inside it
plot.mapDatasetToRangeAxis(i, i);
}
// Just show the X-Axis data type (Time, Distance, etc)
plot.setDomainAxis(new NumberAxis(tags[0].split(",")[0]));
// Create a new JFreeChart with the XYPlot
JFreeChart chart = new JFreeChart(title, getFont(), plot, true);
chart.setBackgroundPaint(Color.WHITE);
// Instantiate chart panel object from the object created from ChartFactory
chartPanel = new ChartPanel(chart);
chartPanel.addOverlay(overlay);
// Set the size of the panel
chartPanel.setSize(new java.awt.Dimension(800, 600));
// Mouse listener
chartPanel.addChartMouseListener(this);
// The form has a subframe inside the mainframe
// Set the subframe's content to be the chartpanel
chartFrame.setContentPane(chartPanel);
//update statistics
updateStatistics(titleToTag(), laps);
//draw markers
drawMarkers(tags, chart.getXYPlot());
}
// Displays the data for all selected data types
private void setChart(String[] tags, int[] laps, int bucketSize) {
// Gets the specific data based on what kind of data we want to show for which
XYSeriesCollection[] seriesCollection;
if(laps == null || laps.length == 0) {
seriesCollection = new XYSeriesCollection[tags.length];
} else {
seriesCollection = new XYSeriesCollection[tags.length * laps.length];
}
String title = "";
// Store data for each data type in different XYSeriesCollection
// New title for all the Y-Axis labels added together
for(int i = 0; i < tags.length; i++){
seriesCollection[i] = getDataCollection(tags[i], laps, bucketSize);
title += tags[i].split(",")[1] + " vs ";
}
//add domain
title += tags[0].split(",")[0];
// Use XYPlot in JFreeChart to draw the data
XYPlot plot = new XYPlot();
for(int i = 0; i < tags.length; i++){
// Assign each dataset at some index
plot.setDataset(i, seriesCollection[i]);
// Label the Y-Axis for specific data set
plot.setRangeAxis(i, new NumberAxis(tags[i].split(",")[1]));
// Give the line a different color
plot.setRenderer(i, getNewRenderer(i));
// Makes sure that the Y-values for each dataset are proportional to the data inside it
plot.mapDatasetToRangeAxis(i, i);
}
// Just show the X-Axis data type (Time, Distance, etc)
plot.setDomainAxis(new NumberAxis(tags[0].split(",")[0]));
// Create a new JFreeChart with the XYPlot
JFreeChart chart = new JFreeChart(title, getFont(), plot, true);
chart.setBackgroundPaint(Color.WHITE);
// Instantiate chart panel object from the object created from ChartFactory
chartPanel = new ChartPanel(chart);
chartPanel.addOverlay(overlay);
// Set the size of the panel
chartPanel.setSize(new java.awt.Dimension(800, 600));
// Mouse listener
chartPanel.addChartMouseListener(this);
// The form has a subframe inside the mainframe
// Set the subframe's content to be the chartpanel
chartFrame.setContentPane(chartPanel);
//update statistics
updateStatistics(titleToTag(), laps);
//draw markers
drawMarkers(tags, chart.getXYPlot());
}
// Creates a new render for a new series or data type. Gives a new color
private XYSplineRenderer getNewRenderer(int index){
Random r = new Random();
int rand = r.nextInt(5);
XYSplineRenderer sx = new XYSplineRenderer();
switch (rand){
case 0:
sx.setSeriesFillPaint(index, Color.BLUE);
break;
case 1:
sx.setSeriesFillPaint(index, Color.GREEN);
break;
case 2:
sx.setSeriesFillPaint(index, Color.CYAN); //TODO: CHECK IF THIS FIXED THIS SHITTY YELLOW PIECE OF SHIT COLOR
break;
case 3:
sx.setSeriesFillPaint(index, Color.BLACK);
break;
case 4:
sx.setSeriesFillPaint(index, Color.ORANGE);
break;
}
return sx;
}
/**
* Generates a XYSeriesCollection based on a list retrieved from a tag
* @param tag the tag of the dataset, used to get the data from the CategoricalHashMap
* @param laps the laps the user wants to see
* @return
*/
private XYSeriesCollection getDataCollection(String tag, int[] laps) {
// XY Series Collection allows there to be multiple data lines on the graph
XYSeriesCollection graphData = new XYSeriesCollection();
//if laps were not provided show whole dataset
if(laps == null || laps.length == 0) {
// Get the list of data elements based on the tag
LinkedList<LogObject> data = dataMap.getList(tag);
// Declare the series to add the data elements to
final XYSeries series = new XYSeries(tag.split(",")[1]);
//if tag contains time then its not a function of another dataset
if(tag.contains("Time,")) {
// We could make a XYSeries Array if we wanted to show different lap data
// final XYSeries[] series = new XYSeries[laps.length]; <--- if we wanted to show different laps at the same time
// Iterate through each data element in the received dataMap LinkedList
for (LogObject d : data) {
//Get the x and y values by seprating them by the comma
String[] values = d.toString().split(",");
//Add the x and y value to the series
series.add(Long.parseLong(values[0]), Double.parseDouble(values[1]));
}
} else {
// We could make a XYSeries Array if we wanted to show different lap data
// final XYSeries[] series = new XYSeries[laps.length]; <--- if we wanted to show different laps at the same time
// Iterate through each data element in the received dataMap LinkedList
for (LogObject d : data) {
//Get the x and y values by seprating them by the comma
String[] values = d.toString().split(",");
//Add the x and y value to the series
series.add(Double.parseDouble(values[0]), Double.parseDouble(values[1]));
}
}
//add series to collection
graphData.addSeries(series);
} else { //if lap data was provided
//for each lap
for(int i = 0; i < laps.length; i++) {
Lap currLap = new Lap(0, 0);
for(Lap lap : lapBreaker) {
if(lap.lapNumber == laps[i]) {
currLap = lap;
}
}
//create a series with the tag and lap #
XYSeries series = new XYSeries(tag.split(",")[1] + "Lap " + laps[i]);
//if its a base dataset
if(tag.contains("Time,")) {
//for each log object if the log object belongs in this lap add it to the series
for(LogObject lo : dataMap.getList(tag)) {
if(lo.getLaps().contains(laps[i])) {
//Get the x and y values by seprating them by the comma
String[] values = lo.toString().split(",");
//Add the x and y value to the series
series.add(Long.parseLong(values[0]) - currLap.start, Double.parseDouble(values[1]));
}
}
//else its function of another dataset
} else {
//for each log object if the log object belongs in this lap, add it to the series
for(LogObject lo : dataMap.getList(tag)) {
if(lo.getLaps().contains(laps[i])) {
//Get the x and y values by seprating them by the comma
String[] values = lo.toString().split(",");
//Add the x and y value to the series
series.add(Double.parseDouble(values[0]) - currLap.start, Double.parseDouble(values[1]));
}
}
}
//add to collection
graphData.addSeries(series);
}
}
// Return the XYCollection
return graphData;
}
private XYSeriesCollection getDataCollection(String tag, int[] laps, int bucketSize) {
// XY Series Collection allows there to be multiple data lines on the graph
XYSeriesCollection graphData = new XYSeriesCollection();
//if laps were not provided show whole dataset
if(laps == null || laps.length == 0) {
// Get the list of data elements based on the tag
LinkedList<LogObject> dataLinked = dataMap.getList(tag);
//copy to a arraylist for a better runtime letter
ArrayList<LogObject> data = new ArrayList<>(dataLinked.size());
for(LogObject lo : dataLinked) {
data.add(lo);
}
// Declare the series to add the data elements to
final XYSeries series = new XYSeries(tag.split(",")[1]);
//if tag contains time then its not a function of another dataset
if(tag.contains("Time,")) {
// We could make a XYSeries Array if we wanted to show different lap data
// final XYSeries[] series = new XYSeries[laps.length]; <--- if we wanted to show different laps at the same time
// Iterate through each data element in the received dataMap LinkedList
//for each element
for(int i = 0; i < data.size(); i++) {
//modifes the index
int modifier = ((bucketSize - 1) / 2) * -1;
//holds current avg
double avg = 0;
//x to add to series
long x = 0;
//how many indecies we actually used
int usedIndecies = 0;
//while we have not accounted for each item in the bucket
while(modifier <= ((bucketSize - 1) / 2)) {
//make sure the index is correct
if(i + modifier > -1 && i + modifier < data.size()) {
//add this index value's object's value
avg += Double.parseDouble(data.get(i + modifier).toString().split(",")[1]);
//increment usedIndevies
usedIndecies++;
}
if(modifier == 0) {
x = Long.parseLong(data.get(i + modifier).toString().split(",")[0]);
}
modifier++;
}
if(usedIndecies != 0) {
//calculate average
avg /= usedIndecies;
//add that to series
series.add(x, avg);
}
}
} else {
// We could make a XYSeries Array if we wanted to show different lap data
// final XYSeries[] series = new XYSeries[laps.length]; <--- if we wanted to show different laps at the same time
// Iterate through each data element in the received dataMap LinkedList
//for each element
for(int i = 0; i < data.size(); i++) {
//modifes the index
int modifier = ((bucketSize - 1) / 2) * -1;
//holds current avg
double avg = 0;
//x to add to series
double x = 0;
//how many indecies we actually used
int usedIndecies = 0;
//while we have not accounted for each item in the bucket
while(modifier <= ((bucketSize - 1) / 2)) {
//make sure the index is correct
if(i + modifier > -1 && i + modifier < data.size()) {
//add this index value's object's value
avg += Double.parseDouble(data.get(i + modifier).toString().split(",")[1]);
//increment usedIndevies
usedIndecies++;
}
if(modifier == 0) {
x = Double.parseDouble(data.get(i + modifier).toString().split(",")[0]);
}
modifier++;
}
if(usedIndecies != 0) {
//calculate average
avg /= usedIndecies;
//add that to series
series.add(x, avg);
}
}
}
//add series to collection
graphData.addSeries(series);
} else { //if lap data was provided
// Get the list of data elements based on the tag
LinkedList<LogObject> rawdata = dataMap.getList(tag);
//for each lap
for(int l = 0; l < laps.length; l++) {
Lap currLap = new Lap(0, 0);
for(Lap lap : lapBreaker) {
if(lap.lapNumber == laps[l]) {
currLap = lap;
}
}
//create a dataset of items only of the current lap.
LinkedList<LogObject> data = new LinkedList<>();
for(LogObject lo : rawdata) {
if(lo.laps.contains(laps[l]))
data.add(lo);
}
//create a series with the tag and lap #
XYSeries series = new XYSeries(tag.split(",")[1] + "Lap " + laps[l]);
//if its a base dataset
if(tag.contains("Time,")) {
//for each log object if the log object belongs in this lap add it to the series
for(int i = 0; i < data.size(); i++) {
//modifes the index
int modifier = ((bucketSize - 1) / 2) * -1;
//holds current avg
double avg = 0;
//x to add to series
long x = 0;
//how many indecies we actually used
int usedIndecies = 0;
//while we have not accounted for each item in the bucket
while(modifier <= ((bucketSize - 1) / 2)) {
//make sure the index is correct
if(i + modifier > -1 && i + modifier < data.size()) {
//add this index value's object's value
avg += Double.parseDouble(data.get(i + modifier).toString().split(",")[1]);
//increment usedIndevies
usedIndecies++;
}
if(modifier == 0) {
x = Long.parseLong(data.get(i + modifier).toString().split(",")[0]);
}
modifier++;
}
if(usedIndecies != 0) {
//calculate average
avg /= usedIndecies;
//add that to series
series.add(x - currLap.start, avg);
}
}
//else its function of another dataset
} else {
//for each element
for(int i = 0; i < data.size(); i++) {
//modifes the index
int modifier = ((bucketSize - 1) / 2) * -1;
//holds current avg
double avg = 0;
//x to add to series
double x = 0;
//how many indecies we actually used
int usedIndecies = 0;
//while we have not accounted for each item in the bucket
while(modifier <= ((bucketSize - 1) / 2)) {
//make sure the index is correct
if(i + modifier > -1 && i + modifier < data.size()) {
//add this index value's object's value
avg += Double.parseDouble(data.get(i + modifier).toString().split(",")[1]);
//increment usedIndevies
usedIndecies++;
}
if(modifier == 0) {
x = Double.parseDouble(data.get(i + modifier).toString().split(",")[0]);
}
modifier++;
}
if(usedIndecies != 0) {
//calculate average
avg /= usedIndecies;
//add that to series
series.add(x - currLap.start, avg);
}
}
}
//add to collection
graphData.addSeries(series);
}
}
// Return the XYCollection
return graphData;
}
private XYSeriesCollection getHistogramDataCollection(String[] tags, int[] laps) {
//collection to return
final XYSeriesCollection graphData = new XYSeriesCollection();
for(String tag : tags) {
//get data from dataset
LinkedList<LogObject> data = dataMap.getList(tag);
//if asked for data with laps, complete for each lap
if(laps != null) {
for(int l = 0; l < laps.length; l++) {
//series that will hold the data
XYSeries series = new XYSeries(tag.split(",")[1] + "Laps " + laps[l]);
//calculate min and max value of the data
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
for(LogObject lo : data) {
if(lo.getLaps().contains(laps[l])) {
if(lo instanceof SimpleLogObject) {
if(((SimpleLogObject) lo).getValue() > max)
max = ((SimpleLogObject) lo).getValue();
if(((SimpleLogObject) lo).getValue() < min)
min = ((SimpleLogObject) lo).getValue();
}
}
}
//get the intervals to work with
double interval = max - min;
interval /= 50;
//holds how many instances occured within this interval
int counter;
//for each of the 50 intervals
for(int i = 1; i < 51; i++) {
//start with 0 count
counter = 0;
//for each data element
for(LogObject lo : data) {
if(lo.getLaps().contains(laps[l])) {
//if its a simple log object its value can be obtained
if(lo instanceof SimpleLogObject) {
//if the value of the current object is between the interval we are searching for
if(((SimpleLogObject) lo).getValue() < ((interval * i) + min) && ((SimpleLogObject) lo).getValue() > ((interval * (i-1)) + min)) {
//increment the counter
counter++;
}
} else if(lo instanceof FunctionOfLogObject) {
if(((FunctionOfLogObject) lo).getValue() < ((interval * i) + min) && ((FunctionOfLogObject) lo).getValue() > ((interval * (i-1)) + min)) {
//increment the counter
counter++;
}
}
}
}
//if the counter is not 0, add the median of the interval we are looking for along with the counter to the series.
if(counter != 0)
series.add((((interval * i) + min) + ((interval * i - 1) + min))/2, counter*50);
}
graphData.addSeries(series);
}
} else {
//series that will hold the data
XYSeries series = new XYSeries(tag.split(",")[1]);
//calculate min and max value of the data
double min = Double.MAX_VALUE;
double max = Double.MIN_VALUE;
for(LogObject lo : data) {
if(lo instanceof SimpleLogObject) {
if(((SimpleLogObject) lo).getValue() > max)
max = ((SimpleLogObject) lo).getValue();
if(((SimpleLogObject) lo).getValue() < min)
min = ((SimpleLogObject) lo).getValue();
}
}
//get the intervals to work with
double interval = max - min;
interval /= 50;
//holds how many instances occured within this interval
int counter;
//for each of the 50 intervals
for(int i = 1; i < 51; i++) {
//start with 0 count
counter = 0;
//for each data element
for(LogObject lo : data) {
//if its a simple log object its value can be obtained
if(lo instanceof SimpleLogObject) {
//if the value of the current object is between the interval we are searching for
if(((SimpleLogObject) lo).getValue() < ((interval * i) + min) && ((SimpleLogObject) lo).getValue() > ((interval * (i-1)) + min)) {
//increment the counter
counter++;
}
} else if(lo instanceof FunctionOfLogObject) {
if(((FunctionOfLogObject) lo).getValue() < ((interval * i) + min) && ((FunctionOfLogObject) lo).getValue() > ((interval * (i-1)) + min)) {
//increment the counter
counter++;
}
}
}
//if the counter is not 0, add the median of the interval we are looking for along with the counter to the series.
if(counter != 0)
series.add((((interval * i) + min) + ((interval * i - 1) + min))/2, counter*50);
}
graphData.addSeries(series);
}
}
return graphData;
}
// When the chart is clicked
@Override
public void chartMouseClicked(ChartMouseEvent cme) {
//if the lap breaker hasn't been activiates
if(lapBreakerActive < 0) {
// Create a static cursor that isnt cleared every time
ValueMarker marker = new ValueMarker(xCor);
//calculate the tag
String title = cme.getChart().getTitle().getText();
//create array of tags
String[] titleSplit = title.split(" vs ");
String[] tags = new String[titleSplit.length - 1];
for (int i = 0; i < titleSplit.length - 1; i++) {
tags[i] = titleSplit[titleSplit.length - 1] + "," + titleSplit[i];
}
for(String tag : tags) {
//add to the list of static markers
if(staticMarkers.get(new CategorizedValueMarker(tag, marker)) == null)
staticMarkers.put(new CategorizedValueMarker(tag, marker));
}
//draw markers
drawMarkers(titleToTag(), chartPanel.getChart().getXYPlot());
} else {
//if lapbreaker has just started
if(lapBreakerActive == 0) {
//get clicked position and set it as start
newLap.start = getRoundedTime(xCor);
//move to next task
lapBreakerActive++;
ValueMarker startMarker = new ValueMarker(newLap.start);
for(String tag : dataMap.tags) {
if(staticMarkers.get(new CategorizedValueMarker(tag, startMarker, "Start Lap" + newLap.lapNumber)) == null)
staticMarkers.put(new CategorizedValueMarker(tag, startMarker, "Start Lap" + newLap.lapNumber));
}
//draw markers
drawMarkers(titleToTag(), chartPanel.getChart().getXYPlot());
//if the start has already been defined
} else if(lapBreakerActive == 1) {
//define the next click as a stop
newLap.stop = getRoundedTime(xCor);
//hold the laps start and stop, so we have the value in case its lost
long oldStartTime = newLap.start;
long oldStopTime = newLap.stop;
ValueMarker stopMarker = new ValueMarker(newLap.stop);
//apply marker to all datasets.
for(String tag : dataMap.tags) {
//add to the list of static markers
if(staticMarkers.get(new CategorizedValueMarker(tag, stopMarker, "End Lap" + newLap.lapNumber)) == null)
staticMarkers.put(new CategorizedValueMarker(tag, stopMarker, "End Lap" + newLap.lapNumber));
}
//draw markers
drawMarkers(titleToTag(), chartPanel.getChart().getXYPlot());
//get the used lap numbers
ArrayList<Integer> usedLaps = new ArrayList<>();
for(Lap l : lapBreaker) {
usedLaps.add(l.lapNumber);
}
//create and run the dialog
LapDataDialog ldd = new LapDataDialog(this, true, newLap, usedLaps);
ldd.setVisible(true);
//while the dialog is running
while(ldd.isRunning()) {
try {
Thread.currentThread().wait(100);
} catch (InterruptedException ex) {
Logger.getLogger(DataAnalyzer.class.getName()).log(Level.SEVERE, null, ex);
}
}
if(!newLap.lapLabel.equals("!#@$LAPCANCELLED")) {
//remove old start and stop markers and add new ones with values from text box
ValueMarker startMarker = new ValueMarker(newLap.start);
stopMarker = new ValueMarker(newLap.stop);
for(String tag : dataMap.tags) {
staticMarkers.remove(getMarkerFromDomainValue(tag, oldStartTime));
staticMarkers.remove(getMarkerFromDomainValue(tag, oldStopTime));
if(staticMarkers.get(new CategorizedValueMarker(tag, startMarker, "Start Lap" + newLap.lapNumber)) == null)
staticMarkers.put(new CategorizedValueMarker(tag, startMarker, "Start Lap" + newLap.lapNumber));
if(staticMarkers.get(new CategorizedValueMarker(tag, stopMarker, "End Lap" + newLap.lapNumber)) == null)
staticMarkers.put(new CategorizedValueMarker(tag, stopMarker, "End Lap" + newLap.lapNumber));
}
//add that to the list of laps
lapBreaker.add(newLap);
//apply the lap data to the datasets
Lap.applyToDataset(dataMap, lapBreaker);
//reset the lapbreaker
lapBreakerActive = -1;
//reset the new lap
newLap = new Lap();
//fill lap list
fillDataList(dataMap.tags);
} else {
//delete previous markers
for(String tag : dataMap.tags) {
staticMarkers.remove(getMarkerFromDomainValue(tag, oldStartTime));
staticMarkers.remove(getMarkerFromDomainValue(tag, oldStopTime));
}
drawMarkers(titleToTag(), chartPanel.getChart().getXYPlot());
}
}
}
}
//when the mouse moves over the chart
@Override
public void chartMouseMoved(ChartMouseEvent cme) {
// The data area of where the chart is.
Rectangle2D dataArea = this.chartPanel.getScreenDataArea();
// Get the chart from the chart mouse event
JFreeChart chart = cme.getChart();
// Get the xy plot object from the chart
XYPlot plot = (XYPlot) chart.getPlot();
// Clear all markers
// This will be a problem for static markers we want to create
// Get the xAxis
ValueAxis xAxis = plot.getDomainAxis();
// Get the xCordinate from the xPositon of the mouse
xCor = xAxis.java2DToValue(cme.getTrigger().getX(), dataArea,
RectangleEdge.BOTTOM);
// Find the y cordinate from the plots data set given a x cordinate
yCor = DatasetUtilities.findYValue(plot.getDataset(), 0, xCor);
String[] titles = titleToTag();
int index = 0;
// String object that holds values for all the series on the plot.