|
|
@@ -1,11 +1,17 @@
|
|
|
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.TableDTO;
|
|
|
+import org.apache.commons.math3.stat.StatUtils;
|
|
|
import org.apache.commons.math3.stat.regression.SimpleRegression;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
public class LinearRangeAverageSlope extends PVModel {
|
|
|
|
|
|
@@ -14,15 +20,27 @@ public class LinearRangeAverageSlope extends PVModel {
|
|
|
private double slopeCI;//ConfidenceInterval
|
|
|
private double rSquare;
|
|
|
private double r;
|
|
|
+ private double[] targetValues;
|
|
|
+ private double[] means;
|
|
|
+ private double allowableR2;
|
|
|
|
|
|
public LinearRangeAverageSlope(double[][] data, InspectionConfigVO configVO) {
|
|
|
super(data, configVO);
|
|
|
+ this.targetValues = configVO.getTargetValue();
|
|
|
+ this.allowableR2 = configVO.getAllowableR2();
|
|
|
+ this.means = new double[data.length];
|
|
|
+ for (int i = 0; i < data.length; i++) {
|
|
|
+ means[i] = StatUtils.mean(data[i]);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void calculate() {
|
|
|
final SimpleRegression regression = new SimpleRegression();
|
|
|
- regression.addData(data);
|
|
|
+ for (int i = 0; i < means.length; i++) {
|
|
|
+
|
|
|
+ regression.addData(targetValues[i],means[i]);
|
|
|
+ }
|
|
|
slope = regression.getSlope();
|
|
|
intercept = regression.getIntercept();
|
|
|
slopeCI = regression.getSlopeConfidenceInterval();
|
|
|
@@ -31,7 +49,45 @@ public class LinearRangeAverageSlope extends PVModel {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ TableDTO buildTable1DTO(int sheetIndex) {
|
|
|
+
|
|
|
+ TableDTO table = new TableDTO();
|
|
|
+ String[] header = {"样本名", "理论值","实测均值", "偏差", "百分偏差%"};
|
|
|
+ table.buildHeader(header);
|
|
|
+
|
|
|
+
|
|
|
+ Object[][] r = new Object[specimensNum][5];
|
|
|
+
|
|
|
+ for (int i = 0; i < r.length; i++) {
|
|
|
+ r[i][0] = specimensName[i];
|
|
|
+ r[i][1] = format(getTargetValues()[i],getScale());
|
|
|
+ r[i][2] = format(getMeans()[i],getScale());
|
|
|
+ r[i][3] = format(getMeans()[i] - getTargetValues()[i],getScale());
|
|
|
+ r[i][4] = format(100 * (getMeans()[i] - getTargetValues()[i]) /getTargetValues()[i],1);
|
|
|
+ }
|
|
|
+ table.buildData(r);
|
|
|
+ return table;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public String[] tableNames() {
|
|
|
+ return new String[]{"表1: 线性范围计算结果"};
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ ChartDTO buildChart1DTO(int sheetIndex) {
|
|
|
+ ChartDTO chartDTO = new ChartDTO("polynomialRegression");
|
|
|
+ double[][] data = new double[targetValues.length][2];
|
|
|
+ for (int i = 0; i < data.length; i++) {
|
|
|
+ data[i] = new double[]{format(targetValues[i],getScale()), format(means[i],getScale())};
|
|
|
+ }
|
|
|
+// chartDTO.setData(data);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("data", JSONObject.toJSONString(data, SerializerFeature.DisableCircularReferenceDetect));
|
|
|
|
|
|
+ chartDTO.setOption(renderChartTemplate(map, 0, "/scatter/polynomialRegression.ftl"));
|
|
|
+ return chartDTO;
|
|
|
+ }
|
|
|
public TableDTO buildDataTableDTO() {
|
|
|
List<String> header = new ArrayList<String>();
|
|
|
|
|
|
@@ -52,14 +108,9 @@ public class LinearRangeAverageSlope extends PVModel {
|
|
|
}
|
|
|
|
|
|
|
|
|
- @Override
|
|
|
- public String[] tableNames() {
|
|
|
- return new String[0];
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public String[] chartNames() {
|
|
|
- return new String[0];
|
|
|
+ return new String[]{"图1: 线性评价散点图"};
|
|
|
}
|
|
|
|
|
|
public String getFunction() {
|
|
|
@@ -68,14 +119,14 @@ public class LinearRangeAverageSlope extends PVModel {
|
|
|
|
|
|
return "y =" +
|
|
|
(b0 >= 0 ? " " : " -") +
|
|
|
- Math.abs(b0) +
|
|
|
+ Math.abs(format(b0,getScale())) +
|
|
|
(b1 > 0 ? " + " : " - ") +
|
|
|
- Math.abs(b1) +
|
|
|
+ Math.abs(format(b1,getScale())) +
|
|
|
"x";
|
|
|
}
|
|
|
|
|
|
public String getSlopeCIFormat(){
|
|
|
- return String.format("%s ~ %s)", slope - slopeCI,slope + slopeCI);
|
|
|
+ return String.format("%s ~ %s)", format(slope - slopeCI,getScale()),format(slope + slopeCI,getScale()));
|
|
|
}
|
|
|
|
|
|
public double getSlope() {
|
|
|
@@ -103,7 +154,7 @@ public class LinearRangeAverageSlope extends PVModel {
|
|
|
}
|
|
|
|
|
|
public double getrSquare() {
|
|
|
- return rSquare;
|
|
|
+ return format(rSquare,getScale());
|
|
|
}
|
|
|
|
|
|
public void setrSquare(double rSquare) {
|
|
|
@@ -111,10 +162,34 @@ public class LinearRangeAverageSlope extends PVModel {
|
|
|
}
|
|
|
|
|
|
public double getR() {
|
|
|
- return r;
|
|
|
+ return format(r,getScale());
|
|
|
}
|
|
|
|
|
|
public void setR(double r) {
|
|
|
this.r = r;
|
|
|
}
|
|
|
+
|
|
|
+ public double[] getTargetValues() {
|
|
|
+ return targetValues;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setTargetValues(double[] targetValues) {
|
|
|
+ this.targetValues = targetValues;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double[] getMeans() {
|
|
|
+ return means;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setMeans(double[] means) {
|
|
|
+ this.means = means;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getAllowableR2() {
|
|
|
+ return allowableR2;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setAllowableR2(double allowableR2) {
|
|
|
+ this.allowableR2 = allowableR2;
|
|
|
+ }
|
|
|
}
|