Merge remote-tracking branch 'origin/SelfStation' into SelfStation

This commit is contained in:
nieziyan 2024-07-25 14:28:59 +08:00
commit 82ebe1009e
3 changed files with 142 additions and 4 deletions

View File

@ -1,5 +1,10 @@
package org.jeecg.modules.controller;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
@ -15,6 +20,8 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
@RestController
@ -51,8 +58,12 @@ public class SelfStationController {
@PutMapping("updateROI")
@ApiOperation(value = "更新ROI范围", notes = "更新ROI范围")
public Result updateROI(@RequestBody List<ROIParam> roiParams, @RequestParam String sampleFileName, HttpServletRequest request) {
return selfStationService.updateROI(roiParams, sampleFileName, request);
public Result updateROI(@RequestParam String roiParams, @RequestParam String sampleFileName, HttpServletRequest request) {
if (StrUtil.isBlank(roiParams)) {
return Result.error("roiParams cannot be empty!");
}
List<ROIParam> roiParamList = JSONArray.parseArray(roiParams, ROIParam.class);
return selfStationService.updateROI(roiParamList, sampleFileName, request);
}
@GetMapping("energyCalibration")
@ -281,6 +292,12 @@ public class SelfStationController {
return selfStationService.fitting(fittingBody.getParamA(), fittingBody.getParamB(), fittingBody.getParamC(), fittingBody.getTempPoints(), fittingBody.getCount(), fittingBody.getSampleFileName(), fittingBody.getTabName(), fittingBody.isFittingBtn(), request);
}
@GetMapping("getGammaGated")
@ApiOperation(value = "获取gamma对应count数据", notes = "获取gamma对应count数据")
public Result getGammaGated(Integer chartHeight, Integer channelWidth, Integer gammaChannel, Integer sampleId, String qcFileName, String sampleFileName, HttpServletRequest request) {
return selfStationService.getGammaGated(chartHeight, channelWidth, gammaChannel, sampleId, qcFileName, sampleFileName, request);
}
@GetMapping("NuclideLibrary")
@ApiOperation(value = "查看Nuclide Library页面数据", notes = "查看Nuclide Library页面数据")
public Result NuclideLibrary(Integer sampleId, String fileName, String editEnergy, double err, String libraryName, String nuclideName, HttpServletRequest request) {

View File

@ -95,6 +95,8 @@ public interface ISelfStationService {
Result fitting(Double paramA, Double paramB, Double paramC, List<SeriseData> tempPointsArray, Integer count,
String sampleFileName, String tabName, boolean fittingBtn, HttpServletRequest request);
Result getGammaGated(Integer chartHeight, Integer channelWidth, Integer gammaChannel, Integer sampleId, String qcFileName, String sampleFileName, HttpServletRequest request);
Result NuclideLibrary(Integer sampleId, String fileName, String editEnergy, double err, String libraryName, String nuclideName, HttpServletRequest request);
Result configUserLibrary(Integer sampleId, String fileName, HttpServletRequest request);

View File

@ -13,12 +13,12 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.cache.Cache;
import com.google.common.collect.Maps;
import org.apache.commons.io.FileUtils;
import org.apache.commons.math3.fitting.GaussianCurveFitter;
import org.apache.commons.math3.fitting.WeightedObservedPoints;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.cache.LocalCache;
import org.jeecg.common.cache.SelfCache;
import org.jeecg.common.constant.DateConstant;
import org.jeecg.common.properties.ParameterProperties;
import org.jeecg.common.properties.SpectrumPathProperties;
import org.jeecg.common.system.util.JwtUtil;
@ -1742,6 +1742,9 @@ public class SelfStationServiceImpl implements ISelfStationService {
}
//Beta-Gamma Spectrum: QC 散点图相关数据
List<HistogramData> histogramDataList = new LinkedList<>();
// todo 减少数量 暂时写512
gChannels = 512;
bChannels = 512;
for (int column=0; column<gChannels; column++) {
for (int row=0; row<bChannels; row++) {
Long index = column * bChannels + row;
@ -1794,6 +1797,39 @@ public class SelfStationServiceImpl implements ISelfStationService {
}
map.put("EToC", fittingParaToUiStr);
// todo 按照默认点选择刻度点
// E_β=661.6-E_γE_γ=F(C)
//中心C_β=F(E_β)范围[C_β-3(C_β ), C_β+3(C_β )]
// 高斯函数拟合得到拟合的中心道址显示Energy vs. Channel
//页面展示的表单数据数组
List<TableWidget> table = new LinkedList<>();
for (int i = 0; i < oldScatterSeries.size(); i++) {
SeriseData data = oldScatterSeries.get(i);
WeightedObservedPoints points = new WeightedObservedPoints();
// 通过散点图gamma的channel拿到当前beta横向数据
List<SeriseData> seriseDatas = this.getGateGamma(5, 256, (int) data.getX(), betaDataFile);
seriseDatas.forEach(f->{
// x = beta channel, y = beta energy
double x = f.getX();
double left = x - Math.cbrt(x);
double right = x + Math.cbrt(x);
points.add(x, left, right);
});
// 使用高斯曲线拟合观测点
GaussianCurveFitter fitter = GaussianCurveFitter.create();
double[] parameters = fitter.fit(points.toList());
//表单数据信息
TableWidget tableWidget = new TableWidget();
tableWidget.setRowCount(i+1);
tableWidget.setChannel(parameters[0]);
tableWidget.setEnergy(parameters[0]);
System.out.println("table:" + parameters[0]);
table.add(tableWidget);
}
map.put("tableWidgets", table);
//判断人工交互的道值与能量对应参数数组是否为空
if (Objects.nonNull(betaDataFile.getBgPara()) && CollectionUtils.isNotEmpty(betaDataFile.getBetaList())) {
//存储计算参数道值
@ -2944,6 +2980,89 @@ public class SelfStationServiceImpl implements ISelfStationService {
return result;
}
@Override
public Result getGammaGated(Integer chartHeight, Integer channelWidth, Integer gammaChannel, Integer sampleId, String qcFileName, String sampleFileName, HttpServletRequest request) {
Result result = new Result();
Map<String, Object> map = new HashMap<>();
//获取用户名称
String userName = JwtUtil.getUserNameByToken(request);
//获取自建台站缓存信息
Cache<String, SelfStationData> selfCache = selfStationCache.getSelfCache();
SelfStationData betaDataFile = selfCache.getIfPresent(sampleFileName + StringPool.DASH + userName);
// Cache<String, BetaDataFile> cache = betaCache.getBetaCache();
// BetaDataFile betaDataFile = cache.getIfPresent(sampleFileName + "-" + userName);
if (Objects.isNull(betaDataFile)) {
result.error500("Load basic file information first!");
return result;
}
//选择矩形框高度
Integer flagHeight = channelWidth * (chartHeight/256);
int value = Double.valueOf(flagHeight / 2).intValue();
//计算得到最高值
int up = gammaChannel - value;
if (up<0){
up = 0;
}
//计算得到最低值
int down = up + value;
EnergySpectrumStruct struct = betaDataFile.getQcStruct();
if (Objects.nonNull(struct)) {
//Beta-Gamma Spectrum: QC
long bChannels = struct.b_channels;
List<Long> hCounts = struct.h_counts;
List<SeriseData> serise_data = new LinkedList<>();
for ( int i=0; i<bChannels; ++i ) {
long count = 0;
for (int j=up; j<=down; ++j) {
Long index = j * bChannels + i;
count += hCounts.get(index.intValue());
}
SeriseData temp = new SeriseData();
temp.setX(i);
temp.setY(count);
serise_data.add(temp);
}
map.put("data", serise_data);
}
result.setSuccess(true);
result.setResult(map);
return result;
}
private List<SeriseData> getGateGamma(int channelWidth, int chartHeight, int gammaChannel, SelfStationData betaDataFile){
List<SeriseData> serise_data = new LinkedList<>();
//选择矩形框高度
Integer flagHeight = channelWidth * (chartHeight/256);
int value = Double.valueOf(flagHeight / 2).intValue();
//计算得到最高值
int up = gammaChannel - value;
if (up<0){
up = 0;
}
//计算得到最低值
int down = up + value;
EnergySpectrumStruct struct = betaDataFile.getQcStruct();
if (Objects.nonNull(struct)) {
//Beta-Gamma Spectrum: QC
long bChannels = struct.b_channels;
List<Long> hCounts = struct.h_counts;
for ( int i=0; i<bChannels; ++i ) {
long count = 0;
for (int j=up; j<=down; ++j) {
Long index = j * bChannels + i;
count += hCounts.get(index.intValue());
}
SeriseData temp = new SeriseData();
temp.setX(i);
temp.setY(count);
serise_data.add(temp);
}
}
return serise_data;
}
@Override
@DS("ora")
public Result NuclideLibrary(Integer sampleId, String fileName, String editEnergy, double err, String libraryName, String nuclideName, HttpServletRequest request) {