feat:processFile

This commit is contained in:
nieziyan 2023-10-20 17:19:40 +08:00
parent f4876a5863
commit fe376fc30d
3 changed files with 109 additions and 112 deletions

View File

@ -1,110 +0,0 @@
package org.jeecg.modules;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import java.io.*;
import java.util.*;
public class Demo {
public static Map<String, NuclideInfo> processFile(File file){
Map<String, NuclideInfo> m_mapNuclideInfo = new TreeMap<>();
if (ObjectUtil.isNull(file)) return m_mapNuclideInfo;
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String nucline_flag = "-----------------------------------------";
String energy_flag = "REL. IMPULSANZ. KORR.FAKTOR";
String line = reader.readLine();
String nucName;
while (line != null) {
if (line.trim().equals(nucline_flag)) {
line = reader.readLine(); // 空行
nucName = reader.readLine().trim(); // 核素名称
nucName = StrUtil.subBefore(nucName, " ", false);
while (line != null && !line.trim().equals(nucline_flag)) {
if (line.trim().equals(energy_flag)) {
line = reader.readLine(); // 空行
line = reader.readLine();
List<Double> energyList = new LinkedList<>();
List<Double> factorList = new LinkedList<>();
while (line != null && !line.trim().isEmpty()) {
List<String> strList = StrUtil.splitTrim(line.trim(), " ");
if (strList.size() == 3) {
energyList.add(Double.parseDouble(strList.get(0)));
factorList.add(Double.parseDouble(strList.get(2)));
}
line = reader.readLine();
}
NuclideInfo nuclideInfo = new NuclideInfo();
nuclideInfo.setEnergy(energyList);
nuclideInfo.setFactor(factorList);
m_mapNuclideInfo.put(nucName, nuclideInfo);
} else {
line = reader.readLine();
}
}
} else {
line = reader.readLine();
}
}
} catch (IOException e) {
e.printStackTrace();
}
// 排序
for (NuclideInfo ni : m_mapNuclideInfo.values()) {
for (int i = 0; i < ni.energy.size() - 1; ++i) {
for (int j = i + 1; j < ni.energy.size(); ++j) {
if (ni.energy.get(i) > ni.energy.get(j)) {
double tempEnergy = ni.energy.get(i);
double tempFactor = ni.factor.get(i);
ni.energy.set(i, ni.energy.get(j));
ni.factor.set(i, ni.factor.get(j));
ni.energy.set(j, tempEnergy);
ni.factor.set(j, tempFactor);
}
}
}
}
return m_mapNuclideInfo;
}
private static class NuclideInfo {
List<Double> energy;
List<Double> factor;
public List<Double> getEnergy() {
return energy;
}
public void setEnergy(List<Double> energy) {
this.energy = energy;
}
public List<Double> getFactor() {
return factor;
}
public void setFactor(List<Double> factor) {
this.factor = factor;
}
NuclideInfo() {
energy = new LinkedList<>();
factor = new LinkedList<>();
}
@Override
public String toString() {
return "NuclideInfo{" +
"energy=" + energy +
", factor=" + factor +
'}';
}
}
}

View File

@ -0,0 +1,41 @@
package org.jeecg.modules.entity.vo;
import lombok.Data;
import java.util.LinkedList;
import java.util.List;
@Data
public class NuclideInfoData {
public List<Double> energy;
public List<Double> factor;
public List<Double> getEnergy() {
return energy;
}
public void setEnergy(List<Double> energy) {
this.energy = energy;
}
public List<Double> getFactor() {
return factor;
}
public void setFactor(List<Double> factor) {
this.factor = factor;
}
public NuclideInfoData() {
energy = new LinkedList<>();
factor = new LinkedList<>();
}
@Override
public String toString() {
return "NuclideInfo{" +
"energy=" + energy +
", factor=" + factor +
'}';
}
}

View File

@ -2245,13 +2245,79 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
throw new RuntimeException(e);
}
//读取生成的结果文件 并将数据存入对应的map中
Map<String, NuclideInfo> m_mapNuclideInfo = new HashMap<>();
String outFilePath = parameterProperties.getFilePath() + File.separator + "result.out";
Map<String, NuclideInfoData> m_mapNuclideInfo = processFile(new File(outFilePath));
result.setSuccess(true);
result.setResult(m_mapNuclideInfo);
return result;
}
private Map<String, NuclideInfoData> processFile(File file){
Map<String, NuclideInfoData> m_mapNuclideInfo = new TreeMap<>();
if (ObjectUtil.isNull(file)) return m_mapNuclideInfo;
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String nucline_flag = "-----------------------------------------";
String energy_flag = "REL. IMPULSANZ. KORR.FAKTOR";
String line = reader.readLine();
String nucName;
while (line != null) {
if (line.trim().equals(nucline_flag)) {
line = reader.readLine(); // 空行
nucName = reader.readLine().trim(); // 核素名称
nucName = StrUtil.subBefore(nucName, " ", false);
while (line != null && !line.trim().equals(nucline_flag)) {
if (line.trim().equals(energy_flag)) {
line = reader.readLine(); // 空行
line = reader.readLine();
List<Double> energyList = new LinkedList<>();
List<Double> factorList = new LinkedList<>();
while (line != null && !line.trim().isEmpty()) {
List<String> strList = StrUtil.splitTrim(line.trim(), " ");
if (strList.size() == 3) {
energyList.add(Double.parseDouble(strList.get(0)));
factorList.add(Double.parseDouble(strList.get(2)));
}
line = reader.readLine();
}
NuclideInfoData nuclideInfo = new NuclideInfoData();
nuclideInfo.setEnergy(energyList);
nuclideInfo.setFactor(factorList);
m_mapNuclideInfo.put(nucName, nuclideInfo);
} else {
line = reader.readLine();
}
}
} else {
line = reader.readLine();
}
}
} catch (IOException e) {
e.printStackTrace();
}
// 排序
for (NuclideInfoData ni : m_mapNuclideInfo.values()) {
for (int i = 0; i < ni.energy.size() - 1; ++i) {
for (int j = i + 1; j < ni.energy.size(); ++j) {
if (ni.energy.get(i) > ni.energy.get(j)) {
double tempEnergy = ni.energy.get(i);
double tempFactor = ni.factor.get(i);
ni.energy.set(i, ni.energy.get(j));
ni.factor.set(i, ni.factor.get(j));
ni.energy.set(j, tempEnergy);
ni.factor.set(j, tempFactor);
}
}
}
}
return m_mapNuclideInfo;
}
private String ReadRemaining() {
String txtPath = parameterProperties.getFilePath() + StringPool.SLASH + "Kordat_Remaining.txt";
File file = new File(txtPath);