From 356bd94a26eda8123ac7c427b28a08d9d6f75ffd Mon Sep 17 00:00:00 2001 From: xiaoguangbin Date: Tue, 20 Aug 2024 18:25:05 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E6=96=B0beta?= =?UTF-8?q?=E7=9A=84=E4=BF=9D=E5=AD=98=E6=8E=A5=E5=8F=A3=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E9=9D=9E=E5=B8=B8=E6=85=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeecg/common/constant/RedisConstant.java | 2 + .../common/parameter/SelfParameterInit.java | 99 ++++++++++++ .../properties/ParameterProperties.java | 8 + .../modules/entity/vo/SelfParameter.java | 17 ++ .../modules/native_jni/CalValuesHandler.java | 2 + .../jeecg/common/util/SelfStationUtil.java | 8 + .../service/impl/SelfStationServiceImpl.java | 153 +++++++++++++++++- 7 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/common/parameter/SelfParameterInit.java create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/modules/entity/vo/SelfParameter.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java index 2e885a34..50d83b65 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/constant/RedisConstant.java @@ -41,4 +41,6 @@ public interface RedisConstant { String EMAIL_MSG_ID = "email_msg_id"; String UNDEAL_FILE = "Undeal:"; + + String SELF_PARAMETER = "self_parameter"; } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/parameter/SelfParameterInit.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/parameter/SelfParameterInit.java new file mode 100644 index 00000000..915729ff --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/parameter/SelfParameterInit.java @@ -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 0) { + //遍历子节点信息 将核素信息封存到缓存中 + for (int j=0; j nuclideMap; + + public SelfParameter(){ + nuclideMap = new HashMap<>(); + } +} diff --git a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/CalValuesHandler.java b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/CalValuesHandler.java index 25e0147c..91beeb3c 100644 --- a/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/CalValuesHandler.java +++ b/jeecg-module-beta-gamma-analyser/src/main/java/org/jeecg/modules/native_jni/CalValuesHandler.java @@ -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 Af, List Cf, List Ff); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java index c21b8a7d..d081a135 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/common/util/SelfStationUtil.java @@ -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; diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SelfStationServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SelfStationServiceImpl.java index 6ecd9305..6cc2e9e8 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SelfStationServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SelfStationServiceImpl.java @@ -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 nuclideLinesMap) throws JsonProcessingException { + SelfStationVueData sampleData = selfStationData.getSampleVueData(); + EnergySpectrumStruct struct = selfStationData.getSampleStruct(); + + // 获取自建台站参数 + SelfParameter selfParameter = (SelfParameter) redisUtil.get(RedisConstant.SELF_PARAMETER); + HashMap nuclideMap = selfParameter.getNuclideMap(); + + // 获取峰面积、半衰期、发射几率 + HashMap 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 getBetaAnalyseNuclideParam(SelfStationVueData sampleData, HashMap nuclideMap, + List gStart, List gStop, Map nuclideLinesMap) { + HashMap param = Maps.newHashMap(); + // 获取峰信息 + List vPeak = null; + String mapKey = ""; + // 遍历roiLimit + for (int g = 0; g < gStart.size(); g++) { + HashMap 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 nuclideParam = Maps.newHashMap(); + double baseLineCount = 0; + String currentText = null; + List 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"+(i-1)+" * "+NumberFormatUtil.numberFormat(String.valueOf(m_curParam.getP().get(i))); + } + fwhm = Math.pow(fwhm, 0.5); +// equation += ")"+1+"/"+2+""; + } + // 通过energy带入到FHWM公式中,将结果energy转化channel,加减1.25之后取这个范围之内的baseline进行加和 + List 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();