fix:新beta 增加fitting接口

This commit is contained in:
xiaoguangbin 2024-07-17 14:33:04 +08:00
parent 5b94121112
commit 16a1407216
3 changed files with 206 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.entity.vo.ChangeData;
import org.jeecg.modules.entity.vo.FittingBody;
import org.jeecg.modules.service.ISelfStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -176,4 +177,12 @@ public class SelfStationController {
return selfStationService.Reprocessing(fileName, processKey, request);
}
@PostMapping("fitting")
@ApiOperation(value = "公式计算新的曲线", notes = "公式计算新的曲线")
public Result fitting(@RequestBody FittingBody fittingBody, HttpServletRequest request) {
return selfStationService.fitting(fittingBody.getParamA(), fittingBody.getParamB(), fittingBody.getParamC(), fittingBody.getTempPoints(), fittingBody.getCount(), fittingBody.getSampleFileName(), fittingBody.getTabName(), fittingBody.isFittingBtn(), request);
}
}

View File

@ -2,6 +2,7 @@ package org.jeecg.modules.service;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.entity.vo.ParameterInfo;
import org.jeecg.modules.entity.vo.SeriseData;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
@ -62,4 +63,8 @@ public interface ISelfStationService {
Result viewBetaDetectorCalibration(Integer sampleId, String sampleFileName, String qcFileName, boolean fittingBtn, HttpServletRequest request);
Result Reprocessing(String fileName, String processKey, HttpServletRequest request);
Result fitting(Double paramA, Double paramB, Double paramC, List<SeriseData> tempPointsArray, Integer count,
String sampleFileName, String tabName, boolean fittingBtn, HttpServletRequest request);
}

View File

@ -1734,6 +1734,198 @@ public class SelfStationServiceImpl implements ISelfStationService {
return result;
}
@Override
public Result fitting(Double paramA, Double paramB, Double paramC, List<SeriseData> tempPoints, Integer count,
String sampleFileName, String tabName, boolean fittingBtn, HttpServletRequest request) {
Result result = new Result();
//获取用户名
String userName = JwtUtil.getUserNameByToken(request);
//获取自建台站缓存信息
Cache<String, SelfStationData> selfCache = selfStationCache.getSelfCache();
SelfStationData selfStationData = selfCache.getIfPresent(sampleFileName + StringPool.DASH + userName);
// Cache<String, BetaDataFile> cache = betaCache.getBetaCache();
// BetaDataFile selfStationData = cache.getIfPresent(sampleFileName + "-" + userName);
if (Objects.isNull(selfStationData)) {
result.error500("Load basic file information first!");
return result;
}
Map<String, Object> map = new HashMap<>();
//记录点位的x轴数据
List<Double> xs = new LinkedList<>();
//记录点位的y轴数据
List<Double> ys = new LinkedList<>();
//接收算法计算得到的公式的数据
List<Double> fittingPara = new LinkedList<>();
//记录计算结果转换为字符串后数据的数组 第一组公式
List<String> fittingParaStr = new LinkedList<>();
//记录点位道值的数组
List<Double> channels = new LinkedList<>();
//新计算的点位数组
List<SeriseData> seriseDataList = new LinkedList<>();
//页面展示的表单数据数组
List<TableWidget> tableWidgets = new LinkedList<>();
//新计算得到的线点位数组
List<SeriseData> newLineSeries = new LinkedList<>();
//计算得到的新能量数组
List<List<Double>> energyList = new LinkedList<>();
//记录计算结果转换成字符串后数据的数组 第二组公式
List<String> fittingParaToUiStr = new LinkedList<>();
//tempPoint数组大小需要大于2个值
if ((CollectionUtils.isNotEmpty(tempPoints) && tempPoints.size() > 2 && Objects.nonNull(count) && tempPoints.size() != count)
|| (Objects.isNull(paramA) || StringUtils.isBlank(String.valueOf(paramA)))
|| (Objects.isNull(paramB) || StringUtils.isBlank(String.valueOf(paramB)))
|| (Objects.isNull(paramC) || StringUtils.isBlank(String.valueOf(paramC))) ){
//遍历临时点数组 将点位的横坐标以及纵坐标封装到对应的数组
for (int i=0; i<tempPoints.size(); i++){
xs.add(tempPoints.get(i).getX());
ys.add(tempPoints.get(i).getY());
}
//C to E
fittingPara = EnergySpectrumHandler.GetFileFittingPara(xs, ys);
for (Double para:fittingPara) {
fittingParaStr.add(String.valueOf(para));
}
map.put("CToE", fittingParaStr);
//填充道值数组的数据
for (int i=0; i<255; i++) {
channels.add(Double.valueOf(i));
}
//计算道值的能量
List<Double> energys = EnergySpectrumHandler.GetFileFittingData(channels,fittingPara);
//如果当前fitting按钮没有进行过操作 并且 操作的是gamma探测器相关的
if (tabName.equalsIgnoreCase("gamma") && !fittingBtn) {
//根据临时点的道值修改对应能量值
//遍历所有道值
for (int i=0; i< channels.size(); i++) {
//获取道值
double channel = channels.get(i).doubleValue();
//遍历临时点数据
for (int j=0; j<tempPoints.size(); j++) {
SeriseData seriseData = tempPoints.get(j);
double tempChannel = seriseData.getX();
//如果道值等于临时点的道值
if (channel == tempChannel) {
energys.set(i, seriseData.getY());
}
}
}
}
//将新计算的能量封装到数组
for (Double calEnergy:energys) {
List<Double> newEnergy = new LinkedList<>();
newEnergy.add(calEnergy);
energyList.add(newEnergy);
}
//遍历道值添加各道值对应点数据到数组
for (int i=0; i<channels.size(); ++i) {
SeriseData seriseData = new SeriseData();
seriseData.setX(channels.get(i));
seriseData.setY(energys.get(i));
newLineSeries.add(seriseData);
}
map.put("newLineSeries", newLineSeries);
//遍历点 缓存到表单数组以及折线图点位数组
for (int i=0; i<tempPoints.size(); i++) {
//表单数据信息
TableWidget tableWidget = new TableWidget();
tableWidget.setRowCount(i+1);
tableWidget.setChannel(tempPoints.get(i).getX());
tableWidget.setEnergy(tempPoints.get(i).getY());
tableWidgets.add(tableWidget);
//折线图位置信息
SeriseData seriseData = new SeriseData();
seriseData.setX(tempPoints.get(i).getX());
seriseData.setY(tempPoints.get(i).getY());
seriseDataList.add(seriseData);
}
map.put("tableWidgets", tableWidgets);
map.put("newScatterSeriesData", seriseDataList);
//E to C
List<Double> fittingParaToUi = EnergySpectrumHandler.GetFileFittingPara(ys, xs);
for (Double para:fittingParaToUi) {
fittingParaToUiStr.add(String.valueOf(para));
}
map.put("EToC", fittingParaToUiStr);
} else {
//添加公式的数据到公式一的数组
fittingPara.add(paramA);
fittingPara.add(paramB);
fittingPara.add(paramC);
//将公式各数据转换成字符串存到数组中
fittingParaStr.add(String.valueOf(paramA));
fittingParaStr.add(String.valueOf(paramB));
fittingParaStr.add(String.valueOf(paramC));
map.put("CToE", fittingParaStr);
//遍历点位数组 将横坐标的数据加入到数组中
for (int i=0; i<tempPoints.size(); i++){
xs.add(tempPoints.get(i).getX());
}
//根据公式和横坐标值 计算新的纵坐标数据
ys = EnergySpectrumHandler.GetFileFittingData(xs, fittingPara);
//遍历横坐标数值 将数据封存到表单数组以及折线图数组中
for (int i=0; i<xs.size(); i++) {
//表单数据信息
TableWidget tableWidget = new TableWidget();
tableWidget.setRowCount(i+1);
tableWidget.setChannel(xs.get(i));
tableWidget.setEnergy(ys.get(i));
tableWidgets.add(tableWidget);
//折线图位置信息
SeriseData seriseData = new SeriseData();
seriseData.setX(xs.get(i));
seriseData.setY(ys.get(i));
seriseDataList.add(seriseData);
}
map.put("tableWidgets", tableWidgets);
map.put("newScatterSeriesData", seriseDataList);
//填充道值数组的数据
for (int i=0; i<255; i++) {
channels.add(Double.valueOf(i));
}
//根据道值和公式参数计算新的能量数据
List<Double> energys = EnergySpectrumHandler.GetFileFittingData(channels,fittingPara);
for (Double calEnergy:energys) {
List<Double> newEnergy = new LinkedList<>();
newEnergy.add(calEnergy);
energyList.add(newEnergy);
}
//遍历道值 将道值和新的能量封装到新的点位数组
for (int i=0; i<channels.size(); ++i) {
SeriseData seriseData = new SeriseData();
seriseData.setX(channels.get(i));
seriseData.setY(energys.get(i));
newLineSeries.add(seriseData);
}
map.put("newLineSeries", newLineSeries);
//E to C
List<Double> fittingParaToUi = EnergySpectrumHandler.GetFileFittingPara(ys, xs);
for (Double para:fittingParaToUi) {
fittingParaToUiStr.add(String.valueOf(para));
}
map.put("EToC", fittingParaToUiStr);
}
if (tabName.equalsIgnoreCase("beta")) {
selfStationData.setBetaListNow(tempPoints);
selfStationData.setBetaFittingParaNow(fittingParaStr);
selfStationData.setBetaFittingParaToUiNow(fittingParaToUiStr);
selfStationData.setBetaNewEnergyListNow(energyList);
} else if (tabName.equalsIgnoreCase("gamma")) {
selfStationData.setGammaListNow(tempPoints);
selfStationData.setGammaFittingParaNow(fittingParaStr);
selfStationData.setGammaFittingParaToUiNow(fittingParaToUiStr);
selfStationData.setGammaNewEnergyListNow(energyList);
//gamma的进行计算后将当前的beta缓存的数据进行重置
selfStationData.setBetaListNow(Collections.EMPTY_LIST);
selfStationData.setBetaFittingParaNow(Collections.EMPTY_LIST);
selfStationData.setBetaFittingParaToUiNow(Collections.EMPTY_LIST);
selfStationData.setBetaNewEnergyListNow(Collections.EMPTY_LIST);
}
result.setSuccess(true);
result.setResult(map);
return result;
}
private Map<String, Object> gammaAnalyse(PHDFile phd, Map<String, NuclideLines> nuclideLinesMap,
Map<String, String> colorMap) throws RuntimeException{