use of com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel in project ma-modules-public by infiniteautomation.
the class PointValueRollupCalculator method generateStream.
@Override
protected void generateStream(DateTime from, DateTime to, CSVPojoWriter<PointValueTimeModel> writer) {
DataValue startValue = this.getStartValue(vo.getId());
BucketCalculator bc = this.getBucketCalculator(from, to);
final AbstractDataQuantizer quantizer = createQuantizer(vo, startValue, bc, writer, false, true);
this.calculate(quantizer, vo.getId(), from, to);
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel in project ma-modules-public by infiniteautomation.
the class IdPointValueRollupCalculator method generateStream.
/* (non-Javadoc)
* @see com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.AbstractPointValueRollupCalculator#generateStream(org.joda.time.DateTime, org.joda.time.DateTime, com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter)
*/
@Override
protected void generateStream(DateTime from, DateTime to, CSVPojoWriter<PointValueTimeModel> writer) {
BucketCalculator bc = this.getBucketCalculator(from, to);
IdPointValueStatisticsQuantizerCsvCallback callback = new IdPointValueStatisticsQuantizerCsvCallback(writer.getWriter(), this.voMap, this.useRendered, this.unitConversion, this.rollup, this.dateTimeFormat, timezone);
Iterator<Integer> it = this.voMap.keySet().iterator();
ParentDataQuantizer quantizer = new ParentDataQuantizer(bc, callback);
while (it.hasNext()) {
DataPointVO vo = this.voMap.get(it.next());
DataValue startValue = this.getStartValue(vo.getId());
if (vo.getPointLocator().getDataTypeId() == DataTypes.NUMERIC) {
quantizer.startQuantizer(vo.getId(), startValue, new AnalogStatisticsChildQuantizer(vo.getId(), quantizer));
} else {
quantizer.startQuantizer(vo.getId(), startValue, new ValueChangeCounterChildQuantizer(vo.getId(), quantizer));
}
}
this.calculate(quantizer, from, to);
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel in project ma-modules-public by infiniteautomation.
the class IdPointValueTimeLatestPointValueFacadeStream method streamData.
/* (non-Javadoc)
* @see com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream#streamData(com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter)
*/
@Override
public void streamData(CSVPojoWriter<PointValueTimeModel> writer) throws IOException {
IdPointValueTimeCsvStreamCallback callback = new IdPointValueTimeCsvStreamCallback(writer.getWriter(), pointMap, useRendered, unitConversion, null, dateTimeFormat, timezone);
// Sadly in this scenario we must collect all the data and then order it
List<IdPointValueTime> ipvts = new ArrayList<IdPointValueTime>();
Iterator<Integer> it = this.pointMap.keySet().iterator();
while (it.hasNext()) {
DataPointVO vo = this.pointMap.get(it.next());
PointValueFacade pointValueFacade = new PointValueFacade(vo.getId(), useCache);
List<PointValueTime> pvts = pointValueFacade.getLatestPointValues(limit);
for (PointValueTime pvt : pvts) ipvts.add(new IdPointValueTime(vo.getId(), pvt.getValue(), pvt.getTime()));
}
// Sort it all
Collections.sort(ipvts, new Comparator<IdPointValueTime>() {
@Override
public int compare(IdPointValueTime o1, IdPointValueTime o2) {
return Long.compare(o1.getTime(), o2.getTime());
}
});
for (int i = 0; i < ipvts.size(); i++) callback.row(ipvts.get(i), i);
callback.finish();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel in project ma-modules-public by infiniteautomation.
the class PointValueRestController method getLatestPointValuesForDataSourceAsSingleArray.
/**
* Get the latest point values a set of points return as map of xid to array of values
*
* @param xid
* @param limit
* @return
*/
@ApiOperation(value = "Get Latest Point Values for all points on a data source directly from the Runtime Manager, this makes Cached and Intra-Interval data available.", notes = "Default limit 100, time descending order, Default to return cached data. Returns as single time ordered array.")
@RequestMapping(method = RequestMethod.GET, value = "/{dataSourceXid}/latest-data-source-single-array", produces = { "application/json", "text/csv" })
public ResponseEntity<QueryArrayStream<PointValueTimeModel>> getLatestPointValuesForDataSourceAsSingleArray(HttpServletRequest request, @ApiParam(value = "Data source xid", required = true, allowMultiple = false) @PathVariable String dataSourceXid, @ApiParam(value = "Return rendered value as String", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean useRendered, @ApiParam(value = "Return converted value using displayed unit", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean unitConversion, @ApiParam(value = "Limit results", allowMultiple = false, defaultValue = "100") @RequestParam(value = "limit", defaultValue = "100") int limit, @ApiParam(value = "Return cached data?", allowMultiple = false, defaultValue = "true") @RequestParam(value = "useCache", defaultValue = "true") boolean useCache, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used", required = false, allowMultiple = false) @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat, @ApiParam(value = "Time zone of output, used if formatted times are returned", required = false, allowMultiple = false) @RequestParam(value = "timezone", required = false) String timezone) {
RestProcessResult<QueryArrayStream<PointValueTimeModel>> result = new RestProcessResult<QueryArrayStream<PointValueTimeModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataSourceVO<?> ds = DataSourceDao.instance.getByXid(dataSourceXid);
if (ds == null)
throw new NotFoundRestException();
if (dateTimeFormat != null) {
try {
DateTimeFormatter.ofPattern(dateTimeFormat);
} catch (IllegalArgumentException e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalidValue", "dateTimeFormat");
throw new ValidationFailedRestException(vr);
}
}
if (timezone != null) {
try {
ZoneId.of(timezone);
} catch (Exception e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalidValue", "timezone");
throw new ValidationFailedRestException(vr);
}
}
List<DataPointVO> points = DataPointDao.instance.getDataPointsForDataSourceStart(ds.getId());
Map<Integer, DataPointVO> pointIdMap = new HashMap<Integer, DataPointVO>(points.size());
for (DataPointVO vo : points) {
if (Permissions.hasDataPointReadPermission(user, vo))
pointIdMap.put(vo.getId(), vo);
else {
// Abort, invalid permissions
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
// Do we have any valid points?
if (pointIdMap.size() == 0) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
try {
IdPointValueTimeLatestPointValueFacadeStream pvtDatabaseStream = new IdPointValueTimeLatestPointValueFacadeStream(pointIdMap, useRendered, unitConversion, limit, useCache, dateTimeFormat, timezone);
return result.createResponseEntity(pvtDatabaseStream);
} catch (PermissionException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} else {
return result.createResponseEntity();
}
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel in project ma-modules-public by infiniteautomation.
the class PointValueRestController method latestPointValuesForMultiplePointsAsSingleArray.
private ResponseEntity<QueryArrayStream<PointValueTimeModel>> latestPointValuesForMultiplePointsAsSingleArray(HttpServletRequest request, String[] xids, boolean useRendered, boolean unitConversion, int limit, boolean useCache, String dateTimeFormat, String timezone) {
RestProcessResult<QueryArrayStream<PointValueTimeModel>> result = new RestProcessResult<QueryArrayStream<PointValueTimeModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (dateTimeFormat != null) {
try {
DateTimeFormatter.ofPattern(dateTimeFormat);
} catch (IllegalArgumentException e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalid", "dateTimeFormat");
throw new ValidationFailedRestException(vr);
}
}
if (timezone != null) {
try {
ZoneId.of(timezone);
} catch (Exception e) {
RestValidationResult vr = new RestValidationResult();
vr.addError("validate.invalidValue", "timezone");
throw new ValidationFailedRestException(vr);
}
}
Map<Integer, DataPointVO> pointIdMap = new HashMap<Integer, DataPointVO>(xids.length);
DataPointVO vo;
for (String xid : xids) {
vo = DataPointDao.instance.getByXid(xid);
if (vo != null) {
if (Permissions.hasDataPointReadPermission(user, vo))
pointIdMap.put(vo.getId(), vo);
else {
// Abort, invalid permissions
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
}
// Do we have any valid points?
if (pointIdMap.size() == 0) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
try {
IdPointValueTimeLatestPointValueFacadeStream pvtDatabaseStream = new IdPointValueTimeLatestPointValueFacadeStream(pointIdMap, useRendered, unitConversion, limit, useCache, dateTimeFormat, timezone);
return result.createResponseEntity(pvtDatabaseStream);
} catch (PermissionException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} else {
return result.createResponseEntity();
}
}
Aggregations