| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.model.common.enums.DataTypeEnum; |
| | | import com.iailab.module.model.influxdb.pojo.InfluxModelResultLastBakSimPOJO; |
| | | import com.iailab.module.model.influxdb.pojo.InfluxModelResultLastSimPOJO; |
| | | import com.iailab.module.model.influxdb.pojo.InfluxModelResultPOJO; |
| | | import com.iailab.module.model.influxdb.pojo.InfluxModelResultSimPOJO; |
| | | import com.iailab.module.model.influxdb.service.InfluxDBService; |
| | | import com.iailab.module.model.influxdb.vo.InfluxModelResultVO; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemResultJsonEntity; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultJsonService; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultService; |
| | | import com.iailab.module.model.mdk.vo.DataValueVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | |
| | | public void savePredictValue(Map<String, List<DataValueVO>> predictValueMap, int t, String nIndex, Date predictTime) { |
| | | List<InfluxModelResultPOJO> importList = new ArrayList<>(); |
| | | List<InfluxModelResultPOJO> lastList = new ArrayList<>(); |
| | | List<InfluxModelResultPOJO> lastBakList = new ArrayList<>(); |
| | | List<MmItemResultJsonEntity> resultJsonList = new ArrayList<>(); |
| | | |
| | | for (Map.Entry<String, List<DataValueVO>> entry : predictValueMap.entrySet()) { |
| | |
| | | pojo.setValue(dataVo.getDataValue()); |
| | | pojo.setTimestamp(dataVo.getDataTime().toInstant()); |
| | | pojo.setOutPutId(entry.getKey()); |
| | | pojo.setType(DataTypeEnum.FLOAT.getCode()); |
| | | importList.add(pojo); |
| | | } |
| | | |
| | |
| | | pojo.setValue(dataVo.getDataValue()); |
| | | pojo.setTimestamp(dataVo.getDataTime().toInstant()); |
| | | pojo.setOutPutId(entry.getKey()); |
| | | pojo.setType(DataTypeEnum.FLOAT.getCode()); |
| | | lastList.add(pojo); |
| | | |
| | | InfluxModelResultLastBakSimPOJO bakSimPojo = new InfluxModelResultLastBakSimPOJO(); |
| | | bakSimPojo.setValue(dataVo.getDataValue()); |
| | | bakSimPojo.setTimestamp(dataVo.getDataTime().toInstant()); |
| | | bakSimPojo.setOutPutId(entry.getKey()); |
| | | lastBakList.add(bakSimPojo); |
| | | } |
| | | |
| | | MmItemResultJsonEntity resultJson = new MmItemResultJsonEntity(); |
| | |
| | | // double结果存入influxdb |
| | | influxDBService.asyncWriteModelResults(importList); |
| | | influxDBService.asyncWriteModelResults(lastList); |
| | | // t+l备份 |
| | | influxDBService.asyncWriteModelResults(lastBakList); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<DataValueVO> getPredictValueLast(String outputid, Date startTime, int mins) { |
| | | List<DataValueVO> result = new ArrayList<>(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(startTime); |
| | | calendar.add(Calendar.MINUTE, mins * -1); |
| | | Date startTimeNew = calendar.getTime(); |
| | | Date endTimeNew = new Date(); |
| | | InfluxModelResultPOJO pojo = new InfluxModelResultPOJO(); |
| | | pojo.setType(DataTypeEnum.FLOAT.getCode()); |
| | | pojo.setOutPutId(outputid); |
| | | List<InfluxModelResultVO> influxModelResultVOS = influxDBService.queryModelResults(pojo, startTimeNew, endTimeNew); |
| | | if (!CollectionUtils.isEmpty(influxModelResultVOS)) { |
| | | InfluxModelResultVO t = influxModelResultVOS.get(influxModelResultVOS.size() - 1); |
| | | DataValueVO dv = new DataValueVO(); |
| | | dv.setDataTime(Date.from(t.getTimestamp())); |
| | | dv.setDataValue(Double.valueOf(t.getValue().toString())); |
| | | result.add(dv); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat) { |
| | | List<Object[]> result = new ArrayList<>(); |
| | | InfluxModelResultPOJO pojo = new InfluxModelResultPOJO(); |
| | |
| | | }); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat, int decimalPlaces) { |
| | | List<Object[]> result = new ArrayList<>(); |
| | | InfluxModelResultPOJO pojo = new InfluxModelResultPOJO(); |
| | | pojo.setType(DataTypeEnum.FLOAT.getCode()); |
| | | pojo.setOutPutId(outputid); |
| | | List<InfluxModelResultVO> influxModelResultVOS = influxDBService.queryModelResults(pojo, startTime, endTime); |
| | | influxModelResultVOS.forEach(item -> { |
| | | Object[] dataItem = new Object[2]; |
| | | dataItem[0] = DateUtils.format(Date.from(item.getTimestamp()), timeFormat); |
| | | dataItem[1] = BigDecimal.valueOf(Double.valueOf(item.getValue().toString())).setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); |
| | | result.add(dataItem); |
| | | }); |
| | | return result; |
| | | } |
| | | } |