bug fixed: 没有推送出去;滤波增加最小记录数判断,如果有效数小于10条,也不滤波

This commit is contained in:
weidong 2023-12-10 17:21:29 +08:00
parent 88b540b536
commit 86e633483a
3 changed files with 31 additions and 23 deletions

View File

@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
@ -50,7 +51,7 @@ public class ForwardGnssTask {
forwardGnssToXFZ(1); forwardGnssToXFZ(1);
} }
@Scheduled(cron = "0 0/30 * * * ?") // 每30分钟执行一次 @Scheduled(cron = "0 10 * * * ?") // 每小时的10分钟执行一次
private void forwardHistoryGnss() { private void forwardHistoryGnss() {
// 1.从转发记录表里检索待补传记录时间表含设备Id时间段 // 1.从转发记录表里检索待补传记录时间表含设备Id时间段
// 2.检索这个这个时间段的解算结果如果有数据则单个终端转发标志记录为已补传 // 2.检索这个这个时间段的解算结果如果有数据则单个终端转发标志记录为已补传
@ -62,33 +63,37 @@ public class ForwardGnssTask {
ConcurrentHashMap<String, List<GnssCalcData>> projects = new ConcurrentHashMap<>(); ConcurrentHashMap<String, List<GnssCalcData>> projects = new ConcurrentHashMap<>();
// 转发新发展数据 // 转发新发展数据
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String sendTime = nowTime.format(formatter);
String sendAfterTime = nowTime.minusMinutes(30).format(formatter);
QueryWrapper<GnssDevice> queryWrapper = new QueryWrapper<>(); QueryWrapper<GnssDevice> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("tenantid", tenantId); queryWrapper.eq("tenantid", tenantId);
List<GnssDevice> gnssDeviceList = deviceMapper.selectList(queryWrapper); List<GnssDevice> gnssDeviceList = deviceMapper.selectList(queryWrapper);
List<GnssCalcData> records; List<GnssCalcData> recordsToSend;
for(GnssDevice device:gnssDeviceList){ for(GnssDevice device:gnssDeviceList){
String projectId = device.getProject_id(); String projectId = device.getProject_id();
if(projectId == null) continue; if(projectId == null) continue;
records = projects.get(projectId); recordsToSend = projects.get(projectId);
if(records == null){ if(recordsToSend == null){
records = new ArrayList<>(); recordsToSend = new ArrayList<>();
projects.put(projectId,records); projects.put(projectId,recordsToSend);
} }
QueryWrapper<GnssCalcData> gnssQueryWrapper = new QueryWrapper<>(); QueryWrapper<GnssCalcData> gnssQueryWrapper = new QueryWrapper<>();
gnssQueryWrapper.eq("deviceid",device.getDeviceid()); gnssQueryWrapper.eq("deviceid",device.getDeviceid());
gnssQueryWrapper.ge("createtime",sendAfterTime);
gnssQueryWrapper.orderByDesc("createtime"); gnssQueryWrapper.orderByDesc("createtime");
gnssQueryWrapper.last("limit 1"); List<GnssCalcData> records = gnssDataMapper.selectList(gnssQueryWrapper);
GnssCalcData record = gnssDataMapper.selectOne(gnssQueryWrapper); for(GnssCalcData record:records) {
if(record != null && record.getEnabled()){ if (record.getEnabled()) {
if(nowTime.isBefore(record.getCreatetime().plusMinutes(40))) { recordsToSend.add(record);
records.add(record); break;
} }
} }
} }
// 按项目打包推送 // 按项目打包推送
String sendTime = nowTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
for (Map.Entry<String, List<GnssCalcData>> entry: projects.entrySet()){ for (Map.Entry<String, List<GnssCalcData>> entry: projects.entrySet()){
SendToXFZ(entry.getKey(), entry.getValue(), sendTime); SendToXFZ(entry.getKey(), entry.getValue(), sendTime);
} }
@ -119,6 +124,7 @@ public class ForwardGnssTask {
String json = GsonUtil.toJson(xfzTcpMessage); String json = GsonUtil.toJson(xfzTcpMessage);
xfzTcpClient.writeAndFlush(json); xfzTcpClient.writeAndFlush(json);
logger.info("project " + projectId + ": push calculation result to XFZ"); logger.info("project " + projectId + ": push calculation result to XFZ");
logger.info(json);
} }
} }

View File

@ -27,13 +27,13 @@ public class XFZTcpClient implements ApplicationRunner {
private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Logger logger = LoggerFactory.getLogger(this.getClass());
//@Value("${xfz.server.host}") //@Value("${xfz.server.host}")
private String host="171.106.48.63"; private String host="115.236.153.174";//"171.106.48.63";
//@Value("${xfz.server.port}") //@Value("${xfz.server.port}")
private int port=52000; private int port=45996; //52000;
//@Value("${xfz.server.data.send}") //@Value("${xfz.server.data.send}")
private boolean send=false; private boolean send=true;
private Bootstrap bootstrap; private Bootstrap bootstrap;
private EventLoopGroup group; private EventLoopGroup group;

View File

@ -43,6 +43,7 @@ public class GNSSDeviceLocationRecordServiceImpl implements GNSSDeviceLocationRe
public static final int FILTER_SHORT_CYCLE_HOUR = 4; public static final int FILTER_SHORT_CYCLE_HOUR = 4;
public static final int FILTER_LONG_CYCLE_HOUR = 25; public static final int FILTER_LONG_CYCLE_HOUR = 25;
static final int FILTER_MAX_RECORD_NUM = 50; static final int FILTER_MAX_RECORD_NUM = 50;
static final int FILTER_MIN_RECORD_NUM = 10;
static final double XY_THRESHOLD = 30; //水平异常点30mm static final double XY_THRESHOLD = 30; //水平异常点30mm
static final double Z_THRESHOLD = 30; //高程异常点30mm static final double Z_THRESHOLD = 30; //高程异常点30mm
@ -121,16 +122,16 @@ public class GNSSDeviceLocationRecordServiceImpl implements GNSSDeviceLocationRe
String deviceId = newRecord.getDeviceid(); String deviceId = newRecord.getDeviceid();
// 读取离newRecord的创建时间之前最近recordNum个原始值按时间倒序排序 // 读取离newRecord创建时间最近的filterCycleHour小时内的记录按时间倒序排序
QueryWrapper<GnssCalcData> query = new QueryWrapper<>(); QueryWrapper<GnssCalcData> query = new QueryWrapper<>();
query.orderByDesc("createtime");
query.eq("deviceid", deviceId); query.eq("deviceid", deviceId);
query.le("createtime", newRecord.getCreatetime().format(dateFormatter)); query.orderByDesc("createtime");
query.last("limit "+FILTER_MAX_RECORD_NUM); query.last("limit "+FILTER_MAX_RECORD_NUM);
List<GnssCalcData> gnssDeviceLocationRecords = repository.selectList(query); List<GnssCalcData> gnssDeviceLocationRecords = repository.selectList(query);
LocalDateTime newRecordTime = newRecord.getCreatetime(); LocalDateTime newRecordTime = newRecord.getCreatetime();
LocalDateTime filterAfterTime = newRecordTime.plusHours(filterCycleHour);
boolean hasCheck = false; boolean hasCheck = false;
if(gnssDeviceLocationRecords.size() > 0){ if(gnssDeviceLocationRecords.size() > 0){
// 求本组和最近recordNum组原始值的平均值 // 求本组和最近recordNum组原始值的平均值
@ -153,7 +154,7 @@ public class GNSSDeviceLocationRecordServiceImpl implements GNSSDeviceLocationRe
hasCheck = true; hasCheck = true;
} }
// 超过平滑周期的不参与平滑计算 // 超过平滑周期的不参与平滑计算
if(newRecordTime.isAfter(record.getCreatetime().plusHours(filterCycleHour))) break; if(newRecordTime.isAfter(filterAfterTime)) break;
if (record.getEnabled()) {//只选取好点参与滤波 if (record.getEnabled()) {//只选取好点参与滤波
sumE += record.getB562e(); sumE += record.getB562e();
sumN += record.getB562n(); sumN += record.getB562n();
@ -164,11 +165,12 @@ public class GNSSDeviceLocationRecordServiceImpl implements GNSSDeviceLocationRe
} }
} }
logger.info(deviceId + " filter records num: "+count); logger.info(deviceId + " filter records num: "+count);
return new double[]{sumE/count, sumN/count, sumD/count}; if(count >= FILTER_MIN_RECORD_NUM) {
} return new double[]{sumE / count, sumN / count, sumD / count};
else{ }
return new double[]{newRecord.getB562e(),newRecord.getB562n(),newRecord.getB562d()};
} }
return null;
} }
@Override @Override