Search in sources :

Example 41 with PointValueTime

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);
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) Test(org.junit.Test)

Example 42 with PointValueTime

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;
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList)

Example 43 with PointValueTime

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;
}
Also used : IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList)

Example 44 with PointValueTime

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;
}
Also used : IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)

Example 45 with PointValueTime

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;
}
Also used : IdPointValueTime(com.serotonin.m2m2.rt.dataImage.IdPointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList)

Aggregations

PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)104 ArrayList (java.util.ArrayList)33 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)31 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)29 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)24 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)23 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)23 IOException (java.io.IOException)18 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)17 HashMap (java.util.HashMap)17 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)15 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)12 PointValueFacade (com.serotonin.m2m2.rt.dataImage.PointValueFacade)11 ScriptException (javax.script.ScriptException)10 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)9 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)9 LogStopWatch (com.serotonin.log.LogStopWatch)8 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)8 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)8 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)8