Ver código fonte

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

liyuan 2 anos atrás
pai
commit
8a71c449cb

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

@@ -0,0 +1,48 @@
+package com.lc.ibps.components.verification.excel;
+
+import org.apache.poi.ss.usermodel.Chart;
+import org.apache.poi.ss.usermodel.ClientAnchor;
+import org.apache.poi.ss.usermodel.Drawing;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.charts.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterSer;
+
+public class CreateExcelScatterChart {
+    public static void create(Sheet sheet) {
+
+
+        Drawing<?> drawing = sheet.createDrawingPatriarch();
+        ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, sheet.getLastRowNum() + 1, 6, sheet.getLastRowNum() + 16);
+
+        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(8, 8, 2, 15));
+        ChartDataSource<Number> ys = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(7, 7, 2, 15));
+
+        ScatterChartSeries chartSerie = data.addSerie(xs, ys);
+        chartSerie.setTitle("线性回归");
+        chart.plot(data, bottomAxis, leftAxis);
+
+        //set line properties of first scatter chart data serie to no fill:
+        CTScatterSer[] scatterChartSeries = ((XSSFChart) chart).getCTChart().getPlotArea().getScatterChartArray(0).getSerArray();
+        for (int i = 0; i < scatterChartSeries.length; i++) {
+            scatterChartSeries[i].addNewSpPr().addNewLn().addNewNoFill();
+            scatterChartSeries[i].addNewSmooth().setVal(true);
+        }
+//        ((XSSFChart) chart).getCTChart().getPlotArea().getScatterChartArray(0).getSerArray(0)
+//                .addNewTrendline()
+//                .addNewTrendlineType()
+//                .setVal(org.openxmlformats.schemas.drawingml.x2006.chart.STTrendlineType.LINEAR);
+    }
+}

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

@@ -2,6 +2,12 @@ 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;
@@ -10,12 +16,16 @@ 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;
 
     public void postHanderSheet(Sheet sheet, Collection<?> dataSet) {
+
+        boolean isChart = false;
         ExcelExportEntity entity = new ExcelExportEntity("公式计算", "statistic");
 
         Row row = sheet.createRow(sheet.getLastRowNum() + 1);
@@ -33,11 +43,15 @@ public class PVExcelExportReportServer extends ExcelExportServer {
             createStringCell(row, index++, "", getStyles(false, entity), null);
             if (func == FunctionEnum.LRE || func == FunctionEnum.R) {
                 createItemRow(sheet, entity, row, index, func);
+                isChart = true;
             } else {
                 createSpecimensRow(sheet, entity, row, index, func);
             }
         }
         createResultRow(sheet, entity, row);
+
+        if (isChart) CreateExcelScatterChart.create(sheet);
+
     }
 
     private void createResultRow(Sheet sheet, ExcelExportEntity entity, Row row) {

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

@@ -6,7 +6,12 @@ import com.lc.ibps.components.verification.model.InspectionConfigVO;
 import com.lc.ibps.components.verification.model.InspectionItemVO;
 import com.lc.ibps.components.verification.model.InspectionVO;
 import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.junit.Test;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
 
 import java.io.*;
 import java.time.LocalDate;
@@ -17,11 +22,11 @@ public class PVTest {
     @Test
     public void testExcelImport() throws FileNotFoundException {
 
-        InspectionConfigVO config = new InspectionConfigVO("批内精密度",1,2,
-                new String[]{"高溶度(R1)","低浓度(R2)"},10, LocalDate.now(),true);
+        InspectionConfigVO config = new InspectionConfigVO("批内精密度", 1, 2,
+                new String[]{"高溶度(R1)", "低浓度(R2)"}, 10, LocalDate.now(), true);
         InspectionItemVO item = new InspectionItemVO(config);
 
-        File file = new File(String.format("C:/tmp/%s.xlsx",config.getName()));
+        File file = new File(String.format("C:/tmp/%s.xlsx", config.getName()));
         FileInputStream in = new FileInputStream(file);
 
         item.importExcelRecord(in);
@@ -40,12 +45,12 @@ public class PVTest {
 //        InspectionConfigVO config = new InspectionConfigVO("正确度",5,2,
 //                new String[]{"L2","L4"},2, LocalDate.now(),true);
 
-        InspectionConfigVO config = new InspectionConfigVO("线性范围",1,7,
-                new String[]{"E8","E7","E6","E5","E4","E3","E2"},3, LocalDate.now(),true);
+        InspectionConfigVO config = new InspectionConfigVO("线性范围", 1, 7,
+                new String[]{"E8", "E7", "E6", "E5", "E4", "E3", "E2"}, 3, LocalDate.now(), true);
 
         InspectionItemVO item = new InspectionItemVO(config);
         Workbook workbook = item.exportExcelTemplate();
-        FileOutputStream fos = new FileOutputStream(String.format("C:/tmp/%s.xlsx",config.getName()));
+        FileOutputStream fos = new FileOutputStream(String.format("C:/tmp/%s.xlsx", config.getName()));
         workbook.write(fos);
         fos.close();
     }
@@ -81,13 +86,13 @@ public class PVTest {
 //        item3.importExcelRecord(in3);
 
         //线性范围
-        InspectionConfigVO config4 = new InspectionConfigVO("线性范围",1,7,
-                new String[]{"E8","E7","E6","E5","E4","E3","E2"},3, LocalDate.now(),true);
+        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.setTargetValue(new double[]{8.48,7.48,6.48,5.48,4.48,3.48,2.48});
+        config4.setFunc(new FunctionEnum[]{FunctionEnum.AVERAGE, FunctionEnum.TARGET, 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()));
+        File file4 = new File(String.format("C:/tmp/%sdata.xlsx", config4.getName()));
         FileInputStream in4 = new FileInputStream(file4);
         item4.importExcelRecord(in4);
 
@@ -100,10 +105,26 @@ public class PVTest {
         vo.getItem().add(item4);
 
         final Workbook workbook = vo.exportExcelReport();
-        FileOutputStream fos = new FileOutputStream(String.format("C:/tmp/%s.xlsx",vo.getName()));
+        FileOutputStream fos = new FileOutputStream(String.format("C:/tmp/%s.xlsx", vo.getName()));
         workbook.write(fos);
         fos.close();
 
 
     }
+
+    @Test
+    public void testChart() throws Exception {
+        FileInputStream fis = new FileInputStream("C:/tmp/TEST.xlsx");
+        XSSFWorkbook wb = new XSSFWorkbook(fis);
+        XSSFSheet sheet = wb.getSheetAt(0);
+        XSSFDrawing drawing = sheet.getDrawingPatriarch();
+        List<XSSFChart> charts = drawing.getCharts();
+        for (int i = 0; i < charts.size(); i++) {
+            XSSFChart chart = charts.get(i);
+            CTChart ctChart = chart.getCTChart();
+            System.out.println(ctChart);
+        }
+        fis.close();
+        wb.close();
+    }
 }