|
|
@@ -1,10 +1,7 @@
|
|
|
package com.lc.ibps.components.verification.model2;
|
|
|
|
|
|
import com.lc.ibps.components.verification.model.InspectionConfigVO;
|
|
|
-import com.lc.ibps.components.verification.regression.PolynomialRegression;
|
|
|
import com.lc.ibps.components.verification.report.TableDTO;
|
|
|
-import org.apache.commons.lang3.ArrayUtils;
|
|
|
-import org.apache.commons.math3.stat.regression.RegressionResults;
|
|
|
import org.apache.commons.math3.stat.regression.SimpleRegression;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
@@ -12,89 +9,46 @@ import java.util.List;
|
|
|
|
|
|
public class LinearRangeAverageSlope extends PVModel {
|
|
|
|
|
|
- private final double[] means;
|
|
|
- private final double[][] diffs;
|
|
|
- private final double[][] dli;
|
|
|
- private double maxDli;
|
|
|
- private double mean;
|
|
|
- private final double[] standardDeviations;
|
|
|
-
|
|
|
- private double[] targetValues;
|
|
|
- private boolean isTarget = true;
|
|
|
-
|
|
|
-
|
|
|
- private final PolynomialRegression pr1 = new PolynomialRegression();
|
|
|
-
|
|
|
- private double sdr;
|
|
|
- private double cvr;
|
|
|
+ private double slope;
|
|
|
+ private double intercept;
|
|
|
+ private double slopeCI;//ConfidenceInterval
|
|
|
+ private double rSquare;
|
|
|
+ private double r;
|
|
|
|
|
|
public LinearRangeAverageSlope(double[][] data, InspectionConfigVO configVO) {
|
|
|
super(data, configVO);
|
|
|
-
|
|
|
- this.means = new double[this.specimensNum];
|
|
|
- this.standardDeviations = new double[this.specimensNum];
|
|
|
- this.diffs = new double[5][this.specimensNum];
|
|
|
- this.dli = new double[5][this.specimensNum];
|
|
|
- this.targetValues = new double[this.specimensNum];
|
|
|
- calcTarget(configVO.getTargetValue());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void calculate() {
|
|
|
final SimpleRegression regression = new SimpleRegression();
|
|
|
regression.addData(data);
|
|
|
- RegressionResults results = regression.regress();
|
|
|
-// results.
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private void calcTarget(double[] targets) {
|
|
|
- if (ArrayUtils.isEmpty(targets)) {
|
|
|
- for (int i = 0; i < specimensNum; i++) {
|
|
|
- targetValues[i] = i + 1;
|
|
|
- }
|
|
|
- isTarget = false;
|
|
|
- } else if (targets.length == 2) {
|
|
|
- targetValues[0] = targets[0];
|
|
|
- targetValues[specimensNum - 1] = targets[1];
|
|
|
- int range = specimensNum - 1;
|
|
|
- for (int i = 1; i < range; i++) {
|
|
|
- targetValues[i] = format(targets[0] * (range - i) / range + targets[1] * i / range, 2);
|
|
|
- }
|
|
|
- } else if (targets.length == specimensNum) {
|
|
|
- targetValues = targets;
|
|
|
- }
|
|
|
+ slope = regression.getSlope();
|
|
|
+ intercept = regression.getIntercept();
|
|
|
+ slopeCI = regression.getSlopeConfidenceInterval();
|
|
|
+ rSquare = regression.getRSquare();
|
|
|
+ r = regression.getR();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public TableDTO buildDataTableDTO() {
|
|
|
List<String> header = new ArrayList<String>();
|
|
|
|
|
|
header.add("标本号");
|
|
|
- if (isTarget) header.add("目标值");
|
|
|
for (int i = 1; i <= repeatNum; i++) {
|
|
|
header.add(String.format("重复#%d", i));
|
|
|
}
|
|
|
TableDTO table = new TableDTO();
|
|
|
table.buildHeader(header.toArray(new String[header.size()]));
|
|
|
|
|
|
- String[][] r = new String[specimensNum][];
|
|
|
- for (int i = 0; i < data.length; i++) {
|
|
|
- List<String> rl = new ArrayList();
|
|
|
- rl.add(String.valueOf(i + 1));
|
|
|
- if (isTarget) rl.add(String.valueOf(targetValues[i]));
|
|
|
-
|
|
|
- for (int j = 0; j < data[i].length; j++) {
|
|
|
- rl.add(format(data[i][j]));
|
|
|
- }
|
|
|
- r[i] = rl.toArray(new String[rl.size()]);
|
|
|
- }
|
|
|
- table.buildData(r);
|
|
|
+ table.buildDataWithIndex(getData(),getScale());
|
|
|
return table;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String generateResult() {
|
|
|
- return renderReportTemplate(this, null);
|
|
|
+ return renderReportTemplate(this, "/report/linearRangeAverageSlope.ftl");
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -108,4 +62,59 @@ public class LinearRangeAverageSlope extends PVModel {
|
|
|
return new String[0];
|
|
|
}
|
|
|
|
|
|
+ public String getFunction() {
|
|
|
+ double b0 = intercept;
|
|
|
+ double b1 = slope;
|
|
|
+
|
|
|
+ return "y =" +
|
|
|
+ (b0 >= 0 ? " " : " -") +
|
|
|
+ Math.abs(b0) +
|
|
|
+ (b1 > 0 ? " + " : " - ") +
|
|
|
+ Math.abs(b1) +
|
|
|
+ "x";
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getSlopeCIFormat(){
|
|
|
+ return String.format("%s ~ %s)", slope - slopeCI,slope + slopeCI);
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getSlope() {
|
|
|
+ return slope;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setSlope(double slope) {
|
|
|
+ this.slope = slope;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getIntercept() {
|
|
|
+ return intercept;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setIntercept(double intercept) {
|
|
|
+ this.intercept = intercept;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getSlopeCI() {
|
|
|
+ return slopeCI;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setSlopeCI(double slopeCI) {
|
|
|
+ this.slopeCI = slopeCI;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getrSquare() {
|
|
|
+ return rSquare;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setrSquare(double rSquare) {
|
|
|
+ this.rSquare = rSquare;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getR() {
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setR(double r) {
|
|
|
+ this.r = r;
|
|
|
+ }
|
|
|
}
|