Explorar o código

[性能验证][task-1390] 各个指标中数据公式的计算和结论推导,线性范围

Li Yuan %!s(int64=2) %!d(string=hai) anos
pai
achega
ae31d9c959

+ 82 - 4
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/CreateExcelScatterChart.java

@@ -1,5 +1,6 @@
 package com.lc.ibps.components.verification.excel;
 
+import com.lc.ibps.components.poi.excel.entity.params.ExcelExportEntity;
 import com.lc.ibps.components.verification.funcs.xValue;
 import com.lc.ibps.components.verification.model.InspectionItemVO;
 import org.apache.poi.ss.usermodel.*;
@@ -10,9 +11,10 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.*;
 import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal;
 
 public class CreateExcelScatterChart {
-    public static void create(Sheet sheet, InspectionItemVO item) {
-
+    public static void createLRE(Sheet sheet, InspectionItemVO item) {
+        ExcelExportEntity entity = new ExcelExportEntity("图表", "chart");
         Row row = sheet.createRow(sheet.getLastRowNum() + 1);
+
         for (int i = 0; i < item.getItemCalcVO().getTargetValue().length; i++) {
             final xValue value = item.getItemCalcVO().getTargetValue()[i];
             Cell cell = row.createCell(i);
@@ -32,12 +34,13 @@ public class CreateExcelScatterChart {
         row.setZeroHeight(true);
 
         row = sheet.createRow(sheet.getLastRowNum() + 1);
+        row.setHeight((short) (entity.getHeight() * 50));
         Cell cell = row.createCell(0);
         cell.setCellValue("线性回归图");
         cell.setCellType(CellType.STRING);
 
         Drawing<?> drawing = sheet.createDrawingPatriarch();
-        ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, sheet.getLastRowNum() + 1, 6, sheet.getLastRowNum() + 16);
+        ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, sheet.getLastRowNum() + 1, 6, sheet.getLastRowNum() + 9);
 
         Chart chart = drawing.createChart(anchor);
         ChartLegend legend = chart.getOrCreateLegend();
@@ -74,10 +77,85 @@ public class CreateExcelScatterChart {
         final CTTrendline trendline = ctChart.getPlotArea().getScatterChartArray(0).getSerArray(0)
                 .addNewTrendline();
         trendline.addNewDispRSqr().setVal(true);
-        trendline.addNewIntercept().setVal(0.1767);
+        trendline.addNewIntercept().setVal(item.getItemCalcVO().getA().getDoub());
         trendline.addNewDispEq().setVal(true);
         trendline.addNewSpPr().addNewLn().addNewSolidFill().addNewSchemeClr().setVal(STSchemeColorVal.Enum.forInt(5));
         trendline.addNewTrendlineType()
                 .setVal(org.openxmlformats.schemas.drawingml.x2006.chart.STTrendlineType.LINEAR);
+
+        for (int i = 0; i < 8; i++) {
+
+            row = sheet.createRow(sheet.getLastRowNum() + 1);
+            row.setHeight((short) (entity.getHeight() * 50));
+        }
+    }
+
+    public static void createVarianceChart(Sheet sheet, InspectionItemVO item) {
+        ExcelExportEntity entity = new ExcelExportEntity("图表", "chart");
+        Row row = sheet.createRow(sheet.getLastRowNum() + 1);
+
+        for (int i = 0; i < item.getItemCalcVO().getTargetValue().length; i++) {
+            final xValue value = item.getItemCalcVO().getTargetValue()[i];
+            Cell cell = row.createCell(i);
+            cell.setCellValue(value.getDoub());
+            cell.setCellType(CellType.NUMERIC);
+        }
+        row.setZeroHeight(true);
+        int rowNum = row.getRowNum();
+
+        row = sheet.createRow(sheet.getLastRowNum() + 1);
+        for (int i = 0; i < item.getItemCalcVO().getSpecimensValue().length; i++) {
+            final xValue value = item.getItemCalcVO().getSpecimensValue()[i];
+            Cell cell = row.createCell(i);
+            cell.setCellValue(item.getRecord().get(item.getConfig().getSpecimensName()[i]).getRelDev().getDoub());
+            cell.setCellType(CellType.NUMERIC);
+        }
+        row.setZeroHeight(true);
+
+        row = sheet.createRow(sheet.getLastRowNum() + 1);
+        row.setHeight((short) (entity.getHeight() * 50));
+        Cell cell = row.createCell(0);
+        cell.setCellValue("差异图");
+        cell.setCellType(CellType.STRING);
+
+        Drawing<?> drawing = sheet.createDrawingPatriarch();
+        ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, sheet.getLastRowNum() + 1, 6, sheet.getLastRowNum() + 9);
+
+        Chart chart = drawing.createChart(anchor);
+        ChartLegend legend = chart.getOrCreateLegend();
+        legend.setPosition(LegendPosition.TOP_RIGHT);
+
+        ScatterChartData data = chart.getChartDataFactory().createScatterChartData();
+
+        ValueAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
+        ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
+
+        leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
+        bottomAxis.setCrosses(AxisCrosses.AUTO_ZERO);
+        ChartDataSource<Number> xs = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(rowNum, rowNum, 0, item.getConfig().getSpecimensNum()-1));
+        ChartDataSource<Number> ys = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(rowNum+1, rowNum+1, 0, item.getConfig().getSpecimensNum()-1));
+
+        ScatterChartSeries chartSeries = data.addSerie(xs, ys);
+        chartSeries.setTitle("差异图");
+        chart.plot(data, bottomAxis, leftAxis);
+
+        final CTChart ctChart = ((XSSFChart) chart).getCTChart();
+        ctChart.unsetLegend();
+        ctChart.getPlotVisOnly().setVal(false);
+        //set line properties of first scatter chart data serie to no fill:
+        CTScatterSer[] scatterChartSeries = ctChart.getPlotArea().getScatterChartArray(0).getSerArray();
+        for (int i = 0; i < scatterChartSeries.length; i++) {
+            scatterChartSeries[i].addNewSpPr().addNewLn().addNewNoFill();
+        }
+
+        for(CTValAx ax: ctChart.getPlotArea().getValAxList()){
+            ax.addNewMajorGridlines();
+        }
+
+        for (int i = 0; i < 8; i++) {
+
+            row = sheet.createRow(sheet.getLastRowNum() + 1);
+            row.setHeight((short) (entity.getHeight() * 50));
+        }
     }
 }

+ 13 - 11
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVExcelExportReportServer.java

@@ -2,12 +2,6 @@ package com.lc.ibps.components.verification.excel;
 
 import com.lc.ibps.components.poi.excel.entity.params.ExcelExportEntity;
 import com.lc.ibps.components.poi.excel.export.ExcelExportServer;
-import com.lc.ibps.components.poi.excel.graph.builder.ExcelChartBuildService;
-import com.lc.ibps.components.poi.excel.graph.constant.ExcelGraphElementType;
-import com.lc.ibps.components.poi.excel.graph.constant.ExcelGraphType;
-import com.lc.ibps.components.poi.excel.graph.entity.ExcelGraph;
-import com.lc.ibps.components.poi.excel.graph.entity.ExcelGraphDefined;
-import com.lc.ibps.components.poi.excel.graph.entity.ExcelGraphElement;
 import com.lc.ibps.components.verification.model.FunctionEnum;
 import com.lc.ibps.components.verification.model.InspectionItemVO;
 import com.lc.ibps.components.verification.model.ItemCalcVO;
@@ -16,9 +10,7 @@ import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.util.CellRangeAddress;
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
 
 public class PVExcelExportReportServer extends ExcelExportServer {
     private InspectionItemVO item;
@@ -50,7 +42,8 @@ public class PVExcelExportReportServer extends ExcelExportServer {
         }
         createResultRow(sheet, entity, row);
 
-        if (isChart) CreateExcelScatterChart.create(sheet,item);
+        if (isChart) CreateExcelScatterChart.createLRE(sheet, item);
+//        CreateExcelScatterChart.createVarianceChart(sheet, item);
 
     }
 
@@ -84,7 +77,11 @@ public class PVExcelExportReportServer extends ExcelExportServer {
             sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), index, i));
         }
         entity.setKey(getCellStyle(func));
-        createStringCell(row, index++, getCalcValue(func, item.getItemCalcVO()), getStyles(false, entity), null);
+        if(func == FunctionEnum.R) {
+            createDoubleCell(row, index++, getCalcValue(func, item.getItemCalcVO()), getStyles(false, entity), null);
+        }else {
+            createStringCell(row, index++, getCalcValue(func, item.getItemCalcVO()), getStyles(false, entity), null);
+        }
         for (int j = index; j <= i; j++) {
             createStringCell(row, index++, "0", getStyles(false, entity), null);
         }
@@ -119,7 +116,11 @@ public class PVExcelExportReportServer extends ExcelExportServer {
             case TARGET:
                 return specimensCalcVO.getTargetValue().toString();
             case ABSDEV:
-                return Double.toString(specimensCalcVO.calcAbsoluteDeviation());
+                return specimensCalcVO.getAbsDev().getStr();
+            case RVALUE:
+                return specimensCalcVO.getRvalue().getStr();
+            case RELDEV:
+                return specimensCalcVO.getRelDev().getStr();
             default:
                 return "";
         }
@@ -138,6 +139,7 @@ public class PVExcelExportReportServer extends ExcelExportServer {
 
     public String getCellStyle(FunctionEnum func) {
         switch (func) {
+            case RVALUE:
             case CV:
                 return "statistic-percent";
             case R:

+ 1 - 2
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/excel/PVTest.java

@@ -1,6 +1,5 @@
 package com.lc.ibps.components.verification.excel;
 
-import com.lc.ibps.components.poi.util.PoiPublicUtil;
 import com.lc.ibps.components.verification.model.FunctionEnum;
 import com.lc.ibps.components.verification.model.InspectionConfigVO;
 import com.lc.ibps.components.verification.model.InspectionItemVO;
@@ -89,7 +88,7 @@ public class PVTest {
         InspectionConfigVO config4 = new InspectionConfigVO("线性范围", 1, 7,
                 new String[]{"E8", "E7", "E6", "E5", "E4", "E3", "E2"}, 3, LocalDate.now(), true);
 
-        config4.setFunc(new FunctionEnum[]{FunctionEnum.AVERAGE, FunctionEnum.TARGET, FunctionEnum.LRE, FunctionEnum.R});
+        config4.setFunc(new FunctionEnum[]{FunctionEnum.AVERAGE, FunctionEnum.TARGET, FunctionEnum.ABSDEV,FunctionEnum.RELDEV,FunctionEnum.RVALUE, FunctionEnum.LRE, FunctionEnum.R});
         config4.setTargetValue(new double[]{8.48, 7.48, 6.48, 5.48, 4.48, 3.48, 2.48});
         InspectionItemVO item4 = new InspectionItemVO(config4);
         File file4 = new File(String.format("C:/tmp/%sdata.xlsx", config4.getName()));

+ 4 - 2
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/FunctionEnum.java

@@ -4,11 +4,13 @@ public enum FunctionEnum {
     SD("标准差(SD)"),
     AVERAGE("均值"),
     CV("变异系数(CV)"),
-    TARGET("靶值"),
-    ABSDEV("绝对偏差"),
+    TARGET("理论值/靶值"),
+    ABSDEV("绝对偏倚"),
+    RELDEV("相对偏倚"),
     A("截距(a)"),
     B("斜率(b)"),
     R("相关系数(r)"),
+    RVALUE("R值"),//检测均值/预期值×100%
     LRE("线性回归方程");
     private String text;
 

+ 30 - 3
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model/SpecimensCalcVO.java

@@ -24,6 +24,12 @@ public class SpecimensCalcVO {
     private xValue sd;
     //变异系数百分比 = sd/average
     private xValue cv;
+    //绝对偏倚  average - targetValue;
+    private xValue absDev;
+    //相对偏倚 = 绝对偏倚 / targetValue
+    private xValue relDev;
+    //检测均值对数/预期值对数×100%
+    private xValue rvalue;
     //靶值
     private Double targetValue;
 
@@ -55,13 +61,34 @@ public class SpecimensCalcVO {
             convertedData = xLog10.eval(data);
     }
 
-    public double calcAbsoluteDeviation() {
+    public xValue getAbsDev() {
+        if(absDev != null) return absDev;
         if (targetValue == null) {
-            return 0;
+            return new xValue();
         }
-        return targetValue - getAverage().getDoub();
+        absDev = new xValue( getAverage().getDoub() - targetValue );
+        return absDev;
     }
 
+    public xValue getRelDev() {
+        if(relDev != null) return relDev;
+        if (targetValue == null) {
+            return new xValue();
+        }
+        relDev = new xValue( getAbsDev().getDoub()/targetValue );
+        return relDev;
+    }
+    //检测均值/预期值×100%
+    public xValue getRvalue() {
+        if(rvalue != null) return rvalue;
+        if (targetValue == null) {
+            return new xValue();
+        }
+        rvalue = new xValue( getAverage().getDoub()/targetValue );
+        return rvalue;
+    }
+
+
     public xValue[] getData() {
         return data;
     }