fix: 能谱log日志生产工具

This commit is contained in:
orgin 2023-09-18 15:16:31 +08:00
parent ed7493423b
commit 674fc6f78b
2 changed files with 317 additions and 0 deletions

View File

@ -0,0 +1,292 @@
package org.jeecg.common.util;
import cn.hutool.core.lang.Console;
import com.google.common.collect.Lists;
import lombok.Data;
import org.jeecg.modules.base.bizVo.AttributeItemVo;
import java.util.*;
@Data
public class MyLogFormatUtil {
public List<String> energyAttribute;
public List<String> efficiencyAttribute;
public List<String> resolutionAttribute;
public List<String> totalEfficiencyAttribute;
/**
* 标题长度
*/
public static Integer CONTEXT_TITLE_SIZE = 100;
/**
* 页眉长度
*/
public static Integer CONTEXT_HEADER_SIZE = 5;
/**
* .
*/
public static String CONTEXT_TITLE_FLAG = ".";
/**
* -
*/
public static String FILE_TITLE_FLAG = "-";
public static String STRING_END = "\n";
/**
* 自动处理 log 开始
*/
public static final String analyseResultsBegin = "Sample Analyse Beginning at %1";
/**
* 读取 calibration 开始
*/
public static final String titleCalibrationIdEnd = "Read calibration finished";
/**
* 读取 calibration 结束
*/
public static final String titleCalibration = "Read calibration data";
/**************************************** Beta ****************************************/
/**
* 获取 det gas 开头
*/
public static final String BTitleId = "Get DetaId and GasId";
/**
* 获取 det gas 结束
*/
public static final String BTitleIdEnd = "Get DetaId and GasId finished";
/**************************************** Gamma ****************************************/
// Reading sample beta energy pairs(sampleID: 478827).....
public static final String SetSampleBEnergyChannel = "Reading sample beta energy pairs(sampleID: %1)";
// Reading gamma energy pairs(sampleID: 478660).....
public static final String SetSampleGEnergyChannel = "Reading sample gamma energy pairs(sampleID: %1)";
public static final String SetDetaBEnergyChannel = "Reading DETBK Spectrum beta energy pairs(sampleID: %1)";
public static final String SetDetaGEnergyChannel = "Reading DETBK Spectrum gamma energy pairs(sampleID: %1)";
public static final String SetGasBEnergyChannel = "Reading GASBK Spectrum beta energy pairs(sampleID: %1)";
public static final String SetGasGEnergyChannel = "Reading GASBK Spectrum gamma energy pairs(sampleID: %1)";
public static final String GetMeasurementTime = "Reading mesurement information";
public static final String GetVolume = "Reading volume data";
public static final String SetRoiLimits = "Reading ROI limits";
public static final String SetRoiRatios = "Reading ROI ratios";
public static final String SetDetectorEfficiencies = "Reading b-g Efficiency";
public static final String SetBoundary = "Limits per ROI (SampleID:%1)";
public static final String SetGrossCounts = "Gross counts per ROI";
public static final String SetNetCounts = "Net counts and Lc per ROI";
// public static final String SetConcentrationMdc = "Concentration and MDC per ROI";
public static final String SetConcentrationMdc = "Concentration and MDC per isotope";
public static final String TitleNCC = "Starting NCC analysis";
public static final String TitleNCCEnd = "NCC analysis finished";
public static final String GSetSampleEnergyChannel = "Reading gamma energy pairs(sampleID: %1)";
public static final String GSetSampleResolutionChannel = "Reading gamma Resolution pairs(sampleID: %1)";
public static final String GSetSampleEfficiencyChannel = "Reading gamma Efficiency pairs(sampleID: %1)";
public static final String GSetSampleTotalEfficiencyChannel = "Reading gamma TotalEfficiency pairs(sampleID: %1)";
public static final String sampleInfo = "Reading sample information";
public static final String GTitleCalibration = "Starting Calibration";
public static final String GTitleCalibrationEnd = "Calibration Finished";
public static final String GTitleSpectrum = "Starting Spectrum Analysis";
public static final String GTitleSpectrumEnd = "Spectrum Analysis Finished";
public static final String GGetPROCESSING = "PROCESSING PARAMETERS";
public static final String GGetCALIBRATION = "CALIBRATION PARAMETERS";
public static final String GGetPeakSearchResult = "Nuclide Identified";
public static final String GGetDataQuality = "Starting Data Quality";
public static List<String> getBlock(String title, String sampleId, List<AttributeItemVo> attributeItemVo) {
title = title.replace("%1", sampleId);
List<String> context = getBlockContext(attributeItemVo);
context.add(0, title + STRING_END);
return context;
}
public static void main(String[] args) {
Map<String, Object> data = new LinkedHashMap<>();
data.put("Collection Start", "2023/09/11 01:20:24");
data.put("Collection Stop", "2023/09/12 01:12:44");
data.put("Sampling Time[h]", 23.8722);
data.put("Sample Quantity[m3]", 22825);
data.put("Decay Time[h]", 24.2167);
data.put("Acquisition Start", "2023/09/13 01:25:45");
data.put("Acquisition Stop", "2023/09/14 01:05:17");
data.put("Acquisition Time[s]", 85435);
int keyWidth = 20;
int valueWidth = 25;
getBlockContext(data);
Console.log(getContextTitleFormat("title","."));
Console.log(getContextHeaderFormat("header","."));
List<String> channels = Arrays.asList("59.541", "88.034", "122.061", "165.857", "391.698", "661.657", "834.838", "898.036", "1115.540", "1173.230", "1332.490", "1836.050");
List<String> energies = Arrays.asList("0.168", "0.176", "0.174", "0.155", "0.092", "0.059", "0.051", "0.040", "0.040", "0.031", "0.028", "0.022");
List<String> errors = Arrays.asList("0.003", "0.004", "0.003", "0.003", "0.002", "0.001", "0.001", "0.001", "0.001", "0.001", "0.001", "0.000");
List<AttributeItemVo> energys = new ArrayList<>();
AttributeItemVo attributeItemVo = new AttributeItemVo();
attributeItemVo.setAttribute("Channel");
attributeItemVo.setContext(channels);
energys.add(attributeItemVo);
// attributeItem = new AttributeItem();
// attributeItem.setAttribute("Energy");
// attributeItem.setContext(energies);
// energys.add(attributeItem);
// attributeItem = new AttributeItem();
// attributeItem.setAttribute("Error");
// attributeItem.setContext(errors);
energys.add(attributeItemVo);
MyLogFormatUtil.getBlock(MyLogFormatUtil.SetSampleGEnergyChannel, "sampleId", energys);
// List<AttributeItem> data = new ArrayList<>();
// AttributeItem attributeItem = new AttributeItem();
// attributeItem.setAttribute("channel");
// attributeItem.setUnit(" ");
// attributeItem.setContext(channels);
//
// AttributeItem attributeItem1 = new AttributeItem();
// attributeItem1.setAttribute("energies");
// attributeItem1.setUnit(" dev");
// attributeItem1.setContext(energies);
//
// AttributeItem attributeItem2 = new AttributeItem();
// attributeItem2.setAttribute("errors");
// attributeItem2.setUnit(" ");
// attributeItem2.setContext(errors);
//
// data.add(attributeItem);
// data.add(attributeItem1);
// data.add(attributeItem2);
// setBlock(new GammaArrLog().totalEfficiencyChannel, "abc", data);
}
/**
* 获取标题格式
* ....................................... XXX ........................................
* @param title
* @param flag
* @return
*/
public static String getContextTitleFormat(String title, String flag) {
int padding = (CONTEXT_TITLE_SIZE - title.length()) / 2;
return String.format("%" + padding + "s%s%" + padding + "s", flag, title, flag).replace(" ",flag);
}
/**
* 获取页眉
* XXX.....
* @param title
* @param flag
* @return
*/
public static String getContextHeaderFormat(String title, String flag) {
return String.format("%s%" + CONTEXT_HEADER_SIZE + "s", title, flag, "\n").replace(" ",flag);
}
/**
* 获取内容正文
* @param data
* @return
*/
public static List<String> getBlockContext(Map<String, Object> data) {
List<String> result = new LinkedList<>();
int keyWidth = 0;
int valueWidth = 0;
for (Map.Entry<String, Object> entry : data.entrySet()) {
keyWidth = Math.max(entry.getKey().length(), keyWidth);
valueWidth = Math.max(entry.getValue().toString().length(), valueWidth);
}
for (Map.Entry<String, Object> entry : data.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
String formattedKey = String.format("%-"+ (keyWidth + 4) + "s", key);
String formattedValue = String.format("%-"+ (valueWidth + 4) + "s", value);
System.out.println(formattedKey + " : " + formattedValue);
result.add(formattedKey + " : " + formattedValue);
}
return result;
}
/**
* 获取内容正文
* @param data
* @return
*/
public static List<String> getBlockContext(List<AttributeItemVo> data) {
List<String> result = new LinkedList<>();
List<List<String>> tempData = new ArrayList<>();
if(data.size() > 0) {
// 初始化数据
for(int row = 0; row < data.get(0).getContext().size(); row++) {
List<String> items = new LinkedList<>();
tempData.add(items);
// 获取有多少列数据
for(int column = 0; column < data.size(); column++) {
if(data.get(column).getContext().size() > row) {
AttributeItemVo item = data.get(column);
items.add(item.getAttribute() + " : " + item.getContext().get(row) + " " + item.getUnit());
}
}
}
// 计算每列数据中最长的字符串长度
int[] columnWidths = new int[tempData.get(0).size()];
for (List<String> row : tempData) {
for (int i = 0; i < row.size(); i++) {
columnWidths[i] = Math.max(columnWidths[i], row.get(i).length());
}
}
// 构造格式化字符串
StringBuilder formatBuilder = new StringBuilder();
for (int i = 0; i < columnWidths.length; i++) {
formatBuilder.append("%-").append(columnWidths[i] + 4).append("s");
}
String format = formatBuilder.toString();
// 格式化输出日志
for (List<String> row : tempData) {
result.add(String.format(format, row.toArray()));
Console.log(String.format(format, row.toArray()));
}
result.add(STRING_END);
}
return result;
}
/**
* 求百分比
* @param one 被除数
* @param two 除数
* @return
*/
public static List<String> getPercent(List<String> one, List<String> two) {
List<String> result = Lists.newLinkedList();
for (int i = 0; i < one.size(); i++) {
result.add(((Double.parseDouble(one.get(i)) / Double.parseDouble(two.get(i))) * 100) + "");
}
return result;
}
/**
* 小数点格式化
* @param source 原数据
* @param num 小数点位数
* @return
*/
public static List<String> getValuePoint(List<String> source, int num) {
List<String> result = Lists.newLinkedList();
for (String str : source) {
result.add(String.format("%." + num + "f", Double.parseDouble(str)));
}
return result;
}
}

View File

@ -0,0 +1,25 @@
package org.jeecg.modules.base.bizVo;
import lombok.Data;
import java.util.List;
@Data
public class AttributeItemVo {
private String attribute;
private List<String> context;
private String unit = "";
public AttributeItemVo(){
}
public AttributeItemVo(String attribute, List<String> context, String unit) {
this.attribute = attribute;
this.context = context;
this.unit = unit;
}
public AttributeItemVo(String attribute, List<String> context) {
this.attribute = attribute;
this.context = context;
}
}