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.FileNotFoundException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.List; import java.util.List;
import java.util.Objects;
public class GammaReportUtil { public class GammaReportUtil {
public static void writeBaseline(BaseControls baseCtrl, String path){ public static void writeFile(BaseControls baseCtrl, String path){
// 创建文件 // 创建文件
File file = new File(path); File file = new File(path);
try { try {
@ -19,7 +20,7 @@ public class GammaReportUtil {
String high = String.valueOf(baseCtrl.getRg_high()); String high = String.valueOf(baseCtrl.getRg_high());
out.printf("%" + (low.length() + 15) + "s", low); out.printf("%" + (low.length() + 15) + "s", low);
out.printf("%" + (high.length() + 15) + "s", high); out.printf("%" + (high.length() + 15) + "s", high);
out.println("");
out.println("#XCtrl"); out.println("#XCtrl");
format(baseCtrl.getXCtrl(), out); format(baseCtrl.getXCtrl(), out);
@ -38,53 +39,49 @@ public class GammaReportUtil {
e.printStackTrace(); 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); File file = new File(path);
try { try {
// 创建PrintWriter对象 // 创建PrintWriter对象
PrintWriter out = new PrintWriter(file); PrintWriter out = new PrintWriter(file);
out.println("#AnalyseRange"); out.println("#" + fileType);
String low = String.valueOf(baseCtrl.getRg_low()); out.printf("%" + (String.valueOf(data.size()).length() + 15) + "s", data.size() + "\n");
String high = String.valueOf(baseCtrl.getRg_high()); format(data, out);
out.printf("%" + (low.length() + 15) + "s", low);
out.printf("%" + (high.length() + 15) + "s", high);
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) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
private static void format(List<Double> baseline, PrintWriter out) { private static void format(List<Double> data, PrintWriter out) {
// 每行的数量 // 每行的数量
int numPerLine = 5; 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()]; int[] columnWidths = new int[data.size()];
for (int i = 0; i < baseline.size(); i++) { for (i = 0; i < data.size(); i++) {
columnWidths[i] = Math.max(columnWidths[i], baseline.get(i).toString().length()); 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)); String col = Objects.isNull(data.get(i)) ? "nan" : String.valueOf(data.get(i));
if(i % numPerLine == 0){ out.printf("%" + (columnWidths[i] + 15) + "s", col);
if((i+1) % numPerLine == 0) {
out.println(""); 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("");
} }
} }