修改轨迹展示,获取数据发送频率
This commit is contained in:
parent
a3adc6e33e
commit
e702165615
@ -1,6 +1,7 @@
|
|||||||
package com.yfd.platform.component;
|
package com.yfd.platform.component;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.catalina.connector.ClientAbortException;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
@ -65,13 +66,27 @@ public class ServerSendEventServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("user id:{}, send message error:{}", userId,
|
// 处理客户端断开连接的情况
|
||||||
e.getMessage());
|
if (e instanceof ClientAbortException ||
|
||||||
e.printStackTrace();
|
(e.getCause() != null && e.getCause() instanceof ClientAbortException)) {
|
||||||
|
log.warn("客户端已断开连接,移除SSE连接,user id: {}", userId);
|
||||||
|
} else {
|
||||||
|
log.error("发送消息失败,user id:{}, error:{}", userId, e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除已失效的emitter
|
||||||
|
removeEmitter(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void removeEmitter(String userId) {
|
||||||
|
SseEmitter emitter = sseEmitterMap.remove(userId);
|
||||||
|
if (emitter != null) {
|
||||||
|
emitter.complete(); // 确保资源释放
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 给所有用户发消息
|
* 给所有用户发消息
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -5459,11 +5459,16 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
|
|
||||||
// 根据文件后缀确定配置文件路径
|
// 根据文件后缀确定配置文件路径
|
||||||
String configResourcePath;
|
String configResourcePath;
|
||||||
|
String Separator;
|
||||||
if (fileName.toLowerCase().endsWith(".csv")) {
|
if (fileName.toLowerCase().endsWith(".csv")) {
|
||||||
|
|
||||||
configResourcePath = "config/trj_config.txt";
|
configResourcePath = "config/trj_config.txt";
|
||||||
|
Separator = ",";
|
||||||
} else if (fileName.toLowerCase().endsWith(".txt")) {
|
} else if (fileName.toLowerCase().endsWith(".txt")) {
|
||||||
configResourcePath = "config/trj_config_ins_img.txt";
|
configResourcePath = "config/trj_config_ins_img.txt";
|
||||||
|
Separator = "\t";
|
||||||
} else {
|
} else {
|
||||||
|
Separator = "";
|
||||||
throw new IllegalArgumentException("不支持的文件格式: " + fileName + ",仅支持.csv和.txt文件");
|
throw new IllegalArgumentException("不支持的文件格式: " + fileName + ",仅支持.csv和.txt文件");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5499,7 +5504,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
Path dataPath = basePath.resolve(tsFiles.getFileName());
|
Path dataPath = basePath.resolve(tsFiles.getFileName());
|
||||||
|
|
||||||
// 4. 处理数据文件
|
// 4. 处理数据文件
|
||||||
processDataFile(dataPath, samTimes, token, timeColumn, lonColumn, latColumn, hgtColumn);
|
processDataFile(dataPath, samTimes, token, timeColumn, lonColumn, latColumn, hgtColumn,Separator);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("任务执行失败: {}", e.getMessage(), e);
|
LOGGER.error("任务执行失败: {}", e.getMessage(), e);
|
||||||
@ -5665,7 +5670,7 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
|
|
||||||
private void processDataFile(Path dataPath, int samTimes, String token,
|
private void processDataFile(Path dataPath, int samTimes, String token,
|
||||||
String timeColumn, String lonColumn,
|
String timeColumn, String lonColumn,
|
||||||
String latColumn, String hgtColumn)
|
String latColumn, String hgtColumn,String Separator)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
try (BufferedReader reader = Files.newBufferedReader(dataPath, StandardCharsets.UTF_8)) {
|
try (BufferedReader reader = Files.newBufferedReader(dataPath, StandardCharsets.UTF_8)) {
|
||||||
@ -5749,32 +5754,50 @@ public class TsFilesServiceImpl extends ServiceImpl<TsFilesMapper, TsFiles> impl
|
|||||||
int sendCount = 0;
|
int sendCount = 0;
|
||||||
|
|
||||||
int lineCountData = 0;
|
int lineCountData = 0;
|
||||||
float timeValue0 = 0;
|
double timeValue0 = 0;
|
||||||
float timeValue1 = 0;
|
double timeValue1 = 0;
|
||||||
int result = 0; //
|
int result = 0; //
|
||||||
|
|
||||||
while (!Thread.currentThread().isInterrupted() && (line = reader.readLine()) != null) {
|
while (!Thread.currentThread().isInterrupted() ) {
|
||||||
lineCountData++;
|
String line1 = "";
|
||||||
if (lineCountData > 2) {
|
String line2 = "";
|
||||||
break; // 跳出循环,停止读取数据
|
if((line = reader.readLine()) != null)
|
||||||
|
line1 = line;
|
||||||
|
if ((line = reader.readLine()) != null) {
|
||||||
|
line2 = line;
|
||||||
}
|
}
|
||||||
|
System.out.println("正在处理数据行: {}" +line1);
|
||||||
|
System.out.println("正在处理数据行: {}" +line2);
|
||||||
// 使用逗号分隔数据行
|
// 使用逗号分隔数据行
|
||||||
String[] values = line.split(","); // 改为逗号分隔
|
String[] values = line1.split(Separator); // 改为逗号分隔
|
||||||
if (lineCountData == 1) {
|
timeValue0 = Float.parseFloat(values[timeIndex]);//Float.parseFloat(getValueSafely(values, timeIndex, "0.0"));
|
||||||
// 读取第一行的时间值
|
String[] values2 = line2.split(Separator); // 改为逗号分隔
|
||||||
timeValue0 = Float.parseFloat(getValueSafely(values, timeIndex, "0.0")); // 将字符串转换为数字
|
timeValue1 = Float.parseFloat(values2[timeIndex]);//Float.parseFloat(getValueSafely(values2, timeIndex, "0.0"));
|
||||||
} else if (lineCountData == 2) {
|
|
||||||
// 读取第二行的时间值
|
double data = timeValue1 - timeValue0;
|
||||||
timeValue1 = Float.parseFloat(getValueSafely(values, timeIndex, "0.0")); // 将字符串转换为数字
|
// 计算 1 / data
|
||||||
// 计算 timeValue1 - timeValue0
|
if (Math.abs(data) > 0.0000001) {
|
||||||
float data = timeValue1 - timeValue0;
|
// 四舍五入,而不是向下取整
|
||||||
// 计算 1 / data
|
result = (int) Math.round(1.0 / data);
|
||||||
if (data != 0) { // 确保避免除以零
|
break;
|
||||||
result = (int) Math.floor(1 / data);
|
}else {
|
||||||
} else {
|
result = 1;
|
||||||
result = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// if (lineCountData == 1) {
|
||||||
|
// // 读取第一行的时间值
|
||||||
|
// timeValue0 = Float.parseFloat(getValueSafely(values, timeIndex, "0.0")); // 将字符串转换为数字
|
||||||
|
// } else if (lineCountData == 2) {
|
||||||
|
// // 读取第二行的时间值
|
||||||
|
// timeValue1 = Float.parseFloat(getValueSafely(values, timeIndex, "0.0")); // 将字符串转换为数字
|
||||||
|
// // 计算 timeValue1 - timeValue0
|
||||||
|
// float data = timeValue1 - timeValue0;
|
||||||
|
// // 计算 1 / data
|
||||||
|
// if (data != 0) { // 确保避免除以零
|
||||||
|
// result = (int) Math.floor(1 / data);
|
||||||
|
// } else {
|
||||||
|
// result = 1;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user