diff options
| author | Keith Packard <keithp@keithp.com> | 2017-05-26 00:20:17 -0700 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2017-05-26 00:20:17 -0700 | 
| commit | 2e82051a6aaaccf1e8a242f9c8141e4167e652d2 (patch) | |
| tree | c0f9642d04f28850c9d60a07266f36c685452fef /altoslib/AltosTimeSeries.java | |
| parent | 222158581887b5f9e8b9843d14321c313fa023fa (diff) | |
altoslib,altosuilib,altosui: Get stats and replay working again.
Stats are really easy with all of the data in memory.
Replay takes a special thread to run the data and dump it into a
single state.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosTimeSeries.java')
| -rw-r--r-- | altoslib/AltosTimeSeries.java | 56 | 
1 files changed, 56 insertions, 0 deletions
| diff --git a/altoslib/AltosTimeSeries.java b/altoslib/AltosTimeSeries.java index 30b24d82..142c30ef 100644 --- a/altoslib/AltosTimeSeries.java +++ b/altoslib/AltosTimeSeries.java @@ -85,6 +85,16 @@ public class AltosTimeSeries implements Iterable<AltosTimeValue> {  		return values.get(after).value;  	} +	public double time_of(double value) { +		double	last = AltosLib.MISSING; +		for (AltosTimeValue v : values) { +			if (v.value >= value) +				return v.time; +			last = v.time; +		} +		return last; +	} +  	public int size() {  		return values.size();  	} @@ -102,6 +112,16 @@ public class AltosTimeSeries implements Iterable<AltosTimeValue> {  		return max;  	} +	public double max(double start_time, double end_time) { +		double max = AltosLib.MISSING; +		for (AltosTimeValue tv : values) { +			if (start_time <= tv.time && tv.time <= end_time) +				if (max == AltosLib.MISSING || tv.value > max) +					max = tv.value; +		} +		return max; +	} +  	public double min() {  		double min = AltosLib.MISSING;  		for (AltosTimeValue tv : values) { @@ -111,6 +131,42 @@ public class AltosTimeSeries implements Iterable<AltosTimeValue> {  		return min;  	} +	public double min(double start_time, double end_time) { +		double min = AltosLib.MISSING; +		for (AltosTimeValue tv : values) { +			if (start_time <= tv.time && tv.time <= end_time) +				if (min == AltosLib.MISSING || tv.value < min) +					min = tv.value; +		} +		return min; +	} + +	public double average() { +		double total = 0; +		int count = 0; +		for (AltosTimeValue tv : values) { +			total += tv.value; +			count++; +		} +		if (count == 0) +			return AltosLib.MISSING; +		return total / count; +	} + +	public double average(double start_time, double end_time) { +		double total = 0; +		int count = 0; +		for (AltosTimeValue tv : values) { +			if (start_time <= tv.time && tv.time <= end_time) { +				total += tv.value; +				count++; +			} +		} +		if (count == 0) +			return AltosLib.MISSING; +		return total / count; +	} +  	public AltosTimeSeries integrate(AltosTimeSeries integral) {  		double	value = 0.0;  		double	pvalue = 0.0; | 
