use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-core-public by infiniteautomation.
the class AnalogStatisticsTest method testIntegralNoEndValue.
// Random tests
@Test
public void testIntegralNoEndValue() {
long periodStart = 0;
// 30 Days in ms
long periodEnd = 30l * 24l * 60l * 60l * 1000l;
AnalogStatistics s;
List<PointValueTime> values;
long pointChangeTime;
double pointChangeValue;
Double pointStartValue = 0D;
// Expected Values
Double expectedIntegral;
// Test a series of values
values = new ArrayList<PointValueTime>();
pointStartValue = 100d;
pointChangeTime = 25l * 24l * 60l * 60l * 1000l;
pointChangeValue = 200d;
long dayInMs = 24l * 60l * 60l * 1000l;
long time = dayInMs;
while (time < pointChangeTime) {
values.add(new PointValueTime(pointStartValue, time));
time += dayInMs;
}
values.add(new PointValueTime(pointChangeValue, pointChangeTime));
s = new AnalogStatistics(periodStart, periodEnd, (Double) pointStartValue, values);
expectedIntegral = ((new Double(pointChangeTime) - new Double(periodStart)) * new Double(pointStartValue)) / 1000D;
expectedIntegral += (pointChangeValue * (new Double(periodEnd) - new Double(pointChangeTime))) / 1000D;
assertEquals(expectedIntegral, s.getIntegral(), 0.001D);
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-core-public by infiniteautomation.
the class AnalogStatisticsTest method getMidpointData.
/**
* One value set to 200 at 500ms in
*
* @return
*/
protected List<PointValueTime> getMidpointData() {
List<PointValueTime> values = new ArrayList<PointValueTime>();
values = new ArrayList<PointValueTime>();
values.add(new PointValueTime(200.0, 500));
return values;
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-core-public by infiniteautomation.
the class MockPointValueDao method getLatestPointValues.
/* (non-Javadoc)
* @see com.serotonin.m2m2.db.dao.PointValueDao#getLatestPointValues(int, int)
*/
@Override
public List<PointValueTime> getLatestPointValues(int pointId, int limit) {
List<PointValueTime> pvts = new ArrayList<>();
List<PointValueTime> existing = data.get(pointId);
if (existing != null) {
for (PointValueTime pvt : existing) {
pvts.add(pvt);
if (pvts.size() >= limit)
break;
}
}
return pvts;
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-core-public by infiniteautomation.
the class MockPointValueDao method savePointValueSync.
/* (non-Javadoc)
* @see com.serotonin.m2m2.db.dao.PointValueDao#savePointValueSync(int, com.serotonin.m2m2.rt.dataImage.PointValueTime, com.serotonin.m2m2.rt.dataImage.SetPointSource)
*/
@Override
public PointValueTime savePointValueSync(int pointId, PointValueTime pointValue, SetPointSource source) {
List<PointValueTime> pvts = data.get(pointId);
if (pvts == null) {
pvts = new ArrayList<>();
data.put(pointId, pvts);
}
PointValueTime newPvt = null;
if (source != null)
newPvt = new AnnotatedPointValueTime(pointValue.getValue(), pointValue.getTime(), source.getSetPointSourceMessage());
else
newPvt = new PointValueTime(pointValue.getValue(), pointValue.getTime());
pvts.add(newPvt);
// Keep in time order?
Collections.sort(pvts);
return newPvt;
}
use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-core-public by infiniteautomation.
the class MockPointValueDao method getPointValues.
/* (non-Javadoc)
* @see com.serotonin.m2m2.db.dao.PointValueDao#getPointValues(int, long)
*/
@Override
public List<PointValueTime> getPointValues(int pointId, long since) {
List<PointValueTime> pvts = new ArrayList<>();
List<PointValueTime> existing = data.get(pointId);
if (existing != null) {
for (PointValueTime pvt : existing) {
if (pvt.getTime() >= since)
pvts.add(pvt);
}
}
return pvts;
}
Aggregations