Explorar o código

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

liyuan hai 1 ano
pai
achega
74395efe14
Modificáronse 13 ficheiros con 279 adicións e 12 borrados
  1. 39 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/LinearRangeEP6A.java
  2. 2 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PVModel.java
  3. 6 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/PrecisionEP15.java
  4. 6 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/TruenessEP15Patient.java
  5. 6 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/model2/TruenessRefernece.java
  6. 18 1
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/ChartDTO.java
  7. 1 1
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/EchartsFreemarkerUtils.java
  8. 10 0
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/ReportDataDTO.java
  9. 1 4
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/ReportFactory.java
  10. 6 6
      ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/TableDTO.java
  11. 59 0
      ibps-provider-root/modules/provider-business/src/main/resources/echarts/scatter/linearRegression.ftl
  12. 27 0
      ibps-provider-root/modules/provider-business/src/main/resources/echarts/scatter/linesForRange.ftl
  13. 98 0
      ibps-provider-root/modules/provider-business/src/main/resources/echarts/scatter/polynomialRegression.ftl

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

@@ -3,6 +3,8 @@ package com.lc.ibps.components.verification.model2;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 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 org.apache.commons.lang3.ArrayUtils;
@@ -159,6 +161,42 @@ public class LinearRangeEP6A extends PVModel {
         return reports;
     }
 
+    @Override
+    public Map<String, ChartDTO> buildChartDTO() {
+        Map<String,ChartDTO> charts = new HashMap<>();
+        charts.put("图1: 线性实验",buildChart1DTO());
+        charts.put("图2: 线性评价差值点图",buildChart2DTO());
+        return charts;
+    }
+
+    private ChartDTO buildChart2DTO() {
+        ChartDTO chartDTO = new ChartDTO();
+        double[][] data = new double[targetValues.length][2];
+        for (int i = 0; i < data.length; i++) {
+            data[i] = new double[]{i+1,diffs[1][i]};
+        }
+        chartDTO.setData(data);
+        final HashMap<String, Object> config = new HashMap<>();
+        config.put("yAxisUp",0.1);
+        config.put("yAxisLow",-0.1);
+
+        chartDTO.setOption(EchartsFreemarkerUtils.generate("/scatter/linesForRange.ftl",config));
+        return chartDTO;
+    }
+
+    private ChartDTO buildChart1DTO() {
+        ChartDTO chartDTO = new ChartDTO();
+        double[][] data = new double[targetValues.length][2];
+        for (int i = 0; i < data.length; i++) {
+            data[i] = new double[]{targetValues[i],means[i]};
+        }
+        chartDTO.setData(data);
+
+
+        chartDTO.setOption(EchartsFreemarkerUtils.generate("/scatter/polynomialRegression.ftl",new HashMap<>()));
+        return chartDTO;
+    }
+
     private TableDTO buildTable1DTO(){
 
         TableDTO table = new TableDTO();
@@ -239,6 +277,7 @@ public class LinearRangeEP6A extends PVModel {
         LinearRangeEP6A ep6 = new LinearRangeEP6A(data, new double[]{0,24.09},1,3);
         TableDTO tableDTO = ep6.buildDataTableDTO();
         Map<String, TableDTO> stringTableDTOMap = ep6.buildReportTableDTO();
+        final Map<String, ChartDTO> stringChartDTOMap = ep6.buildChartDTO();
         ReportDataDTO report = new ReportDataDTO();
 
 

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

@@ -1,6 +1,7 @@
 package com.lc.ibps.components.verification.model2;
 
 import com.lc.ibps.components.verification.funcs.xValue;
+import com.lc.ibps.components.verification.report.ChartDTO;
 import com.lc.ibps.components.verification.report.TableDTO;
 import org.apache.commons.math3.distribution.ChiSquaredDistribution;
 import org.apache.commons.math3.distribution.TDistribution;
@@ -48,6 +49,7 @@ public abstract class PVModel {
 
     public abstract TableDTO buildDataTableDTO();
     public abstract Map<String, TableDTO> buildReportTableDTO();
+    public abstract Map<String, ChartDTO> buildChartDTO();
 
     public int getScale() {
         return scale;

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

@@ -1,5 +1,6 @@
 package com.lc.ibps.components.verification.model2;
 
+import com.lc.ibps.components.verification.report.ChartDTO;
 import com.lc.ibps.components.verification.report.TableDTO;
 import org.apache.commons.math3.stat.StatUtils;
 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
@@ -63,6 +64,11 @@ public class PrecisionEP15 extends PVModel {
         return reports;
     }
 
+    @Override
+    public Map<String, ChartDTO> buildChartDTO() {
+        return null;
+    }
+
     private Map<String, TableDTO> buildTable1DTO(Item item) {
         Map<String, TableDTO> reports = new HashMap<>();
         TableDTO table = new TableDTO();

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

@@ -1,5 +1,6 @@
 package com.lc.ibps.components.verification.model2;
 
+import com.lc.ibps.components.verification.report.ChartDTO;
 import com.lc.ibps.components.verification.report.TableDTO;
 import org.apache.commons.math3.stat.StatUtils;
 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
@@ -201,4 +202,9 @@ public class TruenessEP15Patient extends PVModel {
         reports.put("表1",table);
         return reports;
     }
+
+    @Override
+    public Map<String, ChartDTO> buildChartDTO() {
+        return null;
+    }
 }

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

@@ -1,5 +1,6 @@
 package com.lc.ibps.components.verification.model2;
 
+import com.lc.ibps.components.verification.report.ChartDTO;
 import com.lc.ibps.components.verification.report.TableDTO;
 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
 
@@ -214,6 +215,11 @@ public class TruenessRefernece extends PVModel {
         return reports;
     }
 
+    @Override
+    public Map<String, ChartDTO> buildChartDTO() {
+        return null;
+    }
+
     private Map<String, TableDTO> buildTable1DTO(Item item) {
         Map<String, TableDTO> reports = new HashMap<>();
         TableDTO table = new TableDTO();

+ 18 - 1
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/components/verification/report/ChartDTO.java

@@ -4,5 +4,22 @@ public class ChartDTO {
 
     private double[][] data;
     private String option;
-//    private
+
+    public double[][] getData() {
+        return data;
+    }
+
+    public void setData(double[][] data) {
+        this.data = data;
+    }
+
+    public String getOption() {
+        return option;
+    }
+
+    public void setOption(String option) {
+        this.option = option;
+    }
+
+    //    private
 }

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

@@ -33,7 +33,7 @@ public class EchartsFreemarkerUtils {
             Template template = configuration.getTemplate(templateFileName);
             template.process(data, writer);
             writer.flush();
-            return writer.getBuffer().toString();
+            return writer.getBuffer().toString().replaceAll( "\\s*|\t|\r|\n", "" );
         } catch (Exception e) {
         }
         return null;

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

@@ -7,6 +7,8 @@ public class ReportDataDTO {
     private TableDTO   dataDTO;
     private Map<String, TableDTO> reportDataDTO;
 
+    private Map<String,ChartDTO> chartDataDTO;
+
     public TableDTO getDataDTO() {
         return dataDTO;
     }
@@ -22,4 +24,12 @@ public class ReportDataDTO {
     public void setReportDataDTO(Map<String, TableDTO> reportDataDTO) {
         this.reportDataDTO = reportDataDTO;
     }
+
+    public Map<String, ChartDTO> getChartDataDTO() {
+        return chartDataDTO;
+    }
+
+    public void setChartDataDTO(Map<String, ChartDTO> chartDataDTO) {
+        this.chartDataDTO = chartDataDTO;
+    }
 }

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

@@ -8,10 +8,7 @@ public class ReportFactory {
         ReportDataDTO data = new ReportDataDTO();
         data.setDataDTO(builder.getPvModel().buildDataTableDTO());
         data.setReportDataDTO(builder.getPvModel().buildReportTableDTO());
-//        if(item.getConfig().getName().toLowerCase().contains("ep15")){
-//        } else{
-////            data.setData(item.getRecord());
-//        }
+        data.setChartDataDTO(builder.getPvModel().buildChartDTO());
         return  data;
     }
 }

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

@@ -9,7 +9,7 @@ public class TableDTO {
 
     private Map<String, Object>[] header;
 
-    private Map<String, String>[] list;
+    private Map<String, Object>[] list;
 
     public void buildHeader(String[] h, Map<String,String[]> child){
         header = new Map[h.length];
@@ -44,7 +44,7 @@ public class TableDTO {
     public void buildData(String[][] data){
         list = new Map[data.length];
         for (int i = 0; i < data.length; i++) {
-            HashMap<String, String> m = new HashMap<>();
+            HashMap<String, Object> m = new HashMap<>();
             for (int j = 0; j < data[0].length; j++) {
                 m.put(String.valueOf((char)(65+j)), data[i][j]);
             }
@@ -55,9 +55,9 @@ public class TableDTO {
     public void buildData(double[][] data,int scale){
         list = new Map[data.length];
         for (int i = 0; i < data.length; i++) {
-            HashMap<String, String> m = new HashMap<>();
+            HashMap<String, Object> m = new HashMap<>();
             for (int j = 0; j < data[0].length; j++) {
-                m.put(String.valueOf((char)(65+j)), String.valueOf(PVModel.format( data[i][j],scale)));
+                m.put(String.valueOf((char)(65+j)), PVModel.format( data[i][j],scale));
             }
             list[i] = m;
         }
@@ -71,11 +71,11 @@ public class TableDTO {
         this.header = header;
     }
 
-    public Map<String, String>[] getList() {
+    public Map<String, Object>[] getList() {
         return list;
     }
 
-    public void setList(Map<String, String>[] list) {
+    public void setList(Map<String, Object>[] list) {
         this.list = list;
     }
 }

+ 59 - 0
ibps-provider-root/modules/provider-business/src/main/resources/echarts/scatter/linearRegression.ftl

@@ -0,0 +1,59 @@
+{
+  dataset: [
+    {
+      source: data
+    },
+    {
+      transform: {
+        type: 'ecStat:regression'
+        // 'linear' by default.
+        // config: { method: 'linear', formulaOn: 'end'}
+      }
+    }
+  ],
+  title: {
+    text: 'Linear Regression',
+    subtext: 'By ecStat.regression',
+    sublink: 'https://github.com/ecomfe/echarts-stat',
+    left: 'center'
+  },
+  legend: {
+    bottom: 5
+  },
+  tooltip: {
+    trigger: 'axis',
+    axisPointer: {
+      type: 'cross'
+    }
+  },
+  xAxis: {
+    splitLine: {
+      lineStyle: {
+        type: 'dashed'
+      }
+    }
+  },
+  yAxis: {
+    splitLine: {
+      lineStyle: {
+        type: 'dashed'
+      }
+    }
+  },
+  series: [
+    {
+      name: 'scatter',
+      type: 'scatter'
+    },
+    {
+      name: 'line',
+      type: 'line',
+      datasetIndex: 1,
+      symbolSize: 0.1,
+      symbol: 'circle',
+      label: { show: true, fontSize: 16 },
+      labelLayout: { dx: -20 },
+      encode: { label: 2, tooltip: 1 }
+    }
+  ]
+}

+ 27 - 0
ibps-provider-root/modules/provider-business/src/main/resources/echarts/scatter/linesForRange.ftl

@@ -0,0 +1,27 @@
+{
+  xAxis: {},
+  yAxis: {},
+  series: [
+    {
+      data: data,
+      type: 'scatter',
+            markLine: {
+                symbol: ['none', 'none'],//去掉箭头
+                itemStyle: {
+                    normal: { lineStyle: { type: 'solid', color:'blue'}
+                    ,label: { show: false, position:'left' } }
+                },
+                data: [{
+                        name: 'Y 轴值为 100 的水平线',
+                        yAxis: ${yAxisUp},
+                         valueDim: 'close'
+                },{
+                        name: 'Y 轴值为 100 的水平线',
+                        yAxis: ${yAxisLow},
+                        // valueDim: 'close'
+                }
+                ]
+        }
+    }
+  ]
+}

+ 98 - 0
ibps-provider-root/modules/provider-business/src/main/resources/echarts/scatter/polynomialRegression.ftl

@@ -0,0 +1,98 @@
+{
+  dataset: [
+    {
+      source: data
+    },
+    {
+      transform: {
+        type: 'ecStat:regression',
+        config: {
+          method: 'polynomial',
+          order: 1
+        }
+      }
+    },
+    {
+      transform: {
+        type: 'ecStat:regression',
+        config: {
+          method: 'polynomial',
+          order: 2
+        }
+      }
+    }
+  ],
+  title: {
+    text: '18 companies net profit and main business income (million)',
+    subtext: 'By ecStat.regression',
+    sublink: 'https://github.com/ecomfe/echarts-stat',
+    left: 'center',
+    top: 16
+  },
+  tooltip: {
+    trigger: 'axis',
+    axisPointer: {
+      type: 'cross'
+    }
+  },
+  xAxis: {
+    splitLine: {
+      lineStyle: {
+        type: 'dashed'
+      }
+    },
+    splitNumber: 20
+  },
+  yAxis: {
+    min: -40,
+    splitLine: {
+      lineStyle: {
+        type: 'dashed'
+      }
+    }
+  },
+  series: [
+    {
+      name: 'scatter',
+      type: 'scatter'
+    },
+    {
+      name: 'line',
+      type: 'line',
+      smooth: true,
+      datasetIndex: 1,
+      symbolSize: 0.1,
+      symbol: 'circle',
+      label: {
+        show: true,
+        fontSize: 16
+      },
+      labelLayout: {
+        dx: -20
+      },
+      encode: {
+        label: 2,
+        tooltip: 1
+      }
+    },
+    {
+      name: 'line2',
+      type: 'line',
+      smooth: true,
+      datasetIndex: 2,
+      symbolSize: 0.1,
+      symbol: 'circle',
+      label: {
+        show: true,
+        fontSize: 16
+      },
+      labelLayout: {
+        dx: -20
+      },
+      encode: {
+        label: 2,
+        tooltip: 1
+      }
+    }
+  ]
+}