Browse Source

1、用能预测后端数据处理;

dev
mh 4 months ago
parent
commit
0023e82d89
  1. 6
      user-service/src/main/java/com/mh/user/mapper/DeviceInstallMapper.java
  2. 16
      user-service/src/main/java/com/mh/user/mapper/HistoryDataPreMapper.java
  3. 29
      user-service/src/main/java/com/mh/user/service/impl/HistoryDataPreServiceImpl.java

6
user-service/src/main/java/com/mh/user/mapper/DeviceInstallMapper.java

@ -19,8 +19,8 @@ public interface DeviceInstallMapper extends BaseMapper<DeviceInstallEntity> {
* 保存设备信息 * 保存设备信息
* @param deviceInstallEntity * @param deviceInstallEntity
*/ */
@Insert("insert into device_install(device_addr,device_name,device_type,data_com,ratio,baudrate,brand,model,building_id,building_name,installer,install_date,is_use) values (" + @Insert("insert into device_install(device_addr,device_name,device_type,data_com,ratio,baudrate,brand,model,building_id,building_name,installer,install_date,is_use,parity) values (" +
" #{deviceAddr},#{deviceName},#{deviceType},#{dataCom},#{ratio},#{baudRate},#{brand},#{model},#{buildingId},#{buildingName},#{installer},getDate(),#{use})") " #{deviceAddr},#{deviceName},#{deviceType},#{dataCom},#{ratio},#{baudRate},#{brand},#{model},#{buildingId},#{buildingName},#{installer},getDate(),#{use},#{parity})")
int saveDevice(DeviceInstallEntity deviceInstallEntity); int saveDevice(DeviceInstallEntity deviceInstallEntity);
/** /**
@ -160,7 +160,7 @@ public interface DeviceInstallMapper extends BaseMapper<DeviceInstallEntity> {
//根据通讯地址和设备类型查询对应的设备信息 //根据通讯地址和设备类型查询对应的设备信息
@ResultMap("rs") @ResultMap("rs")
@Select("select * from device_install where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId}") @Select("select top 1 * from device_install where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId}")
DeviceInstallEntity selectDevice(@Param("deviceAddr") String deviceAddr,@Param("deviceType") String deviceType,@Param("buildingId") String buildingId); DeviceInstallEntity selectDevice(@Param("deviceAddr") String deviceAddr,@Param("deviceType") String deviceType,@Param("buildingId") String buildingId);
//查询通讯编号是否存在 //查询通讯编号是否存在

16
user-service/src/main/java/com/mh/user/mapper/HistoryDataPreMapper.java

@ -130,13 +130,13 @@ public interface HistoryDataPreMapper extends BaseMapper<HistoryDataPre> {
@Select("<script>" + @Select("<script>" +
"SELECT " + "SELECT " +
" <choose>" + " <choose>" +
" <when test='type == \"1\"'>" + " <when test='type == \"2\"'>" +
" isnull(t.water_value_pre, 0) as cur_yes_data, " + " isnull(t.water_value_pre, 0) as cur_yes_data, " +
" isnull(t1.water_value, 0) as yes_data, " + " isnull(t1.water_value, 0) as yes_data, " +
" isnull(t1.water_value_pre, 0) as pre_yes_data, " + " isnull(t1.water_value_pre, 0) as pre_yes_data, " +
" CASE WHEN t1.water_value_pre > 0 THEN CONVERT(decimal(18, 2), ABS(isnull(t1.water_value_pre, 0) - isnull(t1.water_value, 0)) / t1.water_value_pre * 100) ELSE '0' END as error_data" + " CASE WHEN t1.water_value_pre > 0 THEN CONVERT(decimal(18, 2), ABS(isnull(t1.water_value_pre, 0) - isnull(t1.water_value, 0)) / t1.water_value_pre * 100) ELSE '0' END as error_data" +
" </when>" + " </when>" +
" <when test='type == \"2\"'>" + " <when test='type == \"1\"'>" +
" isnull(t.elect_value_pre, 0) as cur_yes_data, " + " isnull(t.elect_value_pre, 0) as cur_yes_data, " +
" isnull(t1.elect_value, 0) as yes_data, " + " isnull(t1.elect_value, 0) as yes_data, " +
" isnull(t1.elect_value_pre, 0) as pre_yes_data, " + " isnull(t1.elect_value_pre, 0) as pre_yes_data, " +
@ -189,22 +189,22 @@ public interface HistoryDataPreMapper extends BaseMapper<HistoryDataPre> {
"SELECT " + "SELECT " +
" hdp.cur_date, " + " hdp.cur_date, " +
" <choose>" + " <choose>" +
" <when test='type == \"1\"'>isnull(hdp.water_value, 0)</when>" + " <when test='type == \"2\"'>isnull(hdp.water_value, 0)</when>" +
" <when test='type == \"2\"'>isnull(hdp.elect_value, 0)</when>" + " <when test='type == \"1\"'>isnull(hdp.elect_value, 0)</when>" +
" <when test='type == \"3\"'>isnull(hdp.water_level, 0)</when>" + " <when test='type == \"3\"'>isnull(hdp.water_level, 0)</when>" +
" <otherwise>0</otherwise>" + " <otherwise>0</otherwise>" +
" </choose> as cur_data, " + " </choose> as cur_data, " +
" <choose>" + " <choose>" +
" <when test='type == \"1\"'>isnull(hdp.water_value_pre, 0)</when>" + " <when test='type == \"2\"'>isnull(hdp.water_value_pre, 0)</when>" +
" <when test='type == \"2\"'>isnull(hdp.elect_value_pre, 0)</when>" + " <when test='type == \"1\"'>isnull(hdp.elect_value_pre, 0)</when>" +
" <when test='type == \"3\"'>isnull(hdp.water_level_pre, 0)</when>" + " <when test='type == \"3\"'>isnull(hdp.water_level_pre, 0)</when>" +
" <otherwise>0</otherwise>" + " <otherwise>0</otherwise>" +
" </choose> as pre_data, " + " </choose> as pre_data, " +
" CASE " + " CASE " +
" <when test='type == \"1\"'>" + " <when test='type == \"2\"'>" +
" WHEN hdp.water_value_pre > 0 THEN CONVERT(decimal(18, 2), ABS(isnull(hdp.water_value_pre, 0) - isnull(hdp.water_value, 0)) / hdp.water_value_pre * 100) else 0 " + " WHEN hdp.water_value_pre > 0 THEN CONVERT(decimal(18, 2), ABS(isnull(hdp.water_value_pre, 0) - isnull(hdp.water_value, 0)) / hdp.water_value_pre * 100) else 0 " +
" </when>" + " </when>" +
" <when test='type == \"2\"'>" + " <when test='type == \"1\"'>" +
" WHEN hdp.elect_value_pre > 0 THEN CONVERT(decimal(18, 2), ABS(isnull(hdp.elect_value_pre, 0) - isnull(hdp.elect_value, 0)) / hdp.elect_value_pre * 100) else 0 " + " WHEN hdp.elect_value_pre > 0 THEN CONVERT(decimal(18, 2), ABS(isnull(hdp.elect_value_pre, 0) - isnull(hdp.elect_value, 0)) / hdp.elect_value_pre * 100) else 0 " +
" </when>" + " </when>" +
" <when test='type == \"3\"'>" + " <when test='type == \"3\"'>" +

29
user-service/src/main/java/com/mh/user/service/impl/HistoryDataPreServiceImpl.java

@ -86,7 +86,7 @@ public class HistoryDataPreServiceImpl implements HistoryDataPreService {
bpParameter.setHiddenLayerNeuronCount(3); bpParameter.setHiddenLayerNeuronCount(3);
bpParameter.setOutputLayerNeuronCount(3); bpParameter.setOutputLayerNeuronCount(3);
bpParameter.setPrecision(0.01); bpParameter.setPrecision(0.01);
bpParameter.setMaxTimes(50000); bpParameter.setMaxTimes(10000);
// 训练BP神经网络 // 训练BP神经网络
BPModel bpModel = factory.trainBP(bpParameter, trainSet); BPModel bpModel = factory.trainBP(bpParameter, trainSet);
@ -129,11 +129,12 @@ public class HistoryDataPreServiceImpl implements HistoryDataPreService {
// 插入数据 // 插入数据
curHistoryData.setEnvMaxTemp(new BigDecimal(envMaxTemp)); curHistoryData.setEnvMaxTemp(new BigDecimal(envMaxTemp));
curHistoryData.setEnvMinTemp(new BigDecimal(envMinTemp)); curHistoryData.setEnvMinTemp(new BigDecimal(envMinTemp));
HistoryDataPre historyDataPre = historyDataPreMapper.selectOneData(buildingId, curDate);
if (historyDataPre == null) {
historyDataPreMapper.insertData(curHistoryData); historyDataPreMapper.insertData(curHistoryData);
}
// 开始预测 // 开始预测
HistoryDataPre historyDataPre1 = historyDataPreMapper.selectOneData(buildingId, curDate); HistoryDataPre historyDataPre1 = historyDataPreMapper.selectOneData(buildingId, curDate);
String[] preData = new String[]{historyDataPre1.getEnvMinTemp().toString(), historyDataPre1.getEnvMaxTemp().toString()}; String[] preData = new String[]{historyDataPre1.getEnvMinTemp().toString(), historyDataPre1.getEnvMaxTemp().toString()};
CsvInfo csvInfo = new CsvInfo(); CsvInfo csvInfo = new CsvInfo();
@ -156,14 +157,30 @@ public class HistoryDataPreServiceImpl implements HistoryDataPreService {
record[j] = result.getValOfIdx(i, j)+""; record[j] = result.getValOfIdx(i, j)+"";
} }
// 拼接预测值 // 拼接预测值
preHistoryData.setWaterValuePre(new BigDecimal(record[0])); preHistoryData.setWaterValuePre(evaluateAndReturnBigDecimal(record[0]));
preHistoryData.setElectValuePre(new BigDecimal(record[1])); preHistoryData.setElectValuePre(evaluateAndReturnBigDecimal(record[1]));
preHistoryData.setWaterLevelPre(new BigDecimal(record[2])); preHistoryData.setWaterLevelPre(evaluateAndReturnBigDecimal(record[2]));
} }
// 更新预测值 // 更新预测值
historyDataPreMapper.updateById(preHistoryData); historyDataPreMapper.updateById(preHistoryData);
} }
/**
* 判断输入的字符串转换的BigDecimal是否小于或等于0返回BigDecimal.ZERO
* 如果小于或等于0返回输入的BigDecimal如果大于0然后返回相应的BigDecimal值
*
* @param recordValue 记录中的值用于转换为BigDecimal进行比较
* @return 经过判断后的BigDecimal值
*/
public static BigDecimal evaluateAndReturnBigDecimal(String recordValue) {
BigDecimal value = new BigDecimal(recordValue);
if (value.compareTo(BigDecimal.ZERO) >= 0) {
return value;
} else {
return BigDecimal.ZERO;
}
}
@Override @Override
public List<HistoryDataPre> getRecentData(String buildingId, String curDate) { public List<HistoryDataPre> getRecentData(String buildingId, String curDate) {
return historyDataPreMapper.getRecentData(buildingId, curDate); return historyDataPreMapper.getRecentData(buildingId, curDate);

Loading…
Cancel
Save