Search in sources :

Example 31 with PointValueTime

use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-modules-public by infiniteautomation.

the class InternalDataSourceRT method forcePointRead.

@Override
public void forcePointRead(DataPointRT dataPoint) {
    InternalPointLocatorRT locator = dataPoint.getPointLocator();
    ValueMonitor<?> m = Common.MONITORED_VALUES.getValueMonitor(locator.getPointLocatorVO().getMonitorId());
    if (m != null) {
        if (m instanceof IntegerMonitor)
            dataPoint.updatePointValue(new PointValueTime((double) ((IntegerMonitor) m).getValue(), Common.timer.currentTimeMillis()));
        else if (m instanceof LongMonitor)
            dataPoint.updatePointValue(new PointValueTime((double) ((LongMonitor) m).getValue(), Common.timer.currentTimeMillis()));
        else if (m instanceof DoubleMonitor)
            dataPoint.updatePointValue(new PointValueTime((double) ((DoubleMonitor) m).getValue(), Common.timer.currentTimeMillis()));
        else if (m instanceof AtomicIntegerMonitor)
            dataPoint.updatePointValue(new PointValueTime((double) ((AtomicIntegerMonitor) m).getValue(), Common.timer.currentTimeMillis()));
    }
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) LongMonitor(com.infiniteautomation.mango.monitor.LongMonitor) AtomicIntegerMonitor(com.infiniteautomation.mango.monitor.AtomicIntegerMonitor) AtomicIntegerMonitor(com.infiniteautomation.mango.monitor.AtomicIntegerMonitor) IntegerMonitor(com.infiniteautomation.mango.monitor.IntegerMonitor) DoubleMonitor(com.infiniteautomation.mango.monitor.DoubleMonitor)

Example 32 with PointValueTime

use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-core-public by infiniteautomation.

the class ChartExportServlet method exportExcel.

/**
 * Do the export as Excel XLSX File
 * @param response
 * @param from
 * @param to
 * @param def
 * @param user
 * @throws IOException
 */
private void exportExcel(HttpServletResponse response, long from, long to, DataExportDefinition def, User user) throws IOException {
    DataPointDao dataPointDao = DataPointDao.instance;
    PointValueDao pointValueDao = Common.databaseProxy.newPointValueDao();
    // Stream the content.
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    final List<PointValueEmporter> sheetEmporters = new ArrayList<PointValueEmporter>();
    final AtomicInteger sheetIndex = new AtomicInteger();
    sheetEmporters.add(new PointValueEmporter(Common.translate("emport.pointValues") + " " + sheetIndex.get()));
    final SpreadsheetEmporter emporter = new SpreadsheetEmporter(FileType.XLSX);
    BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
    emporter.prepareExport(bos);
    emporter.prepareSheetExport(sheetEmporters.get(0));
    final ExportDataValue edv = new ExportDataValue();
    MappedRowCallback<PointValueTime> callback = new MappedRowCallback<PointValueTime>() {

        @Override
        public void row(PointValueTime pvt, int rowIndex) {
            edv.setValue(pvt.getValue());
            edv.setTime(pvt.getTime());
            if (pvt instanceof AnnotatedPointValueTime)
                edv.setAnnotation(((AnnotatedPointValueTime) pvt).getSourceMessage());
            else
                edv.setAnnotation(null);
            sheetEmporters.get(sheetIndex.get()).exportRow(edv);
            if (sheetEmporters.get(sheetIndex.get()).getRowsAdded() >= emporter.getMaxRowsPerSheet()) {
                ExportPointInfo info = sheetEmporters.get(sheetIndex.get()).getPointInfo();
                sheetIndex.incrementAndGet();
                PointValueEmporter sheetEmporter = new PointValueEmporter(Common.translate("emport.pointValues") + " " + sheetIndex.get());
                sheetEmporter.setPointInfo(info);
                sheetEmporters.add(sheetEmporter);
                emporter.prepareSheetExport(sheetEmporters.get(sheetIndex.get()));
            }
        }
    };
    for (int pointId : def.getPointIds()) {
        DataPointVO dp = dataPointDao.getDataPoint(pointId, false);
        if (Permissions.hasDataPointReadPermission(user, dp)) {
            ExportPointInfo pointInfo = new ExportPointInfo();
            pointInfo.setXid(dp.getXid());
            pointInfo.setPointName(dp.getName());
            pointInfo.setDeviceName(dp.getDeviceName());
            pointInfo.setTextRenderer(dp.getTextRenderer());
            sheetEmporters.get(sheetIndex.get()).setPointInfo(pointInfo);
            pointValueDao.getPointValuesBetween(pointId, from, to, callback);
        }
    }
    emporter.finishExport();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) ExportDataValue(com.serotonin.m2m2.vo.export.ExportDataValue) ArrayList(java.util.ArrayList) ExportPointInfo(com.serotonin.m2m2.vo.export.ExportPointInfo) SpreadsheetEmporter(com.serotonin.m2m2.vo.emport.SpreadsheetEmporter) PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MappedRowCallback(com.serotonin.db.MappedRowCallback) PointValueEmporter(com.serotonin.m2m2.rt.dataImage.PointValueEmporter) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) BufferedOutputStream(java.io.BufferedOutputStream)

Example 33 with PointValueTime

use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-core-public by infiniteautomation.

the class StatisticsChartRenderer method addDataToModel.

@Override
public void addDataToModel(Map<String, Object> model, DataPointVO point) {
    long startTime = getStartTime();
    long endTime = startTime + getDuration();
    PointValueFacade pointValueFacade = new PointValueFacade(point.getId());
    List<PointValueTime> values = pointValueFacade.getPointValuesBetween(startTime, endTime);
    PointValueTime startVT = null;
    if (!values.isEmpty()) {
        startVT = pointValueFacade.getPointValueBefore(startTime);
    }
    // Generate statistics on the values.
    int dataTypeId = point.getPointLocator().getDataTypeId();
    if (values.size() > 0) {
        if (dataTypeId == DataTypes.BINARY || dataTypeId == DataTypes.MULTISTATE) {
            // Runtime stats
            StartsAndRuntimeList stats = new StartsAndRuntimeList(startTime, endTime, startVT, values);
            model.put("start", startVT != null ? startTime : stats.getFirstTime());
            model.put("end", endTime);
            model.put("startsAndRuntimes", stats.getData());
        } else if (dataTypeId == DataTypes.NUMERIC) {
            AnalogStatistics stats = new AnalogStatistics(startTime, endTime, startVT, values);
            model.put("start", startVT != null ? startTime : stats.getFirstTime());
            model.put("end", endTime);
            model.put("minimum", stats.getMinimumValue());
            model.put("minTime", stats.getMinimumTime());
            model.put("maximum", stats.getMaximumValue());
            model.put("maxTime", stats.getMaximumTime());
            model.put("average", stats.getAverage());
            if (includeSum)
                model.put("sum", stats.getSum());
            model.put("count", stats.getCount());
            model.put("noData", stats.getAverage() == null);
            model.put("integral", stats.getIntegral());
        } else if (dataTypeId == DataTypes.ALPHANUMERIC) {
            ValueChangeCounter stats = new ValueChangeCounter(startTime, endTime, startVT, values);
            model.put("changeCount", stats.getChanges());
        }
    }
    model.put("logEntries", values.size());
}
Also used : PointValueFacade(com.serotonin.m2m2.rt.dataImage.PointValueFacade) StartsAndRuntimeList(com.serotonin.m2m2.view.stats.StartsAndRuntimeList) ValueChangeCounter(com.serotonin.m2m2.view.stats.ValueChangeCounter) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnalogStatistics(com.serotonin.m2m2.view.stats.AnalogStatistics)

Example 34 with PointValueTime

use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-core-public by infiniteautomation.

the class Interpolation method interpolate.

private static PointValueTime interpolate(long time, PointValueTime from, PointValueTime to) {
    if (from != null && time == from.getTime())
        return from;
    if (to != null && time == to.getTime())
        return to;
    if (from == null && to == null)
        return new PointValueTime(0, time);
    if (from == null)
        return new PointValueTime(to.getDoubleValue(), time);
    if (to == null)
        return new PointValueTime(from.getDoubleValue(), time);
    double valueDiff = to.getDoubleValue() - from.getDoubleValue();
    long timeDiff = to.getTime() - from.getTime();
    double value = ((double) time - from.getTime()) / timeDiff * valueDiff + from.getDoubleValue();
    return new PointValueTime(value, time);
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime)

Example 35 with PointValueTime

use of com.serotonin.m2m2.rt.dataImage.PointValueTime in project ma-core-public by infiniteautomation.

the class Interpolation method updateYear.

public static List<PointValueTime> updateYear(List<PointValueTime> pvts, int year) {
    List<PointValueTime> result = new ArrayList<PointValueTime>(pvts.size());
    MutableDateTime mdt = new MutableDateTime();
    for (PointValueTime pvt : pvts) {
        mdt.setMillis(pvt.getTime());
        mdt.setYear(year);
        result.add(new PointValueTime(pvt.getValue(), mdt.getMillis()));
    }
    return result;
}
Also used : PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) ArrayList(java.util.ArrayList) MutableDateTime(org.joda.time.MutableDateTime)

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