fix:gamma 生成lc scac baseline工具優化

This commit is contained in:
xiaoguangbin 2023-09-25 19:00:37 +08:00
parent 0ac2c77e27
commit fbd353ea39

View File

@ -6,9 +6,10 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Objects;
public class GammaReportUtil {
public static void writeBaseline(BaseControls baseCtrl, String path){
public static void writeFile(BaseControls baseCtrl, String path){
// 创建文件
File file = new File(path);
try {
@ -19,7 +20,7 @@ public class GammaReportUtil {
String high = String.valueOf(baseCtrl.getRg_high());
out.printf("%" + (low.length() + 15) + "s", low);
out.printf("%" + (high.length() + 15) + "s", high);
out.println("");
out.println("#XCtrl");
format(baseCtrl.getXCtrl(), out);
@ -38,53 +39,49 @@ public class GammaReportUtil {
e.printStackTrace();
}
}
public static void writeSCAC(BaseControls baseCtrl, String path){
public static void writeFile(List<Double> data, String fileType, String path){
// 创建文件
File file = new File(path);
try {
// 创建PrintWriter对象
PrintWriter out = new PrintWriter(file);
out.println("#AnalyseRange");
String low = String.valueOf(baseCtrl.getRg_low());
String high = String.valueOf(baseCtrl.getRg_high());
out.printf("%" + (low.length() + 15) + "s", low);
out.printf("%" + (high.length() + 15) + "s", high);
out.println("#" + fileType);
out.printf("%" + (String.valueOf(data.size()).length() + 15) + "s", data.size() + "\n");
format(data, out);
out.println("#XCtrl");
format(baseCtrl.getXCtrl(), out);
out.println("#YCtrl");
format(baseCtrl.getYCtrl(), out);
out.println("#YSlope");
format(baseCtrl.getYSlope(), out);
out.println("#Baseline");
format(baseCtrl.getBaseline(), out);
out.println("#StepCounts");
format(baseCtrl.getStepCounts(), out);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private static void format(List<Double> baseline, PrintWriter out) {
private static void format(List<Double> data, PrintWriter out) {
// 每行的数量
int numPerLine = 5;
int nBL = baseline.size(), nGroupBL = nBL / numPerLine * numPerLine;
int i,n = data.size(), nGroupBL = n / numPerLine * numPerLine;
// 计算每列数据中最长的字符串长度
int[] columnWidths = new int[baseline.size()];
for (int i = 0; i < baseline.size(); i++) {
columnWidths[i] = Math.max(columnWidths[i], baseline.get(i).toString().length());
int[] columnWidths = new int[data.size()];
for (i = 0; i < data.size(); i++) {
String col = Objects.isNull(data.get(i)) ? "" : String.valueOf(data.get(i));
columnWidths[i] = Math.max(columnWidths[i], col.length());
}
for(int i = 1; i < nGroupBL; i++)
out.printf("%" + (String.valueOf(data.size()).length() + 15) + "s", data.size() + "\n");
for(i = 0; i < nGroupBL; i++)
{
out.printf("%" + (columnWidths[i] + 15) + "s", baseline.get(i-1));
if(i % numPerLine == 0){
String col = Objects.isNull(data.get(i)) ? "nan" : String.valueOf(data.get(i));
out.printf("%" + (columnWidths[i] + 15) + "s", col);
if((i+1) % numPerLine == 0) {
out.println("");
}
}
if(i < n)
{
for(; i<n; ++i){
String col = Objects.isNull(data.get(i)) ? "nan" : String.valueOf(data.get(i));
out.printf("%" + (columnWidths[i] + 15) + "s", col);
}
}
out.println("");
}
}