fix:修复新beta的保存接口执行非常慢的问题
This commit is contained in:
parent
af71f40b1c
commit
356bd94a26
|
@ -41,4 +41,6 @@ public interface RedisConstant {
|
|||
String EMAIL_MSG_ID = "email_msg_id";
|
||||
|
||||
String UNDEAL_FILE = "Undeal:";
|
||||
|
||||
String SELF_PARAMETER = "self_parameter";
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package org.jeecg.common.parameter;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
import org.jeecg.common.properties.ParameterProperties;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.modules.entity.vo.NuclideLine;
|
||||
import org.jeecg.modules.entity.vo.SelfParameter;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
@Configuration
|
||||
public class SelfParameterInit {
|
||||
|
||||
@Autowired
|
||||
private ParameterProperties parameterProperties;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Bean
|
||||
public void readSelfMDCParameter() {
|
||||
//配置文件路径
|
||||
String filePath = parameterProperties.getFilePath()+ File.separator + parameterProperties.getSelfParameterFile();
|
||||
SelfParameter selfParameter = new SelfParameter();
|
||||
try {
|
||||
//创建一个文档解析器工厂
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
//创建文档解析器
|
||||
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
|
||||
//读取xml文件生成一个文档
|
||||
Document document = documentBuilder.parse(filePath);
|
||||
if (Objects.nonNull(document)){
|
||||
//获取文档的根元素
|
||||
Element element = document.getDocumentElement();
|
||||
//获取根元素的子节点
|
||||
NodeList docChildNodes = element.getChildNodes();
|
||||
//判断文件内的节点是否大于0
|
||||
if (Objects.nonNull(docChildNodes) && docChildNodes.getLength() > 0) {
|
||||
//遍历文件节点读取内容
|
||||
for (int i=0; i<docChildNodes.getLength(); i++) {
|
||||
//获取节点信息
|
||||
Node node = docChildNodes.item(i);
|
||||
//判断节点名称是否是 P
|
||||
if (node.getNodeName().equalsIgnoreCase("nuclide")) {
|
||||
//获取节点下的子节点信息
|
||||
NodeList childNodes = node.getChildNodes();
|
||||
//如果子节点不为空
|
||||
if (Objects.nonNull(childNodes) && childNodes.getLength() > 0) {
|
||||
//遍历子节点信息 将核素信息封存到缓存中
|
||||
for (int j=0; j<childNodes.getLength(); j++) {
|
||||
Node childNode = childNodes.item(j);
|
||||
//获取节点属性信息
|
||||
NamedNodeMap attributes = childNode.getAttributes();
|
||||
//判断节点属性信息是否为空
|
||||
if (Objects.nonNull(attributes)) {
|
||||
NuclideLine nuclide = new NuclideLine();
|
||||
//遍历属性信息
|
||||
for (int k=0; k<attributes.getLength(); k++) {
|
||||
//根据顺序读取属性
|
||||
Node attribute = attributes.item(k);
|
||||
if (attribute.getNodeName().equalsIgnoreCase("nuclide_name")) {
|
||||
nuclide.setName(attribute.getNodeValue());
|
||||
} else if (attribute.getNodeName().equalsIgnoreCase("yield")) {
|
||||
nuclide.setYield(Double.valueOf(attribute.getNodeValue()));
|
||||
} else if (attribute.getNodeName().equalsIgnoreCase("energy")) {
|
||||
nuclide.setEnergy(Double.valueOf(attribute.getNodeValue()));
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(nuclide.getName()) && Objects.nonNull(nuclide.getEnergy())) {
|
||||
selfParameter.getNuclideMap().put(nuclide.getName(), nuclide);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
redisUtil.set(RedisConstant.SELF_PARAMETER, selfParameter);
|
||||
} catch (ParserConfigurationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (SAXException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,4 +26,12 @@ public class ParameterProperties implements Serializable {
|
|||
*/
|
||||
private String dbPath;
|
||||
|
||||
private String SelfParameterFile;
|
||||
|
||||
private String MDCParameterFile;
|
||||
|
||||
private String SystemManagerFile;
|
||||
|
||||
private String parameterFile;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package org.jeecg.modules.entity.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import org.jeecg.modules.base.dto.NuclideInfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Data
|
||||
public class SelfParameter implements Serializable {
|
||||
// 存储核素信息
|
||||
private HashMap<String, NuclideLine> nuclideMap;
|
||||
|
||||
public SelfParameter(){
|
||||
nuclideMap = new HashMap<>();
|
||||
}
|
||||
}
|
|
@ -27,6 +27,8 @@ public class CalValuesHandler {
|
|||
|
||||
public static native String analyseSpectrum(String phd, String mapLines, String phdFilePath, AnalysisProcess process);
|
||||
|
||||
public static native String selfBgAnalyse(String PHDPath, String param);
|
||||
|
||||
public static native String fitPeakFull(String phd, List<Integer> Af, List<Integer> Cf, List<Integer> Ff);
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import com.google.common.cache.Cache;
|
|||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.common.cache.SelfCache;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
import org.jeecg.common.properties.ParameterProperties;
|
||||
import org.jeecg.modules.base.abstracts.AbstractLogOrReport;
|
||||
import org.jeecg.modules.base.enums.CalName;
|
||||
import org.jeecg.modules.base.enums.DataTypeAbbr;
|
||||
|
@ -25,9 +27,15 @@ import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.jeecg.modules.service.impl;
|
|||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
@ -21,6 +22,7 @@ import org.apache.commons.io.FileUtils;
|
|||
import org.apache.commons.math3.fitting.WeightedObservedPoints;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.cache.SelfCache;
|
||||
import org.jeecg.common.constant.RedisConstant;
|
||||
import org.jeecg.common.constant.SelfStationConstant;
|
||||
import org.jeecg.common.constant.StringConstant;
|
||||
import org.jeecg.common.constant.enums.FileTypeEnum;
|
||||
|
@ -49,11 +51,9 @@ import org.jeecg.modules.native_jni.struct.CalValuesOut;
|
|||
import org.jeecg.modules.native_jni.struct.EnergySpectrumStruct;
|
||||
import org.jeecg.modules.service.*;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
@ -2601,16 +2601,165 @@ public class SelfStationServiceImpl extends AbstractLogOrReport implements ISelf
|
|||
sampleVueData.setMapEnerPara(phdOne.getMapEnerPara());
|
||||
sampleVueData.setMapResoPara(phdOne.getMapResoPara());
|
||||
sampleVueData.setMapEffiPara(phdOne.getMapEffiPara());
|
||||
|
||||
// todo 调用beta分析
|
||||
this.betaAnalyse(selfStationData.getSampleFilePathName(), selfStationData, nuclideLinesMap);
|
||||
|
||||
result.setSuccess(true);
|
||||
result.setResult(roiMap);
|
||||
selfStationData.setBAnalyed(true);
|
||||
} catch (RuntimeException e) {
|
||||
Log.error("analyse error:", e);
|
||||
result.error500(StrUtil.replace(e.getMessage(), "%s", "ROI"));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void betaAnalyse(String phdPath, SelfStationData selfStationData, Map<String, NuclideLines> nuclideLinesMap) throws JsonProcessingException {
|
||||
SelfStationVueData sampleData = selfStationData.getSampleVueData();
|
||||
EnergySpectrumStruct struct = selfStationData.getSampleStruct();
|
||||
|
||||
// 获取自建台站参数
|
||||
SelfParameter selfParameter = (SelfParameter) redisUtil.get(RedisConstant.SELF_PARAMETER);
|
||||
HashMap<String, NuclideLine> nuclideMap = selfParameter.getNuclideMap();
|
||||
|
||||
// 获取峰面积、半衰期、发射几率
|
||||
HashMap<String, Object> nuclideParam = this.getBetaAnalyseNuclideParam(sampleData, nuclideMap, struct.POI_G_y1, struct.POI_G_y2, nuclideLinesMap);
|
||||
Console.log(JSON.toJSONString(nuclideParam));
|
||||
// 调用beta分析算法
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String result = CalValuesHandler.selfBgAnalyse(phdPath, JSON.toJSONString(mapper.writeValueAsString(nuclideParam)));
|
||||
Console.log(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取结算结果需要的参数(峰面积、半衰期、发射几率)
|
||||
* @param gStart RoiLimit Gamma Start
|
||||
* @param gStop RoiLimit Gamma Stop
|
||||
* @param nuclideLinesMap 所有核素信息
|
||||
*/
|
||||
private HashMap<String, Object> getBetaAnalyseNuclideParam(SelfStationVueData sampleData, HashMap<String, NuclideLine> nuclideMap,
|
||||
List<Double> gStart, List<Double> gStop, Map<String,
|
||||
NuclideLines> nuclideLinesMap) {
|
||||
HashMap<String, Object> param = Maps.newHashMap();
|
||||
// 获取峰信息
|
||||
List<PeakInfo> vPeak = null;
|
||||
String mapKey = "";
|
||||
// 遍历roiLimit
|
||||
for (int g = 0; g < gStart.size(); g++) {
|
||||
HashMap<String, Object> nuclideParam = Maps.newHashMap();
|
||||
String nuclideName = "";
|
||||
switch (g) {
|
||||
case 0:
|
||||
nuclideName = "Xe131M";
|
||||
mapKey = "XE-131m";
|
||||
vPeak = sampleData.getROIOnePHDFile().getVPeak();
|
||||
break;
|
||||
case 1:
|
||||
nuclideName = "Xe133M";
|
||||
mapKey = "XE-133m";
|
||||
vPeak = sampleData.getROITwoPHDFile().getVPeak();
|
||||
break;
|
||||
case 2:
|
||||
nuclideName = "Xe133";
|
||||
mapKey = "XE-133";
|
||||
vPeak = sampleData.getROIThreePHDFile().getVPeak();
|
||||
break;
|
||||
case 3:
|
||||
nuclideName = "Xe135";
|
||||
mapKey = "XE-135";
|
||||
vPeak = sampleData.getROIFourPHDFile().getVPeak();
|
||||
break;
|
||||
}
|
||||
// 发射几率
|
||||
nuclideParam.put("yield", nuclideMap.get(nuclideName).getYield().toString());
|
||||
// baseline 计数,这里使用的energy是固定的 从配置文件中取出
|
||||
nuclideParam.put("baseline",this.getBetaAnalyseBaseLineCount(sampleData, nuclideName,
|
||||
nuclideMap.get(nuclideName).getEnergy())+"");
|
||||
for (PeakInfo info : vPeak) {
|
||||
// 峰核素的energy
|
||||
double energy = info.energy;
|
||||
// 找匹配roi范围的 energy
|
||||
if (energy > gStart.get(g) && energy < gStop.get(g)) {
|
||||
double area = info.area;
|
||||
// 峰如果没有识别到核素则跳过
|
||||
if (info.nuclides.contains(nuclideName)) {
|
||||
NuclideLines nuclideLines = nuclideLinesMap.get(nuclideName);
|
||||
Console.log("halflife:{}",nuclideLines.halflife);
|
||||
// 峰面积
|
||||
nuclideParam.put("area", area+"");
|
||||
// 半衰期
|
||||
nuclideParam.put("halflife", (nuclideLines.halflife / 24 / 60 / 60) +"");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
param.put(mapKey, nuclideParam);
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
||||
private double getBetaAnalyseBaseLineCount(SelfStationVueData sampleData,String nuclideName, Double energy) {
|
||||
HashMap<String, Object> nuclideParam = Maps.newHashMap();
|
||||
double baseLineCount = 0;
|
||||
String currentText = null;
|
||||
List<Double> vBase = null;
|
||||
PHDFile phd = null;
|
||||
// 获取baseline
|
||||
switch (nuclideName) {
|
||||
case "Xe131M":
|
||||
phd = sampleData.getROIOnePHDFile();
|
||||
break;
|
||||
case "Xe133M":
|
||||
phd = sampleData.getROITwoPHDFile();
|
||||
break;
|
||||
case "Xe133":
|
||||
phd = sampleData.getROIThreePHDFile();
|
||||
break;
|
||||
case "Xe135":
|
||||
phd = sampleData.getROIFourPHDFile();
|
||||
break;
|
||||
}
|
||||
if (null == phd) {
|
||||
return 0;
|
||||
}
|
||||
vBase = phd.getVBase();
|
||||
currentText = StrUtil.isNotBlank(phd.getNewEner()) ? phd.getNewEner() : phd.getUsedEner();
|
||||
// 得到baseline count范围
|
||||
double fwhm = 0;
|
||||
// 公式参数
|
||||
ParameterInfo m_curParam = sampleData.getMapResoPara().get(currentText);
|
||||
int p_size = m_curParam.getP().size()-1;
|
||||
if(p_size >= 2 && m_curParam.getP().get(1) > 0 && m_curParam.getP().get(2) > 0) {
|
||||
// Square root of polynomial: y = sqrt(a0+a1*x+a2*x^2+a3*x^3 )
|
||||
fwhm = m_curParam.getP().get(1) + energy * m_curParam.getP().get(2);
|
||||
// equation += "FWHM = ("+NumberFormatUtil.numberFormat(String.valueOf(m_curParam.getP().get(1)))+" + E * "+NumberFormatUtil.numberFormat(String.valueOf(m_curParam.getP().get(2)));
|
||||
for(int i=3; i<=p_size; i++) {
|
||||
fwhm += (Math.pow(energy, (i-1)) * m_curParam.getP().get(i));
|
||||
// equation += " + E<sup style=\"vertical-align:super;\">"+(i-1)+"</sup> * "+NumberFormatUtil.numberFormat(String.valueOf(m_curParam.getP().get(i)));
|
||||
}
|
||||
fwhm = Math.pow(fwhm, 0.5);
|
||||
// equation += ")<sup style=\"vertical-align:super;\">"+1+"/"+2+"</sup>";
|
||||
}
|
||||
// 通过energy带入到FHWM公式中,将结果energy转化channel,加减1.25之后取这个范围之内的baseline进行加和
|
||||
List<Double> energyList = Lists.newLinkedList();
|
||||
energyList.add(energy - (fwhm - 1.25));
|
||||
CalValuesOut energyToChannel = CalValuesHandler.energyToChannel(energyList, phd.getUsedEnerPara().getP());
|
||||
long begin = Math.round(energyToChannel.counts.get(0));
|
||||
energyList = Lists.newLinkedList();
|
||||
energyList.add(energy + (fwhm + 1.25));
|
||||
energyToChannel = CalValuesHandler.energyToChannel(energyList, phd.getUsedEnerPara().getP());
|
||||
long end = Math.round(energyToChannel.counts.get(0));
|
||||
if (begin >= 0 && end <= vBase.size()) {
|
||||
for (long i = begin; i < end; i++) {
|
||||
baseLineCount += vBase.get((int)i);
|
||||
}
|
||||
}
|
||||
return baseLineCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result InteractiveTool(Integer sampleId, String fileName, int gammaROINum, HttpServletRequest request) {
|
||||
Result result = new Result();
|
||||
|
|
Loading…
Reference in New Issue
Block a user