feat: 增加局放谱图解析功能

dev
huangfeng 2 months ago
parent a6b1def256
commit a33d677671

@ -0,0 +1,89 @@
package com.xydl.cac.model.spectrogram;
import lombok.Data;
import java.io.DataInputStream;
import java.util.ArrayList;
import java.util.List;
@Data
public class SouthPd extends SpectrogramModel {
Float version;
Float fileVersion;
Short code;
String flag;
String name;
String pdType;
String warnLevel;
String probabilityFlag;
Float probability1;
Float probability2;
Float probability3;
Float probability4;
Float probability5;
Float probability6;
Float probability7;
Integer m;
Integer n;
Integer p;
Float hz50;
Float hz100;
String picType;
String unit;
Float minLimit;
Float maxLimit;
List<List<Integer>> dataPD;
List<List<Float>> dataPS;
public void readFrom(DataInputStream dis) throws Exception {
version = readLittleEndianFloat(dis);
fileVersion = readLittleEndianFloat(dis);
code = readLittleEndianShort(dis);
createTime = readLittleEndianLong(dis);
flag = readString(dis, 1);
name = readString(dis, 32);
pdType = readString(dis, 1);
warnLevel = readString(dis, 1);
probabilityFlag = readString(dis, 1);
probability1 = readLittleEndianFloat(dis);
probability2 = readLittleEndianFloat(dis);
probability3 = readLittleEndianFloat(dis);
probability4 = readLittleEndianFloat(dis);
probability5 = readLittleEndianFloat(dis);
probability6 = readLittleEndianFloat(dis);
probability7 = readLittleEndianFloat(dis);
m = readLittleEndianInt(dis);
n = readLittleEndianInt(dis);
p = readLittleEndianInt(dis);
hz50 = readLittleEndianFloat(dis);
hz100 = readLittleEndianFloat(dis);
picType = readString(dis, 1);
unit = readString(dis, 1);
minLimit = readLittleEndianFloat(dis);
maxLimit = readLittleEndianFloat(dis);
dis.readInt();
if ("0".equalsIgnoreCase(picType)) {
dataPD = new ArrayList<>();
for (int i = 0; i < m; i++) {
List<Integer> list = new ArrayList<>();
for (int j = 0; j < n; j++) {
Integer v = readLittleEndianInt(dis);
list.add(v);
}
dataPD.add(list);
}
} else if ("1".equalsIgnoreCase(picType)) {
dataPS = new ArrayList<>();
for (int i = 0; i < p; i++) {
List<Float> list = new ArrayList<>();
for (int j = 0; j < m; j++) {
Float v = readLittleEndianFloat(dis);
list.add(v);
}
dataPS.add(list);
}
}
}
}

@ -11,7 +11,6 @@ public class SouthYsp extends SpectrogramModel {
Float version; Float version;
Float fileVersion; Float fileVersion;
Short type; Short type;
Long createTime;
String flag; String flag;
String name; String name;
Float xInterval; Float xInterval;

@ -11,6 +11,8 @@ import java.nio.charset.StandardCharsets;
@Data @Data
public class SpectrogramModel { public class SpectrogramModel {
Long createTime;
// 读取小端序的int4字节 // 读取小端序的int4字节
public static int readLittleEndianInt(DataInputStream dis) throws IOException { public static int readLittleEndianInt(DataInputStream dis) throws IOException {
byte[] bytes = new byte[4]; byte[] bytes = new byte[4];

@ -0,0 +1,34 @@
package com.xydl.cac.spectrogram;
import com.xydl.cac.model.spectrogram.SouthPd;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.DataInputStream;
import java.io.FileInputStream;
@Service
@Slf4j
public class ProcessorPd {
public SouthPd process(String localFilePath) {
try (DataInputStream dis = new DataInputStream(new FileInputStream(localFilePath))) {
SouthPd model = this.readOneBlock(dis);
return model;
} catch (Exception e) {
log.error("解析文件失败" + localFilePath, e);
return null;
}
}
private SouthPd readOneBlock(DataInputStream dis) throws Exception {
SouthPd model = new SouthPd();
model.readFrom(dis);
return model;
}
public static void main(String[] args) {
ProcessorPd processorYsp = new ProcessorPd();
processorYsp.process("C:/Code/cac/局放谱图/50100055_5__001_01_20250409180000.dat");
}
}

@ -3,7 +3,9 @@ package com.xydl.cac.spectrogram;
import com.xydl.cac.config.BizConfig; import com.xydl.cac.config.BizConfig;
import com.xydl.cac.entity.IedDlRecord; import com.xydl.cac.entity.IedDlRecord;
import com.xydl.cac.entity.ModevType; import com.xydl.cac.entity.ModevType;
import com.xydl.cac.model.spectrogram.SouthPd;
import com.xydl.cac.model.spectrogram.SouthYsp; import com.xydl.cac.model.spectrogram.SouthYsp;
import com.xydl.cac.model.spectrogram.SpectrogramModel;
import com.xydl.cac.service.ModevTypeService; import com.xydl.cac.service.ModevTypeService;
import com.xydl.cac.util.DateUtil; import com.xydl.cac.util.DateUtil;
import com.xydl.cac.util.JSONUtil; import com.xydl.cac.util.JSONUtil;
@ -20,11 +22,14 @@ public class SpectrogramHandler {
@Resource @Resource
BizConfig bizConfig; BizConfig bizConfig;
@Resource @Resource
ModevTypeService modevTypeService;
@Resource
ProcessorYsp processorYsp; ProcessorYsp processorYsp;
@Resource @Resource
ModevTypeService modevTypeService; ProcessorPd processorPd;
public void processFile(IedDlRecord record) { public void processFile(IedDlRecord record) {
record.setCreateTime(new Date());
if (record.getTypeId() == null) { if (record.getTypeId() == null) {
return; return;
} }
@ -32,21 +37,15 @@ public class SpectrogramHandler {
try { try {
ModevType modevType = modevTypeService.detail(record.getTypeId()); ModevType modevType = modevTypeService.detail(record.getTypeId());
// 油色谱谱图 // 谱图解析
if (modevType.getMc().contains("油色谱")) { if (modevType.getMc().contains("油色谱")) {
SouthYsp model = processorYsp.process(localFilePath); SouthYsp model = processorYsp.process(localFilePath);
String json = JSONUtil.object2Json(model); this.setData(record, model);
record.setData(json);
record.setCreateTime(new Date());
try {
String str = String.valueOf(model.getCreateTime());
Date dtime = DateUtil.parse(str, "yyyyMMddHHmmss");
record.setDTime(dtime);
} catch (Exception ignore) {
}
log.info("解析油色谱谱图文件成功"); log.info("解析油色谱谱图文件成功");
} else if (modevType.getMc().contains("局部放电")) { } else if (modevType.getMc().contains("局部放电")) {
SouthPd model = processorPd.process(localFilePath);
this.setData(record, model);
log.info("解析局部放电谱图文件成功");
} else { } else {
log.error("缺少该类型" + record.getTypeId() + "的谱图处理模块"); log.error("缺少该类型" + record.getTypeId() + "的谱图处理模块");
} }
@ -56,6 +55,17 @@ public class SpectrogramHandler {
} }
} }
private void setData(IedDlRecord record, SpectrogramModel model) {
String json = JSONUtil.object2Json(model);
record.setData(json);
try {
String str = String.valueOf(model.getCreateTime());
Date dtime = DateUtil.parse(str, "yyyyMMddHHmmss");
record.setDTime(dtime);
} catch (Exception ignore) {
}
}
public void jsonToModel(IedDlRecord record) { public void jsonToModel(IedDlRecord record) {
if (record.getTypeId() == null) { if (record.getTypeId() == null) {
return; return;
@ -70,7 +80,9 @@ public class SpectrogramHandler {
record.setModel(model); record.setModel(model);
record.setData(null); record.setData(null);
} else if (modevType.getMc().contains("局部放电")) { } else if (modevType.getMc().contains("局部放电")) {
SouthPd model = JSONUtil.json2Object(record.getData(), SouthPd.class);
record.setModel(model);
record.setData(null);
} }
} catch (Exception ex) { } catch (Exception ex) {
log.error("谱图数据data内容存在异常, typeId=" + record.getTypeId() + ", devId=" + record.getDevId() log.error("谱图数据data内容存在异常, typeId=" + record.getTypeId() + ", devId=" + record.getDevId()

Loading…
Cancel
Save