Просмотр исходного кода

性能验证模块 开发 (二期) / 重构相关模块

liyuan 1 год назад
Родитель
Сommit
0d9780117d
11 измененных файлов с 100 добавлено и 101 удалено
  1. 23 35
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/LinearRangeAverageSlope.java
  2. 16 14
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/LinearRangeEP6A.java
  3. 20 36
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/LinearRangeRecoveryMethod.java
  4. 21 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/ModelEnum.java
  5. 8 8
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PVItemBuilder.java
  6. 1 1
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PrecisionEP15.java
  7. 3 3
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PrecisionEP15Item.java
  8. 1 1
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PrecisionRepeatability.java
  9. 5 3
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/TruenessBiasAssessment.java
  10. 1 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/TruenessEP15Patient.java
  11. 1 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/TruenessRefernece.java

+ 23 - 35
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/LinearRangeAverageSlope.java

@@ -4,17 +4,20 @@ import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.lc.ibps.components.verification.model.InspectionConfigVO;
 import com.lc.ibps.components.verification.regression.PolynomialRegression;
-import com.lc.ibps.components.verification.report.ChartDTO;
 import com.lc.ibps.components.verification.report.ReportDataDTO;
+import com.lc.ibps.components.verification.report.ReportFactory;
 import com.lc.ibps.components.verification.report.TableDTO;
 import org.apache.commons.lang3.ArrayUtils;
-import org.apache.commons.math3.stat.StatUtils;
-import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+import org.apache.commons.math3.linear.MatrixUtils;
+import org.apache.commons.math3.linear.RealMatrix;
+import org.apache.commons.math3.linear.RealMatrixFormat;
+import org.apache.commons.math3.stat.regression.RegressionResults;
+import org.apache.commons.math3.stat.regression.SimpleRegression;
 
+import java.text.DecimalFormat;
 import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 public class LinearRangeAverageSlope extends PVModel {
 
@@ -47,26 +50,10 @@ public class LinearRangeAverageSlope extends PVModel {
 
     @Override
     public void calculate() {
-
-        for (int i = 0; i < specimensNum; i++) {
-            DescriptiveStatistics stat = new DescriptiveStatistics(data[i]);
-            means[i] = stat.getMean();
-            standardDeviations[i] = stat.getStandardDeviation();
-            if (repeatNum == 2) {
-                diffs[1][i] = data[i][0] - data[i][1];  //diff
-                diffs[2][i] = Math.pow(diffs[1][i], 2) / 2; //diff * diff / 2
-                diffs[3][i] = diffs[1][i] / means[i];  //%diff
-                diffs[4][i] = Math.pow(diffs[3][i], 2) / 2; //%diff * %diff /2
-            }
-
-        }
-        diffs[0] = means;
-        mean = StatUtils.mean(means);
-        sdr = Math.sqrt(StatUtils.mean(diffs[2])) * 100;
-        cvr = Math.sqrt(StatUtils.mean(diffs[4])) * 100;
-        //TODO: check cvr
-
-        pr1.addData(targetValues, means, repeatNum, 1);
+        final SimpleRegression regression = new SimpleRegression();
+        regression.addData(data);
+        RegressionResults results = regression.regress();
+//        results.
 
     }
 
@@ -139,19 +126,20 @@ public class LinearRangeAverageSlope extends PVModel {
         InspectionConfigVO config = new InspectionConfigVO("平均斜率", 1, 6,
                 null, 2, LocalDate.now(), true);
         config.setTargetValue(new double[]{0, 24.56});
+        config.setKey(ModelEnum.LinearRangeAverageSlope.getKey());
         double[][] data = {{-0.01, -0.01}, {5.00, 4.99}, {10.18, 10.05}, {14.65, 14.65}, {19.57, 19.65}, {24.02, 24.09}};
-        LinearRangeAverageSlope ep6 = new LinearRangeAverageSlope(data, config);
-        TableDTO tableDTO = ep6.buildDataTableDTO();
-        Map<String, TableDTO> stringTableDTOMap = ep6.buildTableDTO(0);
-        final Map<String, ChartDTO> stringChartDTOMap = ep6.buildChartDTO(0);
-        ReportDataDTO report = new ReportDataDTO();
-
-
-        report.setDataDTO(tableDTO);
-//        report.setReportDataDTO(stringTableDTOMap);
-        String s = JSONObject.toJSONString(report, SerializerFeature.DisableCircularReferenceDetect);
-
+        RealMatrix matrix = MatrixUtils.createRealMatrix(data);
+        RealMatrixFormat matrixFormat = new RealMatrixFormat("", "", "", "\n",
+                "", ",", new DecimalFormat("0.00"));
+        System.out.println(matrixFormat.format(matrix));
+
+        PVItemBuilder pvItemBuilder = PVItemBuilder.getInstance(config);
+        pvItemBuilder.buildPVModel(data);
+        ReportDataDTO dataDTO = ReportFactory.build(pvItemBuilder);
+        String s = JSONObject.toJSONString(dataDTO, SerializerFeature.DisableCircularReferenceDetect);
+        String s1 = pvItemBuilder.getPvModel().generateResult();
         System.out.println(s);
+        System.out.println(s1);
 
     }
 }

+ 16 - 14
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/LinearRangeEP6A.java

@@ -4,14 +4,15 @@ import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.lc.ibps.components.verification.model.InspectionConfigVO;
 import com.lc.ibps.components.verification.regression.PolynomialRegression;
-import com.lc.ibps.components.verification.report.ChartDTO;
-import com.lc.ibps.components.verification.report.EchartsFreemarkerUtils;
-import com.lc.ibps.components.verification.report.ReportDataDTO;
-import com.lc.ibps.components.verification.report.TableDTO;
+import com.lc.ibps.components.verification.report.*;
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.math3.linear.MatrixUtils;
+import org.apache.commons.math3.linear.RealMatrix;
+import org.apache.commons.math3.linear.RealMatrixFormat;
 import org.apache.commons.math3.stat.StatUtils;
 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
 
+import java.text.DecimalFormat;
 import java.time.LocalDate;
 import java.util.*;
 
@@ -34,7 +35,6 @@ public class LinearRangeEP6A extends PVModel {
     private PolynomialRegression prBest;
 
 
-
     private double sdr;
     private double cvr;
 
@@ -283,19 +283,21 @@ public class LinearRangeEP6A extends PVModel {
         InspectionConfigVO config = new InspectionConfigVO("EP6-A线性评价", 1, 6,
                 null, 2, LocalDate.now(), true);
         config.setTargetValue(new double[]{0, 24.56});
+        config.setKey(ModelEnum.LinearRangeEP6A.getKey());
         double[][] data = {{-0.01, -0.01}, {5.00, 4.99}, {10.18, 10.05}, {14.65, 14.65}, {19.57, 19.65}, {24.02, 24.09}};
-        LinearRangeEP6A ep6 = new LinearRangeEP6A(data, config);
-        TableDTO tableDTO = ep6.buildDataTableDTO();
-        Map<String, TableDTO> stringTableDTOMap = ep6.buildTableDTO(0);
-        final Map<String, ChartDTO> stringChartDTOMap = ep6.buildChartDTO(0);
-        ReportDataDTO report = new ReportDataDTO();
-
 
-        report.setDataDTO(tableDTO);
-//        report.setReportDataDTO(stringTableDTOMap);
-        String s = JSONObject.toJSONString(report, SerializerFeature.DisableCircularReferenceDetect);
+        RealMatrix matrix = MatrixUtils.createRealMatrix(data);
+        RealMatrixFormat matrixFormat = new RealMatrixFormat("", "", "", "\n",
+                "", ",", new DecimalFormat("0.00"));
+        System.out.println(matrixFormat.format(matrix));
 
+        PVItemBuilder pvItemBuilder = PVItemBuilder.getInstance(config);
+        pvItemBuilder.buildPVModel(data);
+        ReportDataDTO dataDTO = ReportFactory.build(pvItemBuilder);
+        String s = JSONObject.toJSONString(dataDTO, SerializerFeature.DisableCircularReferenceDetect);
+        String s1 = pvItemBuilder.getPvModel().generateResult();
         System.out.println(s);
+        System.out.println(s1);
 
     }
 }

+ 20 - 36
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/LinearRangeRecoveryMethod.java

@@ -3,14 +3,15 @@ package com.lc.ibps.components.verification.model2;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.lc.ibps.components.verification.model.InspectionConfigVO;
-import com.lc.ibps.components.verification.report.ChartDTO;
 import com.lc.ibps.components.verification.report.ReportDataDTO;
-import com.lc.ibps.components.verification.report.SheetDTO;
+import com.lc.ibps.components.verification.report.ReportFactory;
 import com.lc.ibps.components.verification.report.TableDTO;
+import org.apache.commons.math3.linear.MatrixUtils;
+import org.apache.commons.math3.linear.RealMatrix;
+import org.apache.commons.math3.linear.RealMatrixFormat;
 
+import java.text.DecimalFormat;
 import java.time.LocalDate;
-import java.util.HashMap;
-import java.util.Map;
 
 public class LinearRangeRecoveryMethod extends LinearRangeAverageSlope {
 
@@ -23,7 +24,7 @@ public class LinearRangeRecoveryMethod extends LinearRangeAverageSlope {
 
     @Override
     public void calculate() {
-
+        super.calculate();
     }
 
 
@@ -32,11 +33,8 @@ public class LinearRangeRecoveryMethod extends LinearRangeAverageSlope {
     }
 
     @Override
-    public SheetDTO[] buildSheetDTO() {
-        SheetDTO sheet = new SheetDTO("线性稀释回收法");
-        sheet.setReportDataDTO(buildReportTableDTO());
-        sheet.setChartDataDTO(buildChartDTO());
-        return new SheetDTO[]{sheet};
+    public String[] sheetNames() {
+        return new String[]{"线性稀释回收法"};
     }
 
     @Override
@@ -44,39 +42,25 @@ public class LinearRangeRecoveryMethod extends LinearRangeAverageSlope {
         return null;
     }
 
-    public Map<String, TableDTO> buildReportTableDTO() {
-        Map<String, TableDTO> reports = new HashMap<>();
-//        reports.put("表1: 重复性差异检测结果", buildTable1DTO());
-//        reports.put("表2: 多项式回归分析结果", buildTable2DTO());
-//        reports.put("表3: 线性偏离计算结果", buildTable3DTO());
-        return reports;
-    }
-
-    public Map<String, ChartDTO> buildChartDTO() {
-        Map<String, ChartDTO> charts = new HashMap<>();
-//        charts.put("图1: 线性实验", buildChart1DTO());
-//        charts.put("图2: 线性评价差值点图", buildChart2DTO());
-        return charts;
-    }
-
 
     public static void main(String[] args) {
         InspectionConfigVO config = new InspectionConfigVO("线性稀释回收法", 1, 6,
                 null, 2, LocalDate.now(), true);
         config.setTargetValue(new double[]{0, 24.56});
+        config.setKey(ModelEnum.LinearRangeRecoveryMethod.getKey());
         double[][] data = {{-0.01, -0.01}, {5.00, 4.99}, {10.18, 10.05}, {14.65, 14.65}, {19.57, 19.65}, {24.02, 24.09}};
-        LinearRangeRecoveryMethod ep6 = new LinearRangeRecoveryMethod(data, config);
-        TableDTO tableDTO = ep6.buildDataTableDTO();
-        Map<String, TableDTO> stringTableDTOMap = ep6.buildReportTableDTO();
-        final Map<String, ChartDTO> stringChartDTOMap = ep6.buildChartDTO();
-        ReportDataDTO report = new ReportDataDTO();
-
-
-        report.setDataDTO(tableDTO);
-//        report.setReportDataDTO(stringTableDTOMap);
-        String s = JSONObject.toJSONString(report, SerializerFeature.DisableCircularReferenceDetect);
-
+        RealMatrix matrix = MatrixUtils.createRealMatrix(data);
+        RealMatrixFormat matrixFormat = new RealMatrixFormat("", "", "", "\n",
+                "", ",", new DecimalFormat("0.00"));
+        System.out.println(matrixFormat.format(matrix));
+
+        PVItemBuilder pvItemBuilder = PVItemBuilder.getInstance(config);
+        pvItemBuilder.buildPVModel(data);
+        ReportDataDTO dataDTO = ReportFactory.build(pvItemBuilder);
+        String s = JSONObject.toJSONString(dataDTO, SerializerFeature.DisableCircularReferenceDetect);
+        String s1 = pvItemBuilder.getPvModel().generateResult();
         System.out.println(s);
+        System.out.println(s1);
 
     }
 }

+ 21 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/ModelEnum.java

@@ -0,0 +1,21 @@
+package com.lc.ibps.components.verification.model2;
+
+public enum ModelEnum {
+    PrecisionEP15("精密度:EP15精密度验证"),
+    PrecisionRepeatability("精密度:重复性验证"),
+    TruenessBiasAssessment("正确度:偏倚评估"),
+    TruenessEP15Patient("正确度:使用患者样品验证"),
+    TruenessRefernece("正确度:使用定值参考物质验证"),
+    LinearRangeEP6A("线性区间:EP6线性评价"),
+    LinearRangeAverageSlope("线性区间:平均斜率评价法"),
+    LinearRangeRecoveryMethod("线性区间:线性稀释回收法");
+    private final String key;
+
+    ModelEnum(String key) {
+        this.key = key;
+    }
+
+    public String getKey() {
+        return key;
+    }
+}

+ 8 - 8
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PVItemBuilder.java

@@ -92,21 +92,21 @@ public class PVItemBuilder {
 
     public PVModel buildPVModel(double[][] dataArrays) {
 //        PVModel pvModel;
-        if (config.getKey().equals("精密度:EP15精密度验证")) {
+        if (config.getKey().equals(ModelEnum.PrecisionEP15.getKey())) {
             pvModel = new PrecisionEP15(dataArrays, config);
-        } else if (config.getKey().equals("精密度:重复性验证")) {
+        } else if (config.getKey().equals(ModelEnum.PrecisionRepeatability.getKey())) {
             pvModel = new PrecisionRepeatability(dataArrays, config);
-        } else if (config.getKey().equals("正确度:使用定值参考物质验证")) {
+        } else if (config.getKey().equals(ModelEnum.TruenessRefernece.getKey())) {
             pvModel = new TruenessRefernece(dataArrays, config);
-        } else if (config.getKey().equals("正确度:使用患者样品验证")) {
+        } else if (config.getKey().equals(ModelEnum.TruenessEP15Patient.getKey())) {
             pvModel = new TruenessEP15Patient(dataArrays, config);
-        } else if (config.getKey().equals("正确度:偏倚评估")) {
+        } else if (config.getKey().equals(ModelEnum.TruenessBiasAssessment.getKey())) {
             pvModel = new TruenessBiasAssessment(dataArrays, config);
-        } else if (config.getKey().equals("线性区间:EP6线性评价")) {
+        } else if (config.getKey().equals(ModelEnum.LinearRangeEP6A.getKey())) {
             pvModel = new LinearRangeEP6A(dataArrays, config);
-        } else if (config.getKey().equals("线性区间:平均斜率评价法")) {
+        } else if (config.getKey().equals(ModelEnum.LinearRangeAverageSlope.getKey())) {
             pvModel = new LinearRangeAverageSlope(dataArrays, config);
-        } else if (config.getKey().equals("线性区间:线性稀释回收法")) {
+        } else if (config.getKey().equals(ModelEnum.LinearRangeRecoveryMethod.getKey())) {
             pvModel = new LinearRangeRecoveryMethod(dataArrays, config);
         } else {
             return null;

+ 1 - 1
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PrecisionEP15.java

@@ -136,7 +136,7 @@ public class PrecisionEP15 extends PVModel {
         config.setDailyCVSValue(3.1);
         config.setDecimal(3);
         config.setUnits("mmg/L");
-        config.setKey("精密度验证");
+        config.setKey(ModelEnum.PrecisionEP15.getKey());
         RandomUtils.nextDouble();
         double[][] data = new double[config.getDays()][config.getRepeatNum() * config.getSpecimensNum()];
         for (int i = 0; i < config.getDays(); i++) {

+ 3 - 3
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PrecisionEP15Item.java

@@ -65,17 +65,17 @@ public class PrecisionEP15Item {
         this.n = configVO.getRepeatNum();
         this.allowableCVr = configVO.getBatchCVSValue();
         this.allowableCVl = configVO.getDailyCVSValue();
-        if(ArrayUtils.isNotEmpty(configVO.getAllowableSDr())) {
+        if (ArrayUtils.isNotEmpty(configVO.getAllowableSDr())) {
             this.allowableSDr = configVO.getAllowableSDr()[index];
         }
-        if(ArrayUtils.isNotEmpty(configVO.getAllowableSDl())) {
+        if (ArrayUtils.isNotEmpty(configVO.getAllowableSDl())) {
             this.allowableSDl = configVO.getAllowableSDl()[index];
         }
 
         this.level = configVO.getSpecimensNum();
         int rate = configVO.getRejectionRate();
         if (rate > 0 && rate < 100) {
-            this.p = (double) (rate / 100);
+            this.p = rate / 100;
         } else {
             this.p = 0.01;
         }

+ 1 - 1
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PrecisionRepeatability.java

@@ -158,7 +158,7 @@ public class PrecisionRepeatability extends PVModel {
         config.setBatchCVSValue(2.5);
         config.setDecimal(3);
         config.setUnits("mmg/L");
-        config.setKey("重复性验证");
+        config.setKey(ModelEnum.PrecisionRepeatability.getKey());
         RandomUtils.nextDouble();
         double[][] data = new double[config.getSpecimensNum()][config.getRepeatNum()];
         for (int i = 0; i < config.getSpecimensNum(); i++) {

+ 5 - 3
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/TruenessBiasAssessment.java

@@ -20,12 +20,13 @@ import java.util.Map;
 public class TruenessBiasAssessment extends PVModel {
     private double[] targetValues;
     private double tea;
-    private double bias;
     private final double[] means;
+    private final double[] bias;
 
     public TruenessBiasAssessment(double[][] data, InspectionConfigVO configVO) {
         super(data, configVO);
         this.means = new double[specimensNum];
+        this.bias = new double[specimensNum];
     }
 
     @Override
@@ -36,6 +37,7 @@ public class TruenessBiasAssessment extends PVModel {
             realMatrix.copySubMatrix(0, data.length - 1,
                     i * repeatNum, (i + 1) * repeatNum - 1, sub);
             means[i] = StatUtils.mean(array2DTo1D(sub));
+            bias[i] = 100 * Math.abs(means[i] - targetValues[i]) / targetValues[i];
         }
     }
 
@@ -83,12 +85,12 @@ public class TruenessBiasAssessment extends PVModel {
     public static void main(String[] args) {
         InspectionConfigVO config = new InspectionConfigVO("偏倚评估", 5, 2,
                 null, 2, LocalDate.now(), true);
-        config.setRange(99);
+        config.setRejectionRate(1);
         config.setBatchCVSValue(3.2);
         config.setDailyCVSValue(3.1);
         config.setDecimal(3);
         config.setUnits("mmg/L");
-        config.setKey("CNAS-GL037偏倚评估");
+        config.setKey(ModelEnum.TruenessBiasAssessment.getKey());
         RandomUtils.nextDouble();
         double[][] data = new double[config.getDays()][config.getRepeatNum() * config.getSpecimensNum()];
         for (int i = 0; i < config.getDays(); i++) {

+ 1 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/TruenessEP15Patient.java

@@ -253,6 +253,7 @@ public class TruenessEP15Patient extends PVModel {
         config.setMethodNum(2);
         config.setClaimValue(3);
         config.setUnits("mmol/L");
+        config.setKey(ModelEnum.TruenessEP15Patient.getKey());
         double[][] data = {{125, 123},
                 {77, 74},
                 {320, 315},

+ 1 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/TruenessRefernece.java

@@ -124,6 +124,7 @@ public class TruenessRefernece extends PVModel {
                 null, 2, LocalDate.now(), true);
         config.setUnits("mmol/L");
         config.setTargetValue(new double[]{2.1, 2.2});
+        config.setKey(ModelEnum.TruenessRefernece.getKey());
         double[][] data = {
                 {2.04, 2.09, 2.04, 2.09},
                 {2.15, 2.04, 2.04, 2.09},