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

[task-1766] 性能验证模块 开发 (二期) / 【后端】验证报告的接口开发

Li Yuan 1 год назад
Родитель
Сommit
d32d26d532
12 измененных файлов с 562 добавлено и 366 удалено
  1. 9 9
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/InspectionItemVO.java
  2. 1 1
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/LinearRangeEP6A.java
  3. 27 24
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PVItemBuilder.java
  4. 13 8
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PVModel.java
  5. 227 145
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PrecisionEP15.java
  6. 49 7
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/TruenessEP15Patient.java
  7. 202 122
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/TruenessRefernece.java
  8. 2 2
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/regression/PolynomialRegression.java
  9. 0 34
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/ReportDataDTO.java
  10. 2 5
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/ReportFactory.java
  11. 28 8
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/TableDTO.java
  12. 2 1
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/service/impl/PerformanceVerificationServiceImpl.java

+ 9 - 9
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/InspectionItemVO.java

@@ -10,7 +10,7 @@ import com.lc.ibps.components.poi.excel.entity.vo.BaseEntityTypeConstants;
 import com.lc.ibps.components.verification.excel.PVExcelExportStyler;
 import com.lc.ibps.components.verification.excel.PVExcelUtil;
 import com.lc.ibps.components.verification.funcs.xValue;
-import com.lc.ibps.components.verification.model2.CalcVO;
+import com.lc.ibps.components.verification.model2.PVModel;
 import com.lc.ibps.components.verification.report.ReportDataDTO;
 import org.apache.poi.ss.usermodel.Workbook;
 
@@ -40,9 +40,9 @@ public class InspectionItemVO {
     private Map<String, SpecimensCalcVO> record = new HashMap<>();
 
     @JSONField(serialize = false)
-    private Map<String, CalcVO> record2 = new HashMap<>();
+    private Map<String, PVModel> record2 = new HashMap<>();
 
-    private CalcVO calcVO;
+    private PVModel PVModel;
 
 
     @JSONField(serialize = false)
@@ -288,19 +288,19 @@ public class InspectionItemVO {
         return null;
     }
 
-    public Map<String, CalcVO> getRecord2() {
+    public Map<String, PVModel> getRecord2() {
         return record2;
     }
 
-    public void setRecord2(Map<String, CalcVO> record2) {
+    public void setRecord2(Map<String, PVModel> record2) {
         this.record2 = record2;
     }
 
-    public CalcVO getCalcVO() {
-        return calcVO;
+    public PVModel getCalcVO() {
+        return PVModel;
     }
 
-    public void setCalcVO(CalcVO calcVO) {
-        this.calcVO = calcVO;
+    public void setCalcVO(PVModel PVModel) {
+        this.PVModel = PVModel;
     }
 }

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

@@ -11,7 +11,7 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
 
 import java.util.*;
 
-public class LinearRangeEP6A extends CalcVO {
+public class LinearRangeEP6A extends PVModel {
 
     private double[][] data;
 

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

@@ -29,8 +29,8 @@ public class PVItemBuilder {
 
     public static String DISPLAY_DATE = "实验日期";
     private InspectionConfigVO config;
-    private CalcVO calcVO;
-    private Map<String, CalcVO> calcMap = new HashMap<>();
+    private PVModel pvModel;
+//    private Map<String, PVModel> calcMap = new HashMap<>();
 
     private PVItemBuilder(){
 
@@ -50,20 +50,12 @@ public class PVItemBuilder {
         this.config = config;
     }
 
-    public CalcVO getCalcVO() {
-        return calcVO;
+    public PVModel getPvModel() {
+        return pvModel;
     }
 
-    public void setCalcVO(CalcVO calcVO) {
-        this.calcVO = calcVO;
-    }
-
-    public Map<String, CalcVO> getCalcMap() {
-        return calcMap;
-    }
-
-    public void setCalcMap(Map<String, CalcVO> calcMap) {
-        this.calcMap = calcMap;
+    public void setPvModel(PVModel pvModel) {
+        this.pvModel = pvModel;
     }
 
     public void importExcelRecord(InputStream inputstream) throws IOException {
@@ -104,33 +96,44 @@ public class PVItemBuilder {
         }
 
         if(config.getName().toLowerCase().contains("精密度")){
+            PrecisionEP15 precisionEP15 = new PrecisionEP15(config.getSpecimensName(),config.getDecimal());
+
             for (String sName : config.getSpecimensName()) {
                 //day - spec
                 double[][] data = new double[config.getDays()][config.getRepeatNum()];
                 for (int j = 0; j < list.size(); j++) {
-                    data[j] = CalcVO.transposeXValue(list.get(j).getConvertedData().get(sName));
+                    data[j] = pvModel.transposeXValue(list.get(j).getConvertedData().get(sName));
                 }
-                calcMap.put(sName, new PrecisionEP15(data,config.getBatchCVSValue(),config.getDailyCVSValue(),config.getDecimal()));
+                precisionEP15.buildItem(sName,data,config.getBatchCVSValue(),config.getDailyCVSValue());
+                pvModel = precisionEP15;
             }
+
         }else if(config.getName().equals("定值参考物质验证")){
+            TruenessRefernece truenessRefernece = new TruenessRefernece(config.getSpecimensName(),config.getDecimal());
             for (String sName : config.getSpecimensName()) {
-                final xValue[] total = new xValue[config.getRepeatNum() * config.getDays()];
+//                final xValue[] total = new xValue[config.getRepeatNum() * config.getDays()];
+//                for (int j = 0; j < list.size(); j++) {
+//                    final xValue[] xValues = list.get(j).getConvertedData().get(sName);
+//                    for (int k = 0; k < xValues.length; k++) {
+//                        total[j * xValues.length + k] = xValues[k];
+//                    }
+//                }
+                //day - spec
+                double[][] data = new double[config.getDays()][config.getRepeatNum()];
                 for (int j = 0; j < list.size(); j++) {
-                    final xValue[] xValues = list.get(j).getConvertedData().get(sName);
-                    for (int k = 0; k < xValues.length; k++) {
-                        total[j * xValues.length + k] = xValues[k];
-                    }
+                    data[j] = pvModel.transposeXValue(list.get(j).getConvertedData().get(sName));
                 }
-                calcMap.put(sName, new TruenessRefernece(CalcVO.transposeXValue(total), config.getTargetValue()[0],config.getClaimValue(),0));
+                truenessRefernece.buildItem(sName,data, config.getTargetValue()[0],config.getClaimValue(),0);
+                pvModel = truenessRefernece;
             }
         }else if(config.getName().equals("EP15-A方法学比对")){
 
-            calcVO = new TruenessEP15Patient(dataArrays, config.getClaimValue(),0);
+            pvModel = new TruenessEP15Patient(dataArrays, config.getClaimValue(),0,config.getDecimal());
 
         }
         else if(config.getName().equals("EP6-A线性评价")){
 
-            calcVO = new LinearRangeEP6A(dataArrays, config.getTargetValue(),config.getClaimValue(),config.getDecimal());
+            pvModel = new LinearRangeEP6A(dataArrays, config.getTargetValue(),config.getClaimValue(),config.getDecimal());
 
         }
 

+ 13 - 8
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/CalcVO.java → ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PVModel.java

@@ -2,11 +2,12 @@ package com.lc.ibps.components.verification.model2;
 
 import com.lc.ibps.components.verification.funcs.xValue;
 import com.lc.ibps.components.verification.report.TableDTO;
+import org.apache.commons.math3.distribution.ChiSquaredDistribution;
 import org.apache.commons.math3.distribution.TDistribution;
 
 import java.util.Map;
 
-public class CalcVO {
+public abstract class PVModel {
 
     private int scale;
     public String format(double d){
@@ -25,6 +26,15 @@ public class CalcVO {
         return format(value,2);
     }
 
+    public static double getC(double degreesOfFreedom, int level){
+        return getC(degreesOfFreedom,level,0.05);
+    }
+
+    public static double getC(double degreesOfFreedom, int level,double p){
+        ChiSquaredDistribution x2 = new ChiSquaredDistribution( 10 );
+        return x2.inverseCumulativeProbability(1 - p/level);//level
+    }
+
 
     public  double[][] transposeMatrix(double[][] before) {
         double[][] after = new double[before[0].length][before.length];
@@ -36,13 +46,8 @@ public class CalcVO {
         return after;
     }
 
-    public TableDTO buildDataTableDTO(){
-        return null;
-    }
-    public Map<String, TableDTO> buildReportTableDTO(){
-
-        return null;
-    }
+    public abstract TableDTO buildDataTableDTO();
+    public abstract Map<String, TableDTO> buildReportTableDTO();
 
     public int getScale() {
         return scale;

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

@@ -1,188 +1,270 @@
 package com.lc.ibps.components.verification.model2;
 
+import com.lc.ibps.components.verification.report.TableDTO;
 import org.apache.commons.math3.stat.StatUtils;
 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
 
-public class PrecisionEP15 extends CalcVO {
-
-    private double[][] data;
-
-    /*
-
-        Number of replicates 	3
-        Number of days				5
-        A       B       C       D       E           F       G
-                Rep 1	Rep 2	Rep 3	Run mean	Run SD	Variance
-    5   Day 1	3.3	    3.23	3.43	3.320	    0.101	0.010
-    6   Day 2	3.21	3.45	3.42	3.360	    0.131	0.017
-    7   Day 3	3.21	3.24	3.45	3.300	    0.131	0.017
-    8   Day 4	3.5	    3.45	3.51	3.487	    0.032	0.001
-    9   Day 5	3.33	3.45	3.32	3.367	    0.072	0.005
-
-    11  Over all mean [ Average E5:E9]	        3.367       总均值
-    12  Within run variance Vr [ average G5:G9]	0.010
-    13 Within run SD [SQRT(B12)]	            0.101       批内标准差(Sr)
-    14  Between run SD [SD(E5:E9)]	            0.073
-    15  Between run variance Vb [B14*B14]	    0.005       批间方差
-    16  Ratio Vr/Vb  [+B12/B15]	                1.928
-    17  Total variance [((B2-1)/B2)*B12+B15]	0.012
-    18  Laboratory SD [SQRT B17]	            0.110       室内标准差
-    19  Laboratory CV[ (B18/B11)*100]	        3.259
-    */
-    private double mean;
-    private double sr;
-    private double vb;
-    private double s1;
-
-    private double cvr;
-    private double cv1;
-    private double n;
-    private int decimal;
-
-    private double allowableCvr;
-    private double allowableCv1;
-    private double allowableSr;
-    private double allowableS1;
-
-    public PrecisionEP15(double[][] data, double allowableCvr, double allowableCv1, int decimal) {
-        this.data = data;
-        this.n = data[0].length;
-        this.allowableCvr = allowableCvr;
-        this.allowableCv1 = allowableCv1;
-        this.decimal = decimal;
-        calculate();
-    }
+import java.util.*;
 
-    public double getSr() {
-        return sr;
-    }
+public class PrecisionEP15 extends PVModel {
 
-    public double getVb() {
-        return vb;
-    }
+    private List<Item> items = new ArrayList<>(); //[day][replicate]
 
-    public double getMean() {
-        return mean;
-    }
+    private String[] specimensName;
 
-    public void setMean(double mean) {
-        this.mean = mean;
+    public PrecisionEP15(String[] specimensName, int decimal) {
+        this.specimensName = specimensName;
+        this.setScale(decimal);
     }
 
-    public void setSr(double sr) {
-        this.sr = sr;
+    public void buildItem(String name,double[][] data, double allowableCvr, double allowableCv1 ){
+        items.add(new Item(name,data,allowableCvr,allowableCv1));
     }
 
-    public void setVb(double vb) {
-        this.vb = vb;
-    }
 
-    public double getS1() {
-        return s1;
-    }
+    @Override
+    public TableDTO buildDataTableDTO() {
+        String[] h = new String[specimensName.length+1];
+        Map<String,String[]> child = new HashMap<>();
+        String[] c = new String[items.get(0).data[0].length ];
+        for (int i = 0; i < c.length ; i++) {
+            c[i] = String.format("重复 %d",(i+1));
+        }
+        h[0] = "天数";
+        for (int i = 0; i < specimensName.length; i++) {
+            h[1+i] = specimensName[i];
+            child.put(h[i+1],c);
+        }
+        TableDTO table = new TableDTO();
+        table.buildHeader(h,child);
 
-    public void setS1(double s1) {
-        this.s1 = s1;
-    }
+        List<double[]> temp = new ArrayList<>();
+        double[] first = new double[items.get(0).data.length];
+        for (int i = 0; i <items.get(0).data.length; i++) {
+            first[i] = i+1;
+        }
+        temp.add(first);
+        for (int i = 0; i < specimensName.length; i++) {
+            temp.addAll(Arrays.<double[]>asList(transposeMatrix(items.get(i).data)));
+        }
 
-    public double getCvr() {
-        return cvr;
-    }
+        double[][] toArray = temp.toArray(new double[0][0]);
+        table.buildData(transposeMatrix(toArray),getScale());
+        return table;
 
-    public void setCvr(double cvr) {
-        this.cvr = cvr;
     }
 
-    public double getCv1() {
-        return cv1;
+    @Override
+    public Map<String, TableDTO> buildReportTableDTO() {
+        Map<String, TableDTO> reports = new HashMap<>();
+        for (Item item : items) {
+            reports.putAll(buildTable1DTO(item));
+        }
+        return reports;
     }
 
-    public void setCv1(double cv1) {
-        this.cv1 = cv1;
+    private Map<String, TableDTO> buildTable1DTO(Item item) {
+        Map<String, TableDTO> reports = new HashMap<>();
+        TableDTO table = new TableDTO();
+        String[][] data = new String[8][2];
+
+        data[0] =new String[]{"总均值" , format(item.mean)};
+        data[1] =new String[]{"批内方差 (V<sub>r</sub>)" , format(item.vr)};
+        data[2] =new String[]{"批内标准差 (S<sub>r</sub>)" , format(item.sr)};
+        data[3] =new String[]{"批内变异系数 (CV<sub>r</sub>)" , format(item.cvr)};
+        data[4] =new String[]{"",""};
+        data[5] =new String[]{"批间方差 (V<sub>b</sub>)" , format(item.vb)};
+//        data[4] =new String[]{"批间标准差 (S<sub>b</sub>)" , format(item.sb)};
+        data[6] =new String[]{"实验室内标准差 (S<sub>1</sub>)" , format(item.s1)};
+        data[7] =new String[]{"实验室变异系数 (CV)" , format(item.cv1)};
+        table.buildData(data);
+        reports.put(item.name,table);
+        return  reports;
     }
 
 
-    public double getAllowableCvr() {
-        return allowableCvr;
-    }
+    class Item {
+
+        private double[][] data;
+        private String name;
+
+        /*
+
+            Number of replicates 	3
+            Number of days				5
+            A       B       C       D       E           F       G
+                    Rep 1	Rep 2	Rep 3	Run mean	Run SD	Variance
+        5   Day 1	3.3	    3.23	3.43	3.320	    0.101	0.010
+        6   Day 2	3.21	3.45	3.42	3.360	    0.131	0.017
+        7   Day 3	3.21	3.24	3.45	3.300	    0.131	0.017
+        8   Day 4	3.5	    3.45	3.51	3.487	    0.032	0.001
+        9   Day 5	3.33	3.45	3.32	3.367	    0.072	0.005
+
+        11  Over all mean [ Average E5:E9]	        3.367       总均值
+        12  Within run variance Vr [ average G5:G9]	0.010
+        13 Within run SD [SQRT(B12)]	            0.101       批内标准差(Sr)
+        14  Between run SD [SD(E5:E9)]	            0.073
+        15  Between run variance Vb [B14*B14]	    0.005       批间方差
+        16  Ratio Vr/Vb  [+B12/B15]	                1.928
+        17  Total variance [((B2-1)/B2)*B12+B15]	0.012
+        18  Laboratory SD [SQRT B17]	            0.110       室内标准差
+        19  Laboratory CV[ (B18/B11)*100]	        3.259
+        */
+        private double mean;
+        private double sr;
+        private double vb;
+        private double s1;
+
+        private double cvr;
+        private double cv1;
+        private double n;
+
+
+        private double allowableCvr;
+        private double allowableCv1;
+        private double allowableSr;
+        private double allowableS1;
+        private double vr;
+        private double sb;
+
+        public Item(String name,double[][] data, double allowableCvr, double allowableCv1) {
+            this.name = name;
+            this.data = data;
+            this.n = data[0].length;
+            this.allowableCvr = allowableCvr;
+            this.allowableCv1 = allowableCv1;
+            calculate();
+        }
 
-    public void setAllowableCvr(double allowableCvr) {
-        this.allowableCvr = allowableCvr;
-    }
+        public double getSr() {
+            return sr;
+        }
 
-    public double getAllowableCv1() {
-        return allowableCv1;
-    }
+        public double getVb() {
+            return vb;
+        }
 
-    public void setAllowableCv1(double allowableCv1) {
-        this.allowableCv1 = allowableCv1;
-    }
+        public double getMean() {
+            return mean;
+        }
 
-    public double getAllowableSr() {
-        return allowableSr;
-    }
+        public void setMean(double mean) {
+            this.mean = mean;
+        }
 
-    public void setAllowableSr(double allowableSr) {
-        this.allowableSr = allowableSr;
-    }
+        public void setSr(double sr) {
+            this.sr = sr;
+        }
 
-    public double getAllowableS1() {
-        return allowableS1;
-    }
+        public void setVb(double vb) {
+            this.vb = vb;
+        }
 
-    public void setAllowableS1(double allowableS1) {
-        this.allowableS1 = allowableS1;
-    }
+        public double getS1() {
+            return s1;
+        }
+
+        public void setS1(double s1) {
+            this.s1 = s1;
+        }
+
+        public double getCvr() {
+            return cvr;
+        }
+
+        public void setCvr(double cvr) {
+            this.cvr = cvr;
+        }
+
+        public double getCv1() {
+            return cv1;
+        }
+
+        public void setCv1(double cv1) {
+            this.cv1 = cv1;
+        }
+
+
+        public double getAllowableCvr() {
+            return allowableCvr;
+        }
+
+        public void setAllowableCvr(double allowableCvr) {
+            this.allowableCvr = allowableCvr;
+        }
+
+        public double getAllowableCv1() {
+            return allowableCv1;
+        }
+
+        public void setAllowableCv1(double allowableCv1) {
+            this.allowableCv1 = allowableCv1;
+        }
 
-    public void calculate() {
-        //批内标准差
+        public double getAllowableSr() {
+            return allowableSr;
+        }
+
+        public void setAllowableSr(double allowableSr) {
+            this.allowableSr = allowableSr;
+        }
+
+        public double getAllowableS1() {
+            return allowableS1;
+        }
+
+        public void setAllowableS1(double allowableS1) {
+            this.allowableS1 = allowableS1;
+        }
+
+        public void calculate() {
+            //批内标准差
 //        xValue[] vrs = Arrays.stream(data).map(SpecimensCalcVO::getVariance).toArray(xValue[]::new);
 //        double withinVr = xAverage.eval(vrs).getDoub();
 //        sr = Math.sqrt(withinVr);
-        double[] vrs = new double[data.length];
-        for (int i = 0; i < data.length; i++) {
-            vrs[i] = StatUtils.variance(data[i]);
-        }
-        double withinVr = StatUtils.mean(vrs);
-        sr = Math.sqrt(withinVr);
-        //总均值
+            double[] vrs = new double[data.length];
+            for (int i = 0; i < data.length; i++) {
+                vrs[i] = StatUtils.variance(data[i]);
+            }
+            vr = StatUtils.mean(vrs);
+            sr = Math.sqrt(vr);
+            //总均值
 //        xValue[] means = Arrays.stream(data).map(SpecimensCalcVO::getMean).toArray(xValue[]::new);
-        double[] means = new double[data.length];
-        for (int i = 0; i < data.length; i++) {
-            means[i] = StatUtils.mean(data[i]);
-        }
-        DescriptiveStatistics stat = new DescriptiveStatistics(means);
-        mean = stat.getMean();
-        //批间方差
-        double x = stat.getStandardDeviation();
-        vb = Math.pow(x, 2);
-
-        //室内标准差
-        double v = (n - 1) / n;
-        s1 = Math.sqrt(v * withinVr + vb);
-
-        cvr = (sr / mean) * 100;
-        cv1 = (s1 / mean) * 100;
-
-        //实验室允许不精密度
-        allowableSr = allowableCvr * mean / 100;
-        allowableS1 = allowableCv1 * mean / 100;
-
-        //format
-        allowableSr = format(allowableSr, decimal);
-        allowableS1 = format(allowableS1, decimal);
-        cv1 = format(cv1, decimal);
-        cvr = format(cvr, decimal);
-        vb = format(vb, decimal);
-        mean = format(mean, decimal);
-        sr = format(sr, decimal);
-        s1 = format(s1, decimal);
+            double[] means = new double[data.length];
+            for (int i = 0; i < data.length; i++) {
+                means[i] = StatUtils.mean(data[i]);
+            }
+            DescriptiveStatistics stat = new DescriptiveStatistics(means);
+            mean = stat.getMean();
+            //批间标准差
+            sb = stat.getStandardDeviation();
+            //批间方差
+            vb = Math.pow(sb, 2);
+
+            //室内标准差
+            double v = (n - 1) / n;
+            s1 = Math.sqrt(v * vr + vb);
+
+            cvr = (sr / mean) * 100;
+            cv1 = (s1 / mean) * 100;
+
+            //实验室允许不精密度
+            allowableSr = allowableCvr * mean / 100;
+            allowableS1 = allowableCv1 * mean / 100;
+
+
+        }
     }
 
     public static void main(String[] args) {
         double[][] data = {{3.3, 3.23, 3.43}, {3.21, 3.45, 3.42}, {3.21, 3.24, 3.45}, {3.5, 3.45, 3.51}, {3.33, 3.45, 3.32}};
-        PrecisionEP15 precisionEP15 = new PrecisionEP15(data, 0, 0, 3);
-
+        PrecisionEP15 precisionEP15 = new PrecisionEP15(new String[]{"test 1","test 2"},3);
+        precisionEP15.buildItem("test 1",data, 0, 0 );
+        precisionEP15.buildItem("test 2",data, 0, 0 );
+        TableDTO tableDTO = precisionEP15.buildDataTableDTO();
+        Map<String, TableDTO> stringTableDTOMap = precisionEP15.buildReportTableDTO();
+//        ChiSquaredDistribution x2 = new ChiSquaredDistribution( 10 );
+//        double result = x2.inverseCumulativeProbability(1 - 0.05/2);//level
         System.out.println(precisionEP15);
     }
 }

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

@@ -1,9 +1,13 @@
 package com.lc.ibps.components.verification.model2;
 
+import com.lc.ibps.components.verification.report.TableDTO;
 import org.apache.commons.math3.stat.StatUtils;
 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
 
-public class TruenessEP15Patient extends CalcVO {
+import java.util.HashMap;
+import java.util.Map;
+
+public class TruenessEP15Patient extends PVModel {
     //多个样本均值 y
     private double[] y;
     //样本的标示值/理论值 x
@@ -24,7 +28,7 @@ public class TruenessEP15Patient extends CalcVO {
     private double lvl;//Lower verification limit
     private double sdClaim;//SD assigned value
 
-    public TruenessEP15Patient(double[][] data, double sdClaim, double t) {
+    public TruenessEP15Patient(double[][] data, double sdClaim, double t, int decimal) {
         this.y = data[0];
         this.x = data[1];
         meanX = StatUtils.mean(x);
@@ -36,6 +40,7 @@ public class TruenessEP15Patient extends CalcVO {
         }
         this.n = this.y.length;
         this.sdClaim = sdClaim;
+        this.setScale(decimal);
         calculate();
     }
 
@@ -150,13 +155,50 @@ public class TruenessEP15Patient extends CalcVO {
     }
     public double[][] getData(){
 
-        double[][] d = new double[y.length][4];
+        double[][] d = new double[y.length][5];
         for (int i = 0; i<y.length;i++){
-            d[i][0] = y[i];
-            d[i][1] = x[i];
-            d[i][2] = yx[i];
-            d[i][3] = yxb[i];
+            d[i][0] = i+1;
+            d[i][1] = y[i];
+            d[i][2] = x[i];
+            d[i][3] = yx[i];
+            d[i][4] = yxb[i];
         }
         return d;
     }
+
+    @Override
+    public TableDTO buildDataTableDTO() {
+        TableDTO table = new TableDTO();
+        String[] header = {"次数", "Y (实验方法)", "X (比较方法)", "Y<sub>i</sub>-X<sub>i</sub>", "(Y<sub>i</sub>-X<sub>i</sub>-B)"};
+        table.buildHeader(header);
+        table.buildData(getData(),getScale());
+        return table;
+    }
+
+    @Override
+    public Map<String, TableDTO> buildReportTableDTO() {
+        Map<String, TableDTO> reports = new HashMap<>();
+        TableDTO table = new TableDTO();
+        String[][] data = new String[8][2];
+
+        data[0] =new String[]{"Y均值" , format(meanY)};
+        data[1] =new String[]{"X均值" , format(meanX)};
+        data[2] =new String[]{"差值(B)" , format(bias)};
+        data[3] =new String[]{"差值标准差(SD<sub>diff</sub>)" , format(sdDiff)};
+        data[4] =new String[]{"置信区间上限" , format(ucl)};
+        data[5] =new String[]{"置信区间下限" , format(lcl)};
+        data[6] =new String[]{"验证区间上限" , format(uvl)};
+        data[7] =new String[]{"验证区间下限" , format(lvl)};
+//        data[1] =new String[]{"批内方差 (V<sub>r</sub>)" , format(item.vr)};
+//        data[2] =new String[]{"批内标准差 (S<sub>r</sub>)" , format(item.sr)};
+//        data[3] =new String[]{"批内变异系数 (CV<sub>r</sub>)" , format(item.cvr)};
+//        data[4] =new String[]{"",""};
+//        data[5] =new String[]{"批间方差 (V<sub>b</sub>)" , format(item.vb)};
+////        data[4] =new String[]{"批间标准差 (S<sub>b</sub>)" , format(item.sb)};
+//        data[6] =new String[]{"实验室内标准差 (S<sub>1</sub>)" , format(item.s1)};
+//        data[7] =new String[]{"实验室变异系数 (CV)" , format(item.cv1)};
+        table.buildData(data);
+        reports.put("表1",table);
+        return reports;
+    }
 }

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

@@ -1,152 +1,232 @@
 package com.lc.ibps.components.verification.model2;
 
+import com.lc.ibps.components.verification.report.TableDTO;
 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
 
-public class TruenessRefernece extends CalcVO {
-
-    private double[] data;
-
-    private double target;
-    private double mean;
-    private double sd;
-    private double se;
-    private double ucl;//Upper confidence limit
-    private double lcl;//Lower confidence limit
-    private double uvl;//Upper verification limit
-    private double lvl;//Lower verification limit
-
-    private double t;//t critical
-    private double sdClaim;//SD assigned value
-
-    public TruenessRefernece(double[] data, double target, double sdClaim, double t){
-        this.data = data;
-        this.target = target;
-        this.sdClaim = sdClaim;
-        if(t == 0){
-            this.t = getT(data.length-1,0.01);
-        }else {
-            this.t = t;
+import java.util.*;
+
+public class TruenessRefernece extends PVModel {
+
+    private List<Item> items = new ArrayList<>();
+    private String[] specimensName;
+    public TruenessRefernece(String[] specimensName, int decimal){
+        this.specimensName = specimensName;
+        this.setScale(decimal);
+    }
+
+    public void buildItem(String name,double[][] data, double target, double sdClaim, double t){
+        items.add(new Item(name,data,target,sdClaim,t));
+    }
+    class Item {
+        private String name;
+        private double[][] data;
+        private double[] calcData;
+
+        private double target;
+        private double mean;
+        private double sd;
+        private double se;
+        private double ucl;//Upper confidence limit
+        private double lcl;//Lower confidence limit
+        private double uvl;//Upper verification limit
+        private double lvl;//Lower verification limit
+
+        private double t;//t critical
+        private double sdClaim;//SD assigned value
+
+        public Item(String name,double[][] data, double target, double sdClaim, double t) {
+            this.name = name;
+            this.data = data;
+            int i = 0;
+            this.calcData = new double[data.length * data[0].length];
+            for (double[] d : data) {
+                for (double dd: d){
+                    calcData[i++] = dd;
+                }
+            }
+            this.target = target;
+            this.sdClaim = sdClaim;
+            if (t == 0) {
+                this.t = PVModel.getT(data.length - 1, 0.01);
+            } else {
+                this.t = t;
+            }
+            calculate();
         }
-        calculate();
-    }
 
-  /*
-  Reference assigned value 50mg/dl
-
-    Day 1	Replicate 1	48
-            Replicate 2	46
-    Day 2	Replicate 1	48
-            Replicate 2	47
-    Day 3	Replicate 1	46
-            Replicate 2	46
-    Day 4	Replicate 1	48
-            Replicate 2	47
-    Day 5	Replicate 1	47
-            Replicate 2	46
-
-    Count	    Count(C3:c12)	    10
-    SQRT        count		        3.16227766
-    Mean	    Average C3 :12	    46.9
-    SD	        SD(C3:C12)	        0.875595036
-    SE of mean                                      C17/SQRT14		0.276887462
-    t critical 		                                                3.25
-    Upper confidence limit	                        c16 +c19*c18	47.79988425
-    Lower confidence limit	                        c16 -c19*c18	46.00011575
-    SD assigned value 		                                        0.15
-    Combined SD uncertainity SE square + SD assign value square		0.099166667
-    Combined SD uncertaininty SQRT (SE square + SD assign)		    0.314907394
-    Upper verification limit		                                47.92344903
-    Lower verification limit		                                45.87655097
-*/
-    public void calculate() {
-        DescriptiveStatistics stat = new DescriptiveStatistics(data);
-        mean = stat.getMean();
-        sd = stat.getStandardDeviation();
-        se = sd / Math.sqrt(data.length);
-        ucl = mean + t * se;
-        lcl = mean - t * se;
-        double combinedSD = Math.sqrt(se * se + sdClaim * sdClaim);
-        uvl = mean + t * combinedSD;
-        lvl = mean - t * combinedSD;
-    }
+        /*
+        Reference assigned value 50mg/dl
+
+          Day 1	Replicate 1	48
+                  Replicate 2	46
+          Day 2	Replicate 1	48
+                  Replicate 2	47
+          Day 3	Replicate 1	46
+                  Replicate 2	46
+          Day 4	Replicate 1	48
+                  Replicate 2	47
+          Day 5	Replicate 1	47
+                  Replicate 2	46
+
+          Count	    Count(C3:c12)	    10
+          SQRT        count		        3.16227766
+          Mean	    Average C3 :12	    46.9
+          SD	        SD(C3:C12)	        0.875595036
+          SE of mean                                      C17/SQRT14		0.276887462
+          t critical 		                                                3.25
+          Upper confidence limit	                        c16 +c19*c18	47.79988425
+          Lower confidence limit	                        c16 -c19*c18	46.00011575
+          SD assigned value 		                                        0.15
+          Combined SD uncertainity SE square + SD assign value square		0.099166667
+          Combined SD uncertaininty SQRT (SE square + SD assign)		    0.314907394
+          Upper verification limit		                                47.92344903
+          Lower verification limit		                                45.87655097
+      */
+        public void calculate() {
+            DescriptiveStatistics stat = new DescriptiveStatistics(calcData);
+            mean = stat.getMean();
+            sd = stat.getStandardDeviation();
+            se = sd / Math.sqrt(calcData.length);
+            ucl = mean + t * se;
+            lcl = mean - t * se;
+            double combinedSD = Math.sqrt(se * se + sdClaim * sdClaim);
+            uvl = mean + t * combinedSD;
+            lvl = mean - t * combinedSD;
+        }
 
-    public double getTarget() {
-        return target;
-    }
+        public double getTarget() {
+            return target;
+        }
 
-    public void setTarget(double target) {
-        this.target = target;
-    }
+        public void setTarget(double target) {
+            this.target = target;
+        }
 
-    public double getMean() {
-        return mean;
-    }
+        public double getMean() {
+            return mean;
+        }
 
-    public void setMean(double mean) {
-        this.mean = mean;
-    }
+        public void setMean(double mean) {
+            this.mean = mean;
+        }
 
-    public double getSd() {
-        return sd;
-    }
+        public double getSd() {
+            return sd;
+        }
 
-    public void setSd(double sd) {
-        this.sd = sd;
-    }
+        public void setSd(double sd) {
+            this.sd = sd;
+        }
 
-    public double getSe() {
-        return se;
-    }
+        public double getSe() {
+            return se;
+        }
 
-    public void setSe(double se) {
-        this.se = se;
-    }
+        public void setSe(double se) {
+            this.se = se;
+        }
 
-    public double getUcl() {
-        return ucl;
-    }
+        public double getUcl() {
+            return ucl;
+        }
 
-    public void setUcl(double ucl) {
-        this.ucl = ucl;
-    }
+        public void setUcl(double ucl) {
+            this.ucl = ucl;
+        }
 
-    public double getLcl() {
-        return lcl;
-    }
+        public double getLcl() {
+            return lcl;
+        }
 
-    public void setLcl(double lcl) {
-        this.lcl = lcl;
-    }
+        public void setLcl(double lcl) {
+            this.lcl = lcl;
+        }
 
-    public double getUvl() {
-        return uvl;
-    }
+        public double getUvl() {
+            return uvl;
+        }
 
-    public void setUvl(double uvl) {
-        this.uvl = uvl;
-    }
+        public void setUvl(double uvl) {
+            this.uvl = uvl;
+        }
 
-    public double getLvl() {
-        return lvl;
-    }
+        public double getLvl() {
+            return lvl;
+        }
 
-    public void setLvl(double lvl) {
-        this.lvl = lvl;
-    }
+        public void setLvl(double lvl) {
+            this.lvl = lvl;
+        }
 
-    public double getT() {
-        return t;
-    }
+        public double getT() {
+            return t;
+        }
 
-    public void setT(double t) {
-        this.t = t;
+        public void setT(double t) {
+            this.t = t;
+        }
+
+        public double getSdClaim() {
+            return sdClaim;
+        }
+
+        public void setSdClaim(double sdClaim) {
+            this.sdClaim = sdClaim;
+        }
     }
+    @Override
+    public TableDTO buildDataTableDTO() {
+        String[] h = new String[specimensName.length+1];
+        Map<String,String[]> child = new HashMap<>();
+        String[] c = new String[items.get(0).data[0].length ];
+        for (int i = 0; i < c.length ; i++) {
+            c[i] = String.format("重复 %d",(i+1));
+        }
+        h[0] = "天数";
+        for (int i = 0; i < specimensName.length; i++) {
+            h[1+i] = specimensName[i];
+            child.put(h[i+1],c);
+        }
+        TableDTO table = new TableDTO();
+        table.buildHeader(h,child);
+
+        List<double[]> temp = new ArrayList<>();
+        double[] first = new double[items.get(0).data.length];
+        for (int i = 0; i <items.get(0).data.length; i++) {
+            first[i] = i+1;
+        }
+        temp.add(first);
+        for (int i = 0; i < specimensName.length; i++) {
+            temp.addAll(Arrays.<double[]>asList(transposeMatrix(items.get(i).data)));
+        }
 
-    public double getSdClaim() {
-        return sdClaim;
+        double[][] toArray = temp.toArray(new double[0][0]);
+        table.buildData(transposeMatrix(toArray),getScale());
+        return table;
     }
 
-    public void setSdClaim(double sdClaim) {
-        this.sdClaim = sdClaim;
+    @Override
+    public Map<String, TableDTO> buildReportTableDTO() {
+        Map<String, TableDTO> reports = new HashMap<>();
+        for (Item item : items) {
+            reports.putAll(buildTable1DTO(item));
+        }
+        return reports;
+    }
+
+    private Map<String, TableDTO> buildTable1DTO(Item item) {
+        Map<String, TableDTO> reports = new HashMap<>();
+        TableDTO table = new TableDTO();
+        String[][] data = new String[6][2];
+
+        data[0] =new String[]{"均值" , format(item.mean)};
+        data[1] =new String[]{"标准差" , format(item.sd)};
+        data[2] =new String[]{"置信区间上限" , format(item.ucl)};
+        data[3] =new String[]{"置信区间下限" , format(item.lcl)};
+        data[4] =new String[]{"验证区间上限" , format(item.uvl)};
+        data[5] =new String[]{"验证区间下限" , format(item.lvl)};
+        table.buildData(data);
+        reports.put(item.name,table);
+        return  reports;
     }
 }

+ 2 - 2
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/regression/PolynomialRegression.java

@@ -1,6 +1,6 @@
 package com.lc.ibps.components.verification.regression;
 
-import com.lc.ibps.components.verification.model2.CalcVO;
+import com.lc.ibps.components.verification.model2.PVModel;
 import org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression;
 
 import java.util.ArrayList;
@@ -47,7 +47,7 @@ public class PolynomialRegression extends Regression{
         for (int i = 0; i < getParameters().length; i++) {
             tValues[i] = getParameters()[i] / getStdErrors()[i];
         }
-        t = CalcVO.getT(getDfDependent(), 0.05);
+        t = PVModel.getT(getDfDependent(), 0.05);
         if (getParameters().length >2) {
             for (int i = 2; i < getParameters().length; i++) {
                 if(tValues[i] > 0){

+ 0 - 34
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/ReportDataDTO.java

@@ -1,46 +1,12 @@
 package com.lc.ibps.components.verification.report;
 
-import com.lc.ibps.components.verification.model.InspectionConfigVO;
-import com.lc.ibps.components.verification.model2.CalcVO;
-
-import java.util.HashMap;
 import java.util.Map;
 
 public class ReportDataDTO {
 
-    private InspectionConfigVO config;
-
-    private Map<String, CalcVO> reportData = new HashMap<>();
-
-    private Map<String, double[]> data = new HashMap<>();
-
     private TableDTO   dataDTO;
     private Map<String, TableDTO> reportDataDTO;
 
-    public InspectionConfigVO getConfig() {
-        return config;
-    }
-
-    public void setConfig(InspectionConfigVO config) {
-        this.config = config;
-    }
-
-    public Map<String, double[]> getData() {
-        return data;
-    }
-
-    public void setData(Map<String, double[]> data) {
-        this.data = data;
-    }
-
-    public Map<String, CalcVO> getReportData() {
-        return reportData;
-    }
-
-    public void setReportData(Map<String, CalcVO> reportData) {
-        this.reportData = reportData;
-    }
-
     public TableDTO getDataDTO() {
         return dataDTO;
     }

+ 2 - 5
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/ReportFactory.java

@@ -6,11 +6,8 @@ public class ReportFactory {
 
     public static ReportDataDTO build(PVItemBuilder builder){
         ReportDataDTO data = new ReportDataDTO();
-
-        data.setConfig(builder.getConfig());
-
-        data.setDataDTO(builder.getCalcVO().buildDataTableDTO());
-        data.setReportDataDTO(builder.getCalcVO().buildReportTableDTO());
+        data.setDataDTO(builder.getPvModel().buildDataTableDTO());
+        data.setReportDataDTO(builder.getPvModel().buildReportTableDTO());
 //        if(item.getConfig().getName().toLowerCase().contains("ep15")){
 //        } else{
 ////            data.setData(item.getRecord());

+ 28 - 8
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/TableDTO.java

@@ -1,26 +1,46 @@
 package com.lc.ibps.components.verification.report;
 
-import com.lc.ibps.components.verification.model2.CalcVO;
+import com.lc.ibps.components.verification.model2.PVModel;
 
 import java.util.HashMap;
 import java.util.Map;
 
 public class TableDTO {
 
-    private Map<String, String>[] header;
+    private Map<String, Object>[] header;
 
     private Map<String, String>[] list;
 
-    public void buildHeader(String[] h){
+    public void buildHeader(String[] h, Map<String,String[]> child){
         header = new Map[h.length];
+        int k = 0;
         for (int i = 0; i < h.length; i++) {
-            HashMap<String, String> m = new HashMap<>();
+            HashMap<String, Object> m = new HashMap<>();
             m.put("label",h[i]);
-            m.put("prop",String.valueOf((char)(65+i)));
+
+            if(child != null && child.containsKey(h[i])){
+                m.put("prop","");
+                String[] c = child.get(h[i]);
+
+                Map<String, Object>[] cm = new Map[c.length];
+                for (int j = 0; j < c.length; j++) {
+                    HashMap<String, Object> mm = new HashMap<>();
+                    mm.put("label",c[j]);
+                    mm.put("prop",String.valueOf((char)(65+k++)));
+                    cm[j] = mm;
+                }
+                m.put("children",cm);
+            }else{
+                m.put("prop",String.valueOf((char)(65+k++)));
+            }
             header[i] = m;
         }
     }
 
+    public void buildHeader(String[] h ){
+        buildHeader(h,null);
+    }
+
     public void buildData(String[][] data){
         list = new Map[data.length];
         for (int i = 0; i < data.length; i++) {
@@ -37,17 +57,17 @@ public class TableDTO {
         for (int i = 0; i < data.length; i++) {
             HashMap<String, String> m = new HashMap<>();
             for (int j = 0; j < data[0].length; j++) {
-                m.put(String.valueOf((char)(65+j)), String.valueOf(CalcVO.format( data[i][j],scale)));
+                m.put(String.valueOf((char)(65+j)), String.valueOf(PVModel.format( data[i][j],scale)));
             }
             list[i] = m;
         }
     }
 
-    public Map<String, String>[] getHeader() {
+    public Map<String, Object>[] getHeader() {
         return header;
     }
 
-    public void setHeader(Map<String, String>[] header) {
+    public void setHeader(Map<String, Object>[] header) {
         this.header = header;
     }
 

+ 2 - 1
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/service/impl/PerformanceVerificationServiceImpl.java

@@ -12,6 +12,7 @@ import com.lc.ibps.components.verification.model2.PVItemBuilder;
 import com.lc.ibps.components.verification.report.ReportDataDTO;
 import com.lc.ibps.components.verification.report.ReportFactory;
 import com.lc.ibps.components.verification.service.PerformanceVerificationService;
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
@@ -76,7 +77,7 @@ public class PerformanceVerificationServiceImpl implements PerformanceVerificati
         InspectionConfigVO config = JSON.parseObject(shiYanCanShu, InspectionConfigVO.class);
         config.setName(experimentalPo.getFangAnLeiXing());
         config.setDecimal(Integer.valueOf(experimentalPo.getBaoLiuXiaoShu()));
-        if(config.getSpecimensName() == null){
+        if(ArrayUtils.isEmpty(config.getSpecimensName())){
             String[] names = new String[config.getSpecimensNum()];
             for (int i = 0; i < config.getSpecimensNum(); i++) {
                 names[i] = String.format("水平 %d",i+1);