-
Notifications
You must be signed in to change notification settings - Fork 0
/
RunList.java
executable file
·156 lines (151 loc) · 3.92 KB
/
RunList.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import java.util.ArrayList;
import java.util.Collections;
import co2histograph.*;
public class RunList
{
String label;
ArrayList <HistData> allRuns;
MeanRun mean;
public RunList()
{
mean = new MeanRun();
allRuns = new ArrayList<HistData>();
}
public RunList(int initCapacity)
{
mean = new MeanRun();
allRuns = new ArrayList<HistData>(initCapacity);
}
/**
* Adds the given run to the this RunList.
*
* @param run the CO2Run to be added
* @return {<code>true} if this list changed as a result of the call
*/
public boolean add(HistData run)
{
boolean rAdd = allRuns.add(run);
if (rAdd==false)
return rAdd;
boolean mAdd = mean.include(run);
if (mAdd==false)
{
allRuns.remove(run);
return false;
}
return true;
}
public int size()
{
return allRuns.size();
}
public CommonData runAtIndex(int i)
{
CommonData c = new CommonData();
DataComparator comp = new DataComparator();
int timeLen = allRuns.get(0).size();
for(int j = 0; j<timeLen; j++)
{
comp.setIndex(j);
Collections.sort(allRuns, comp);
comp.incrementIndex();
c.nextPointFrom(allRuns.get(i));
}
return c;
}
public RunList runsBetweenIndex(int low, int high)
{
RunList cRuns = new RunList(high-low);
for(int i = low; i<high; i++)
{
cRuns.add(this.runAtIndex(i));
}
return cRuns;
}
public CommonData runAtPercentile(double p)
{
CommonData c = new CommonData();
DataComparator comp = new DataComparator();
int timeLen = allRuns.get(0).size();
for(int i = 0; i<timeLen; i++)
{
comp.setIndex(i);
Collections.sort(allRuns, comp);
comp.incrementIndex();
c.nextPointFrom(allRuns.get( (int)(allRuns.size()*p)) );
}
return c;
}
public CommonData[] manyRunAtPercentile(double[] p)
{
CommonData[] cRuns = new CommonData[p.length];
for(int k=0; k<p.length; k++)
cRuns[k]=new CommonData();
DataComparator comp = new DataComparator();
int timeLen = allRuns.get(0).size();
for(int i = 0; i<timeLen; i++)
{
Collections.sort(allRuns, comp);
comp.incrementIndex();
for(int j=0; j<p.length; j++)
{
cRuns[j].nextPointFrom(allRuns.get( (int)(allRuns.size()*p[j])) );
}
}
return cRuns;
}
public HistData get(int i)
{
HistData r = allRuns.get(i);
return r;
}
public MeanRun getMean()
{
return mean;
}
public ArrayList<HistData> getErroredRuns(double threshold)
{
ArrayList<HistData> errors = new ArrayList<HistData>(allRuns.size());
for(HistData h:allRuns)
{
h.setErrorThreshold((float)threshold);
if(h.countErrors()>0)
errors.add(h);
}
return errors;
}
public String getLabel(){
return label;
}
public void setLabel(String label){
label = label;
}
/**
* Inner class implements a comparator for the HistData objects which are
* held by this RunList
*/
private class DataComparator implements java.util.Comparator<HistData>
{
int i;
public DataComparator()
{
i=0;
}
public int compare(HistData o1, HistData o2)
{
return Float.compare(o1.getCO2(i),o2.getCO2(i));
}
public int getCurrentIndex()
{
return i;
}
public void incrementIndex()
{
i++;
}
public void setIndex(int newI)
{
i=newI;
}
}
}