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()));
}
}
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();
}
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());
}
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);
}
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;
}
Aggregations