use of com.serotonin.m2m2.rt.dataImage.types.DataValue in project ma-core-public by infiniteautomation.
the class EventHandlersDwr method createSetValueContent.
@DwrPermission(user = true)
public String createSetValueContent(int pointId, String valueStr, String idSuffix) {
DataPointVO pointVO = DataPointDao.instance.getDataPoint(pointId);
Permissions.ensureDataSourcePermission(Common.getHttpUser(), pointVO.getDataSourceId());
DataValue value = DataValue.stringToValue(valueStr, pointVO.getPointLocator().getDataTypeId());
Map<String, Object> model = new HashMap<String, Object>();
model.put("point", pointVO);
model.put("idSuffix", idSuffix);
model.put("text", pointVO.getTextRenderer().getText(value, TextRenderer.HINT_FULL));
model.put("rawText", pointVO.getTextRenderer().getText(value, TextRenderer.HINT_RAW));
model.put("valueStr", valueStr);
String snippet = pointVO.getTextRenderer().getSetPointSnippetFilename();
return generateContent(WebContextFactory.get().getHttpServletRequest(), snippet, model);
}
use of com.serotonin.m2m2.rt.dataImage.types.DataValue in project ma-core-public by infiniteautomation.
the class DataPointRT method scheduleTimeoutImpl.
public void scheduleTimeoutImpl(long fireTime) {
synchronized (intervalLoggingLock) {
DataValue value;
if (vo.getLoggingType() == DataPointVO.LoggingTypes.INTERVAL) {
if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.INSTANT)
value = PointValueTime.getValue(pointValue);
else if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.MAXIMUM || vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.MINIMUM) {
value = PointValueTime.getValue(intervalValue);
intervalValue = pointValue;
} else if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.AVERAGE) {
// If we don't have enough averaging values then we will bail and wait for more
if (vo.isOverrideIntervalLoggingSamples() && (averagingValues.size() != vo.getIntervalLoggingSampleWindowSize()))
return;
if (vo.getPointLocator().getDataTypeId() == DataTypes.MULTISTATE) {
StartsAndRuntimeList stats = new StartsAndRuntimeList(intervalStartTime, fireTime, intervalValue, averagingValues);
double maxProportion = -1;
Object valueAtMax = null;
for (StartsAndRuntime sar : stats.getData()) {
if (sar.getProportion() > maxProportion) {
maxProportion = sar.getProportion();
valueAtMax = sar.getValue();
}
}
if (valueAtMax != null)
value = new MultistateValue(DataValue.objectToValue(valueAtMax).getIntegerValue());
else
value = null;
} else {
AnalogStatistics stats = new AnalogStatistics(intervalStartTime, fireTime, intervalValue, averagingValues);
if (stats.getAverage() == null || (stats.getAverage() == Double.NaN && stats.getCount() == 0))
value = null;
else if (vo.getPointLocator().getDataTypeId() == DataTypes.NUMERIC)
value = new NumericValue(stats.getAverage());
else if (vo.getPointLocator().getDataTypeId() == DataTypes.BINARY)
value = new BinaryValue(stats.getAverage() >= 0.5);
else
throw new ShouldNeverHappenException("Unsupported average interval logging data type.");
}
// Compute the center point of our average data, starting by finding where our period started
long sampleWindowStartTime;
if (vo.isOverrideIntervalLoggingSamples())
sampleWindowStartTime = averagingValues.get(0).getTime();
else
sampleWindowStartTime = intervalStartTime;
intervalStartTime = fireTime;
// Fix to simulate center tapped filter (un-shift the average)
fireTime = sampleWindowStartTime + (fireTime - sampleWindowStartTime) / 2L;
intervalValue = pointValue;
if (!vo.isOverrideIntervalLoggingSamples())
averagingValues.clear();
} else
throw new ShouldNeverHappenException("Unknown interval logging type: " + vo.getIntervalLoggingType());
} else if (vo.getLoggingType() == DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL) {
// Okay, no changes rescheduled the timer. Get a value, reschedule
if (pointValue != null) {
value = pointValue.getValue();
if (vo.getPointLocator().getDataTypeId() == DataTypes.NUMERIC)
toleranceOrigin = pointValue.getDoubleValue();
} else
value = null;
rescheduleChangeInterval(Common.getMillis(vo.getIntervalLoggingPeriodType(), vo.getIntervalLoggingPeriod()));
} else
value = null;
if (value != null) {
PointValueTime newValue = new PointValueTime(value, fireTime);
valueCache.logPointValueAsync(newValue, null);
// Fire logged Events
fireEvents(null, newValue, null, false, false, true, false, false);
}
}
}
use of com.serotonin.m2m2.rt.dataImage.types.DataValue in project ma-core-public by infiniteautomation.
the class PointValueEmporter method exportRow.
public void exportRow(ExportDataValue edv) {
int cellNum = 0;
Cell cell;
Row row;
row = sheet.createRow(this.rowNum++);
// Set Point XID
cell = row.createCell(cellNum++);
cell.setCellValue(this.pointInfo.getXid());
// Set the Device Name
cell = row.createCell(cellNum++);
cell.setCellValue(this.pointInfo.getDeviceName());
// Set the Point Name
cell = row.createCell(cellNum++);
cell.setCellValue(this.pointInfo.getPointName());
// Time
cell = row.createCell(cellNum++);
cell.setCellValue(new DateTime(edv.getTime()).toDate());
cell.setCellStyle(dateStyle);
if (edv.getValue() != null) {
cell = row.createCell(cellNum++);
DataValue value = edv.getValue();
switch(value.getDataType()) {
case DataTypes.ALPHANUMERIC:
cell.setCellValue(value.getStringValue());
break;
case DataTypes.BINARY:
cell.setCellValue(value.getBooleanValue());
break;
case DataTypes.MULTISTATE:
cell.setCellValue(value.getIntegerValue());
break;
case DataTypes.NUMERIC:
cell.setCellValue(value.getDoubleValue());
break;
default:
}
// Set the text renderer value here
cell = row.createCell(cellNum++);
cell.setCellValue(this.pointInfo.getTextRenderer().getText(edv.getValue(), TextRenderer.HINT_FULL));
} else {
row.createCell(cellNum++);
// Do we need an empty cell?
row.createCell(cellNum++);
}
// Do we have an annotation
if (edv.getAnnotation() != null) {
cell = row.createCell(cellNum++);
cell.setCellValue(edv.getAnnotation().translate(Common.getTranslations()));
} else {
cell = row.createCell(cellNum++);
}
this.rowsAdded++;
}
use of com.serotonin.m2m2.rt.dataImage.types.DataValue in project ma-core-public by infiniteautomation.
the class PointValueDaoSQL method savePointValueImpl.
long savePointValueImpl(final int pointId, final PointValueTime pointValue, final SetPointSource source, boolean async) {
DataValue value = pointValue.getValue();
final int dataType = DataTypes.getDataType(value);
double dvalue = 0;
String svalue = null;
if (dataType == DataTypes.IMAGE) {
ImageValue imageValue = (ImageValue) value;
dvalue = imageValue.getType();
if (imageValue.isSaved())
svalue = Long.toString(imageValue.getId());
} else if (value.hasDoubleRepresentation())
dvalue = value.getDoubleValue();
else
svalue = value.getStringValue();
// Check if we need to create an annotation.
long id;
try {
if (svalue != null || source != null || dataType == DataTypes.IMAGE)
async = false;
id = savePointValue(pointId, dataType, dvalue, pointValue.getTime(), svalue, source, async);
} catch (ConcurrencyFailureException e) {
// Still failed to insert after all of the retries. Store the data
synchronized (UNSAVED_POINT_VALUES) {
UNSAVED_POINT_VALUES.add(new UnsavedPointValue(pointId, pointValue, source));
}
return -1;
}
// Check if we need to save an image
if (dataType == DataTypes.IMAGE) {
ImageValue imageValue = (ImageValue) value;
if (!imageValue.isSaved()) {
imageValue.setId(id);
File file = new File(Common.getFiledataPath(), imageValue.getFilename());
// Write the file.
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
StreamUtils.transfer(new ByteArrayInputStream(imageValue.getData()), out);
} catch (IOException e) {
// Rethrow as an RTE
throw new ImageSaveException(e);
} finally {
try {
if (out != null)
out.close();
} catch (IOException e) {
// no op
}
}
// Allow the data to be GC'ed
imageValue.setData(null);
}
}
clearUnsavedPointValues();
clearUnsavedPointUpdates();
return id;
}
use of com.serotonin.m2m2.rt.dataImage.types.DataValue in project ma-core-public by infiniteautomation.
the class PointValueDaoSQL method createDataValue.
DataValue createDataValue(ResultSet rs, int firstParameter) throws SQLException {
int dataType = rs.getInt(firstParameter);
DataValue value;
switch(dataType) {
case (DataTypes.NUMERIC):
value = new NumericValue(rs.getDouble(firstParameter + 1));
break;
case (DataTypes.BINARY):
value = new BinaryValue(rs.getDouble(firstParameter + 1) == 1);
break;
case (DataTypes.MULTISTATE):
value = new MultistateValue(rs.getInt(firstParameter + 1));
break;
case (DataTypes.ALPHANUMERIC):
String s = rs.getString(firstParameter + 2);
if (s == null)
s = rs.getString(firstParameter + 3);
value = new AlphanumericValue(s);
break;
case (DataTypes.IMAGE):
value = new ImageValue(Integer.parseInt(rs.getString(firstParameter + 2)), rs.getInt(firstParameter + 1));
break;
default:
value = null;
}
return value;
}
Aggregations