Skip to content

Commit a0a3e49

Browse files
committed
#41 adding VStatistics
1 parent 6259e09 commit a0a3e49

3 files changed

Lines changed: 223 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT
3+
* All rights reserved. Use is subject to license terms. See LICENSE.TXT
4+
*/
5+
package org.epics.vtype;
6+
7+
/**
8+
* VStatistics implementation.
9+
*
10+
* @author carcassi
11+
*/
12+
class IVStatistics extends VStatistics {
13+
14+
private Double average;
15+
private Double stdDev;
16+
private Double min;
17+
private Double max;
18+
private Integer nSamples;
19+
20+
private final Alarm alarm;
21+
private final Time time;
22+
private final Display display;
23+
24+
IVStatistics(Double average, Double stdDev, Double min, Double max, Integer nSamples, Alarm alarm, Time time, Display display) {
25+
this.average = average;
26+
this.stdDev = stdDev;
27+
this.min = min;
28+
this.max = max;
29+
this.nSamples = nSamples;
30+
31+
this.alarm = alarm;
32+
this.time = time;
33+
this.display = display;
34+
}
35+
36+
@Override
37+
public Double getAverage() {
38+
return average;
39+
}
40+
41+
@Override
42+
public Double getStdDev() {
43+
return stdDev;
44+
}
45+
46+
@Override
47+
public Double getMin() {
48+
return min;
49+
}
50+
51+
@Override
52+
public Double getMax() {
53+
return max;
54+
}
55+
56+
@Override
57+
public Integer getNSamples() {
58+
return nSamples;
59+
}
60+
61+
@Override
62+
public Alarm getAlarm() {
63+
return alarm;
64+
}
65+
66+
@Override
67+
public Time getTime() {
68+
return time;
69+
}
70+
71+
@Override
72+
public Display getDisplay() {
73+
return display;
74+
}
75+
76+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT
3+
* All rights reserved. Use is subject to license terms. See LICENSE.TXT
4+
*/
5+
package org.epics.vtype;
6+
7+
/**
8+
* Basic type for statistical information of numeric types. The methods never
9+
* return null, even if no connection was ever made. One <b>must always look</b>
10+
* at the alarm severity to be able to correctly interpret the value.
11+
* <p>
12+
* This type can be used regardless of the method used to calculate the average
13+
* (instances: &Sigma;<i>x<sub>i</sub>/N</i>, time:
14+
* &Sigma;<i>x<sub>i</sub>&Delta;t<sub>i</sub>/&Delta;t</i>, time with linear
15+
* interpolation, exponential backoff, ...).
16+
* <p>
17+
* No integer statistics, since averages are not integer in general.
18+
*
19+
* @author carcassi
20+
*/
21+
public abstract class Statistics extends VType implements AlarmProvider, TimeProvider, DisplayProvider {
22+
23+
/**
24+
* The average. Never null.
25+
*
26+
* @return the average
27+
*/
28+
public abstract Double getAverage();
29+
30+
/**
31+
* The standard deviation. Never null.
32+
*
33+
* @return the standard deviation
34+
*/
35+
public abstract Double getStdDev();
36+
37+
/**
38+
* The minimum value.
39+
*
40+
* @return the minimum
41+
*/
42+
public abstract Double getMin();
43+
44+
/**
45+
* The maximum value.
46+
*
47+
* @return the maximum
48+
*/
49+
public abstract Double getMax();
50+
51+
/**
52+
* The number of samples.
53+
*
54+
* @return the number of samples
55+
*/
56+
public abstract Integer getNSamples();
57+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* Copyright (C) 2010-18 diirt developers. See COPYRIGHT.TXT
3+
* All rights reserved. Use is subject to license terms. See LICENSE.TXT
4+
*/
5+
package org.epics.vtype;
6+
7+
import java.util.Objects;
8+
9+
/**
10+
* Statistics for double with alarm, timestamp and display information.
11+
*
12+
* @author carcassi
13+
*/
14+
public abstract class VStatistics extends Statistics {
15+
16+
/**
17+
* Creates a new VStatistics.
18+
*
19+
* @param average average
20+
* @param stdDev standard deviation
21+
* @param min minimum
22+
* @param max maximum
23+
* @param nSamples number of samples
24+
* @param alarm the alarm
25+
* @param time the time
26+
* @param display the display
27+
* @return the new value
28+
*/
29+
public static VStatistics of(final double average, final double stdDev,
30+
final double min, final double max, final int nSamples, final Alarm alarm,
31+
final Time time, final Display display) {
32+
return new IVStatistics(average, stdDev, min, max, nSamples, alarm, time, display);
33+
}
34+
35+
@Override
36+
public final String toString() {
37+
StringBuilder builder = new StringBuilder();
38+
Class type = typeOf(this);
39+
builder.append(type.getSimpleName())
40+
.append('[')
41+
.append("max:" + getMax())
42+
.append(", min:" + getMin())
43+
.append(", mean:" + getAverage())
44+
.append(", std:" + getStdDev())
45+
.append(", #samples" + getNSamples())
46+
.append(", ")
47+
.append(getAlarm())
48+
.append(", ")
49+
.append(getTime())
50+
.append(']');
51+
return builder.toString();
52+
}
53+
54+
@Override
55+
public final boolean equals(Object obj) {
56+
if (this == obj) {
57+
return true;
58+
}
59+
60+
if (obj instanceof VStatistics) {
61+
VStatistics other = (VStatistics) obj;
62+
63+
return getClass().equals(other.getClass()) &&
64+
getMax().equals(other.getMax()) &&
65+
getMin().equals(other.getMin()) &&
66+
getAverage().equals(other.getAverage()) &&
67+
getStdDev().equals(other.getStdDev()) &&
68+
getNSamples().equals(other.getNSamples()) &&
69+
getAlarm().equals(other.getAlarm()) &&
70+
getTime().equals(other.getTime()) &&
71+
getDisplay().equals(other.getDisplay());
72+
}
73+
74+
return false;
75+
}
76+
77+
@Override
78+
public final int hashCode() {
79+
int hash = 7;
80+
hash = 23 * hash + Objects.hashCode(getMax());
81+
hash = 23 * hash + Objects.hashCode(getMin());
82+
hash = 23 * hash + Objects.hashCode(getAverage());
83+
hash = 23 * hash + Objects.hashCode(getStdDev());
84+
hash = 23 * hash + Objects.hashCode(getNSamples());
85+
hash = 23 * hash + Objects.hashCode(getAlarm());
86+
hash = 23 * hash + Objects.hashCode(getTime());
87+
hash = 23 * hash + Objects.hashCode(getDisplay());
88+
return hash;
89+
}
90+
}

0 commit comments

Comments
 (0)