mark for pull

This commit is contained in:
caixiang
2022-08-09 14:57:55 +08:00
parent 314380cd74
commit 01c95bfe1d
29 changed files with 1338 additions and 65 deletions

View File

@@ -0,0 +1,10 @@
package com.cnbm.processInspection.constant;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/8/3 10:01
*/
public class Constant {
public String measureMent = "WeightHeiHei";
}

View File

@@ -7,9 +7,14 @@ import com.cnbm.common.spc.math.StandardDiviation;
import com.cnbm.common.spc.util.DataUtils;
import com.cnbm.common.vo.R;
import com.cnbm.influx.constant.Constant;
import com.cnbm.influx.param.QueryDataGroupByTimeParam;
import com.cnbm.influx.param.QueryDataParam;
import com.cnbm.influx.param.Range;
import com.cnbm.processInspection.dto.*;
import com.cnbm.processInspection.graphAnalyzed.forCount.c.CGraph;
import com.cnbm.processInspection.graphAnalyzed.forCount.np.NPGraph;
import com.cnbm.processInspection.graphAnalyzed.forCount.p.PGraph;
import com.cnbm.processInspection.graphAnalyzed.forCount.u.UGraph;
import com.cnbm.processInspection.graphAnalyzed.forMeterage.mr.MeanRGraph;
import com.cnbm.processInspection.graphAnalyzed.forMeterage.ms.MeanStandardDeviationGraph;
import com.cnbm.processInspection.graphAnalyzed.forMeterage.xmr.XMRGraph;
@@ -36,9 +41,6 @@ public class ProcessInspectionController {
@PostMapping("/XbarSGraphTest")
public R<XbarSGraphData> xbarSGraphTest() throws Exception {
ProductFeaturesDTO productFeaturesDTO = productFeaturesService.get(new Long(1));
ProductFeatures productFeatures = new ProductFeatures();
productFeatures.setSl(new Float(5));
productFeatures.setUsl(new Float(10));
@@ -55,7 +57,7 @@ public class ProcessInspectionController {
QueryDataParam queryDataParam = new QueryDataParam();
queryDataParam.setMeasurement("Weight");
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(), Instant.now()));
meanStandardDeviationGraph.initialDate(queryDataParam);
@@ -89,7 +91,7 @@ public class ProcessInspectionController {
QueryDataParam queryDataParam = new QueryDataParam();
queryDataParam.setMeasurement("Weight");
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(), Instant.now()));
meanRGraph.initialDate(queryDataParam);
@@ -122,7 +124,7 @@ public class ProcessInspectionController {
QueryDataParam queryDataParam = new QueryDataParam();
queryDataParam.setMeasurement("Weight");
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(), Instant.now()));
xmrGraph.initialDate(queryDataParam);
@@ -137,6 +139,109 @@ public class ProcessInspectionController {
return R.ok("成功",xmrGraphData);
}
@PostMapping("/NPGraphTest")
public R<NPGraphData> NPGraphTest() throws Exception {
ProductFeatures productFeatures = new ProductFeatures();
productFeatures.setSl(new Float(5));
productFeatures.setUsl(new Float(10));
productFeatures.setLsl(new Float(1));
productFeatures.setName("LostDays");
NPGraph npGraph = new NPGraph(productFeatures);
QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam();
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range( Instant.now() , DataUtils.getAfterDate(999).toInstant() ));
queryDataParam.setTimeType(1);
npGraph.initialDate(queryDataParam);
NPGraphData npGraph1 = new NPGraphData(
npGraph.getList(),
npGraph.getSpecificationLimit(),
npGraph.getArgName()
);
return R.ok("成功",npGraph1);
}
@PostMapping("/PGraphTest")
public R<PGraphData> PGraphTest() throws Exception {
ProductFeatures productFeatures = new ProductFeatures();
productFeatures.setSl(new Float(5));
productFeatures.setUsl(new Float(10));
productFeatures.setLsl(new Float(1));
productFeatures.setName("LostDays");
PGraph pGraph = new PGraph(productFeatures);
QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam();
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range( Instant.now() , DataUtils.getAfterDate(999).toInstant() ));
queryDataParam.setTimeType(2);
pGraph.initialDate(queryDataParam);
PGraphData npGraph1 = new PGraphData(
pGraph.getList(),
pGraph.getSpecificationLimit(),
pGraph.getArgName()
);
return R.ok("成功",npGraph1);
}
@PostMapping("/CGraphTest")
public R<CGraphData> CGraphTest() throws Exception {
ProductFeatures productFeatures = new ProductFeatures();
productFeatures.setSl(new Float(5));
productFeatures.setUsl(new Float(10));
productFeatures.setLsl(new Float(1));
productFeatures.setName("LostDays");
CGraph cGraph = new CGraph(productFeatures);
QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam();
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range( Instant.now() , DataUtils.getAfterDate(999).toInstant() ));
queryDataParam.setTimeType(2);
cGraph.initialDate(queryDataParam);
CGraphData npGraph1 = new CGraphData(
cGraph.getList(),
cGraph.getSpecificationLimit(),
cGraph.getArgName()
);
return R.ok("成功",npGraph1);
}
@PostMapping("/UGraphTest")
public R<UGraphData> UGraphTest() throws Exception {
ProductFeatures productFeatures = new ProductFeatures();
productFeatures.setSl(new Float(5));
productFeatures.setUsl(new Float(10));
productFeatures.setLsl(new Float(1));
productFeatures.setName("LostDays");
UGraph uGraph = new UGraph(productFeatures);
QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam();
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range( Instant.now() , DataUtils.getAfterDate(999).toInstant() ));
queryDataParam.setTimeType(2);
uGraph.initialDate(queryDataParam);
UGraphData npGraph1 = new UGraphData(
uGraph.getList(),
uGraph.getSpecificationLimit(),
uGraph.getArgName()
);
return R.ok("成功",npGraph1);
}
private ProductFeatures setRealSampleSize(GraphArg graphArg){
ProductFeaturesDTO productFeaturesDTO = productFeaturesService.get(graphArg.getProductFeaturesId());
@@ -235,4 +340,87 @@ public class ProcessInspectionController {
return R.ok("成功",xmrGraphData);
}
@PostMapping("/NPGraph")
public R<NPGraphData> NPGraph(@RequestBody GraphArg graphArg) throws Exception {
ProductFeatures productFeatures = setRealSampleSize(graphArg);
NPGraph npGraph = new NPGraph(productFeatures);
QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam();
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range( graphArg.getBegin().toInstant() , graphArg.getEnd().toInstant() ));
queryDataParam.setTimeType(graphArg.getGroupType());
npGraph.initialDate(queryDataParam);
NPGraphData npGraph1 = new NPGraphData(
npGraph.getList(),
npGraph.getSpecificationLimit(),
npGraph.getArgName()
);
return R.ok("成功",npGraph1);
}
@PostMapping("/PGraph")
public R<PGraphData> PGraph(@RequestBody GraphArg graphArg) throws Exception {
ProductFeatures productFeatures = setRealSampleSize(graphArg);
PGraph pGraph = new PGraph(productFeatures);
QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam();
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range( graphArg.getBegin().toInstant() , graphArg.getEnd().toInstant() ));
queryDataParam.setTimeType(graphArg.getGroupType());
pGraph.initialDate(queryDataParam);
PGraphData npGraph1 = new PGraphData(
pGraph.getList(),
pGraph.getSpecificationLimit(),
pGraph.getArgName()
);
return R.ok("成功",npGraph1);
}
@PostMapping("/CGraph")
public R<CGraphData> CGraph(@RequestBody GraphArg graphArg) throws Exception {
ProductFeatures productFeatures = setRealSampleSize(graphArg);
CGraph cGraph = new CGraph(productFeatures);
QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam();
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range( graphArg.getBegin().toInstant() , graphArg.getEnd().toInstant() ));
queryDataParam.setTimeType(graphArg.getGroupType());
cGraph.initialDate(queryDataParam);
CGraphData npGraph1 = new CGraphData(
cGraph.getList(),
cGraph.getSpecificationLimit(),
cGraph.getArgName()
);
return R.ok("成功",npGraph1);
}
@PostMapping("/UGraph")
public R<UGraphData> UGraph(@RequestBody GraphArg graphArg) throws Exception {
ProductFeatures productFeatures = setRealSampleSize(graphArg);
UGraph uGraph = new UGraph(productFeatures);
QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam();
queryDataParam.setMeasurement(Constant.measurement);
queryDataParam.setRange(new Range( graphArg.getBegin().toInstant() , graphArg.getEnd().toInstant() ));
queryDataParam.setTimeType(graphArg.getGroupType());
uGraph.initialDate(queryDataParam);
UGraphData uGraphData = new UGraphData(
uGraph.getList(),
uGraph.getSpecificationLimit(),
uGraph.getArgName()
);
return R.ok("成功",uGraphData);
}
}

View File

@@ -0,0 +1,32 @@
package com.cnbm.processInspection.dto;
import com.cnbm.qualityPlanning.entity.CPoint;
import com.cnbm.qualityPlanning.entity.PPoint;
import com.cnbm.qualityPlanning.entity.SpecificationLimit;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/7/22 14:18
*/
@Data
@ApiModel(value = "C控制图 结果类")
public class CGraphData {
@ApiModelProperty(value = "P控制图list数据")
private List<CPoint> list;
@ApiModelProperty(value = "P控制图 规格线")
private SpecificationLimit specificationLimit;
@ApiModelProperty(value = "P控制图 参数名")
private String argName;
public CGraphData(List<CPoint> list, SpecificationLimit specificationLimit, String argName) {
this.list = list;
this.specificationLimit = specificationLimit;
this.argName = argName;
}
}

View File

@@ -32,5 +32,6 @@ public class GraphArg {
@ApiModelProperty(value = "样本大小,不填的话用之前配置的")
private Integer sampleSize;
@ApiModelProperty(value = "分组类别1=年 , 2=月 , 3=日)(用于计数型控制图)")
private Integer groupType;
}

View File

@@ -0,0 +1,22 @@
package com.cnbm.processInspection.dto;
import lombok.Data;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/7/27 15:56
*/
@Data
public class InterpretationListArgForCount {
private Integer number;
private Integer arg;
public InterpretationListArgForCount() {
}
public InterpretationListArgForCount(Integer number, Integer arg) {
this.number = number;
this.arg = arg;
}
}

View File

@@ -0,0 +1,35 @@
package com.cnbm.processInspection.dto;
import com.cnbm.common.spc.math.StandardDiviation;
import com.cnbm.processInspection.graphAnalyzed.forMeterage.xmr.XMRGraphEntity;
import com.cnbm.qualityPlanning.entity.ControlLimit;
import com.cnbm.qualityPlanning.entity.NPPoint;
import com.cnbm.qualityPlanning.entity.ProcessCapability;
import com.cnbm.qualityPlanning.entity.SpecificationLimit;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/7/22 14:18
*/
@Data
@ApiModel(value = "NP控制图 结果类")
public class NPGraphData {
@ApiModelProperty(value = "NP控制图list数据")
private List<NPPoint> list;
@ApiModelProperty(value = "NP控制图 规格线")
private SpecificationLimit specificationLimit;
@ApiModelProperty(value = "NP控制图 参数名")
private String argName;
public NPGraphData(List<NPPoint> list, SpecificationLimit specificationLimit, String argName) {
this.list = list;
this.specificationLimit = specificationLimit;
this.argName = argName;
}
}

View File

@@ -0,0 +1,32 @@
package com.cnbm.processInspection.dto;
import com.cnbm.qualityPlanning.entity.NPPoint;
import com.cnbm.qualityPlanning.entity.PPoint;
import com.cnbm.qualityPlanning.entity.SpecificationLimit;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/7/22 14:18
*/
@Data
@ApiModel(value = "P控制图 结果类")
public class PGraphData {
@ApiModelProperty(value = "P控制图list数据")
private List<PPoint> list;
@ApiModelProperty(value = "P控制图 规格线")
private SpecificationLimit specificationLimit;
@ApiModelProperty(value = "P控制图 参数名")
private String argName;
public PGraphData(List<PPoint> list, SpecificationLimit specificationLimit, String argName) {
this.list = list;
this.specificationLimit = specificationLimit;
this.argName = argName;
}
}

View File

@@ -0,0 +1,32 @@
package com.cnbm.processInspection.dto;
import com.cnbm.qualityPlanning.entity.CPoint;
import com.cnbm.qualityPlanning.entity.SpecificationLimit;
import com.cnbm.qualityPlanning.entity.UPoint;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @Desc: ""
* @Author: caixiang
* @DATE: 2022/7/22 14:18
*/
@Data
@ApiModel(value = "U控制图 结果类")
public class UGraphData {
@ApiModelProperty(value = "U控制图list数据")
private List<UPoint> list;
@ApiModelProperty(value = "U控制图 规格线")
private SpecificationLimit specificationLimit;
@ApiModelProperty(value = "U控制图 参数名")
private String argName;
public UGraphData(List<UPoint> list, SpecificationLimit specificationLimit, String argName) {
this.list = list;
this.specificationLimit = specificationLimit;
this.argName = argName;
}
}

View File

@@ -0,0 +1,153 @@
package com.cnbm.processInspection.graphAnalyzed.forCount.c;
import com.cnbm.basic.entity.ProductFeatures;
import com.cnbm.common.spc.util.DataUtils;
import com.cnbm.influx.config.InfluxClient;
import com.cnbm.influx.constant.Constant;
import com.cnbm.influx.param.QueryDataGroupByTimeParam;
import com.cnbm.influx.param.Tag;
import com.cnbm.qualityPlanning.entity.CPoint;
import com.cnbm.qualityPlanning.entity.ControlLimit;
import com.cnbm.qualityPlanning.entity.PPoint;
import com.cnbm.qualityPlanning.entity.SpecificationLimit;
import com.influxdb.query.FluxRecord;
import com.influxdb.query.FluxTable;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @Desc: "均值标准差 控制图 , 计算类"
* @Author: caixiang
* @DATE: 2022/7/20 14:26
* 使用方式:① 先new MeanStandardDeviationGraph 对象 ;② 再initialData 初始化数据;③ 再get 控制限
*
* 步骤:
* ① 先读mysql表查询 product_features 表,先读到 sample_size样本量
* ② 再依据 influx.argName == mysql.product_feature.name && 时间段 查询所有的 参数数据
* ③ 拿到参数数据后,分组 整合成List<Point>,
* 计算控制限
* 计算 母体 的 \sigma 、 bar{x} 。。。
* 计算CPK 、CPU 、CPL这些
* ④ 如果配置了判读方案,还要 调用 StatisticalControlledTest Function 检验。
* ⑤
*/
@Data
public class CGraph {
//计数型,不能用判读方案校验,,因为 当每个样本n不同控制限 都不一定相同。
// private List<InterpretationListArgForCount> interpretationScheme;
private String argName;
private List<CPoint> list;
private Double cbar;
private SpecificationLimit specificationLimit;
public CGraph(ProductFeatures productFeatures) throws Exception {
this.argName = productFeatures.getName();
list = new ArrayList<>();
this.specificationLimit = new SpecificationLimit(
productFeatures.getUsl()==null?null:productFeatures.getUsl(),
productFeatures.getSl()==null?null:productFeatures.getSl(),
productFeatures.getLsl()==null?null:productFeatures.getLsl()
);
}
private Double[] toDoubleArray(Object[] o){
Double[] res= new Double[o.length];
for(int i=0;i<o.length;i++){
res[i] = (Double) o[i];
}
return res;
}
private Double computeCbar(List<FluxTable> query){
Double totalFailNum = (double)0;
for (FluxTable fluxTable : query) {
List<FluxRecord> records = fluxTable.getRecords();
Integer failNum = 0;
for (FluxRecord fluxRecord : records) {
//因为 传进去的就是Double 类型所以取出来自然而然就是Double
Double value = Double.parseDouble(fluxRecord.getValueByKey("_value").toString());
if(value.equals((double) 0)){
failNum+=1;
}
}
totalFailNum =totalFailNum + (double)failNum;
}
return totalFailNum/query.size();
}
public static void main(String[] args) {
//2022-08-04 T06:59:55.628Z
String name = "2022-08-04 T06:59:55.628Z";
String[] s = name.split(" ");
String[] split = s[0].split("-");
System.out.println(name);
}
/**
* name : 初始化数据函数
* desc : 从influxdb 里面读取数据,然后 加工处理成 我需要的
* 步骤:
* ①
* */
public void initialDate(QueryDataGroupByTimeParam queryDataParam){
queryDataParam.setBucket(Constant.bucket);
List<String> dropNames = new ArrayList<>();
dropNames.add("transationId");
dropNames.add("inspectionSheetId");
dropNames.add("batchNum");
queryDataParam.setDropedTagNames(dropNames);
queryDataParam.setTag(new Tag("argName",argName));
List<FluxTable> query = InfluxClient.Client.queryGroupByTime(queryDataParam);
//1. 先从fluxdb 里面提取原始数据
//计算p bar
this.cbar = computeCbar(query);
//2.计算各项式
for(int i=0 ;i<query.size();i++){
List<FluxRecord> records = query.get(i).getRecords();
Integer failNum = 0;
String name = DataUtils.splitToNeed(records.get(0).getTime().toString(),queryDataParam.getTimeType());
for (FluxRecord fluxRecord : records) {
//因为 传进去的就是Double 类型所以取出来自然而然就是Double
Double value = Double.parseDouble(fluxRecord.getValueByKey("_value").toString());
if(value.equals((double) 0)){
failNum+=1;
}
}
list.add(new CPoint(
getCL(),
i,
(double)failNum,
name
));
}
}
/**
* desc: get Xbar控制图 的控制限
* 注意:此函数 要在 initialDate()函数执行之后
* */
public ControlLimit getCL(){
Double mul = 3 * Math.sqrt( this.cbar );
Double lcl = (this.cbar-mul)<0?0:(this.cbar-mul);
return new ControlLimit(
this.cbar + mul,
this.cbar,
lcl
);
}
}

View File

@@ -0,0 +1,156 @@
package com.cnbm.processInspection.graphAnalyzed.forCount.np;
import com.cnbm.basic.entity.ProductFeatures;
import com.cnbm.common.spc.math.StandardDiviation;
import com.cnbm.common.spc.util.DataUtils;
import com.cnbm.influx.config.InfluxClient;
import com.cnbm.influx.constant.Constant;
import com.cnbm.influx.param.QueryDataGroupByTimeParam;
import com.cnbm.influx.param.QueryDataParam;
import com.cnbm.influx.param.Tag;
import com.cnbm.processInspection.controlCoefficientConstant.XBarRCoefficients;
import com.cnbm.processInspection.dto.InterpretationListArg;
import com.cnbm.processInspection.dto.InterpretationListArgForCount;
import com.cnbm.qualityPlanning.common.StatisticalControlledTest;
import com.cnbm.qualityPlanning.entity.*;
import com.influxdb.query.FluxRecord;
import com.influxdb.query.FluxTable;
import lombok.Data;
import org.omg.CORBA.PRIVATE_MEMBER;
import java.util.ArrayList;
import java.util.List;
/**
* @Desc: "均值标准差 控制图 , 计算类"
* @Author: caixiang
* @DATE: 2022/7/20 14:26
* 使用方式:① 先new MeanStandardDeviationGraph 对象 ;② 再initialData 初始化数据;③ 再get 控制限
*
* 步骤:
* ① 先读mysql表查询 product_features 表,先读到 sample_size样本量
* ② 再依据 influx.argName == mysql.product_feature.name && 时间段 查询所有的 参数数据
* ③ 拿到参数数据后,分组 整合成List<Point>,
* 计算控制限
* 计算 母体 的 \sigma 、 bar{x} 。。。
* 计算CPK 、CPU 、CPL这些
* ④ 如果配置了判读方案,还要 调用 StatisticalControlledTest Function 检验。
* ⑤
*/
@Data
public class NPGraph {
//计数型,不能用判读方案校验,,因为 当每个样本n不同控制限 都不一定相同。
// private List<InterpretationListArgForCount> interpretationScheme;
private String argName;
private List<NPPoint> list;
private Double pbar;
private SpecificationLimit specificationLimit;
public NPGraph(ProductFeatures productFeatures) throws Exception {
this.argName = productFeatures.getName();
list = new ArrayList<>();
this.specificationLimit = new SpecificationLimit(
productFeatures.getUsl()==null?null:productFeatures.getUsl(),
productFeatures.getSl()==null?null:productFeatures.getSl(),
productFeatures.getLsl()==null?null:productFeatures.getLsl()
);
}
private Double[] toDoubleArray(Object[] o){
Double[] res= new Double[o.length];
for(int i=0;i<o.length;i++){
res[i] = (Double) o[i];
}
return res;
}
private Double computePbar(List<FluxTable> query){
Double totalFailNum = (double)0;
Double totalN = (double)0;
for (FluxTable fluxTable : query) {
List<FluxRecord> records = fluxTable.getRecords();
Integer failNum = 0;
Integer n = records.size();
for (FluxRecord fluxRecord : records) {
//因为 传进去的就是Double 类型所以取出来自然而然就是Double
Double value = Double.parseDouble(fluxRecord.getValueByKey("_value").toString());
if(value.equals((double) 0)){
failNum+=1;
}
}
totalFailNum =totalFailNum + (double)failNum;
totalN = totalN + (double)n;
}
return totalFailNum/totalN;
}
/**
* name : 初始化数据函数
* desc : 从influxdb 里面读取数据,然后 加工处理成 我需要的
* 步骤:
* ①
* */
public void initialDate(QueryDataGroupByTimeParam queryDataParam){
queryDataParam.setBucket(Constant.bucket);
List<String> dropNames = new ArrayList<>();
dropNames.add("transationId");
dropNames.add("inspectionSheetId");
dropNames.add("batchNum");
queryDataParam.setDropedTagNames(dropNames);
queryDataParam.setTag(new Tag("argName",argName));
List<FluxTable> query = InfluxClient.Client.queryGroupByTime(queryDataParam);
//1. 先从fluxdb 里面提取原始数据
List<Double> originData = new ArrayList<>();
//计算p bar
this.pbar = computePbar(query);
//2.计算各项式
for(int i=0 ;i<query.size();i++){
List<FluxRecord> records = query.get(i).getRecords();
Integer failNum = 0;
Integer n = records.size();
String name = DataUtils.splitToNeed(records.get(0).getTime().toString(),queryDataParam.getTimeType());
for (FluxRecord fluxRecord : records) {
//因为 传进去的就是Double 类型所以取出来自然而然就是Double
Double value = Double.parseDouble(fluxRecord.getValueByKey("_value").toString());
if(value.equals((double) 0)){
failNum+=1;
}
}
list.add(new NPPoint(
getCL((double)n),
i,
failNum,
name
));
}
}
/**
* desc: get Xbar控制图 的控制限
* 注意:此函数 要在 initialDate()函数执行之后
* */
public ControlLimit getCL(Double n){
Double npbar = n * this.pbar;
Double mul = 3 * Math.sqrt(npbar*(1-this.pbar));
Double lcl = (npbar-mul)<0?0:(npbar-mul);
return new ControlLimit(
npbar + mul,
npbar,
lcl
);
}
}

View File

@@ -0,0 +1,163 @@
package com.cnbm.processInspection.graphAnalyzed.forCount.p;
import com.cnbm.basic.entity.ProductFeatures;
import com.cnbm.common.spc.util.DataUtils;
import com.cnbm.influx.config.InfluxClient;
import com.cnbm.influx.constant.Constant;
import com.cnbm.influx.param.QueryDataGroupByTimeParam;
import com.cnbm.influx.param.Tag;
import com.cnbm.qualityPlanning.entity.ControlLimit;
import com.cnbm.qualityPlanning.entity.NPPoint;
import com.cnbm.qualityPlanning.entity.PPoint;
import com.cnbm.qualityPlanning.entity.SpecificationLimit;
import com.influxdb.query.FluxRecord;
import com.influxdb.query.FluxTable;
import lombok.Data;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @Desc: "均值标准差 控制图 , 计算类"
* @Author: caixiang
* @DATE: 2022/7/20 14:26
* 使用方式:① 先new MeanStandardDeviationGraph 对象 ;② 再initialData 初始化数据;③ 再get 控制限
*
* 步骤:
* ① 先读mysql表查询 product_features 表,先读到 sample_size样本量
* ② 再依据 influx.argName == mysql.product_feature.name && 时间段 查询所有的 参数数据
* ③ 拿到参数数据后,分组 整合成List<Point>,
* 计算控制限
* 计算 母体 的 \sigma 、 bar{x} 。。。
* 计算CPK 、CPU 、CPL这些
* ④ 如果配置了判读方案,还要 调用 StatisticalControlledTest Function 检验。
* ⑤
*/
@Data
public class PGraph {
//计数型,不能用判读方案校验,,因为 当每个样本n不同控制限 都不一定相同。
// private List<InterpretationListArgForCount> interpretationScheme;
private String argName;
private List<PPoint> list;
private Double pbar;
private SpecificationLimit specificationLimit;
public PGraph(ProductFeatures productFeatures) throws Exception {
this.argName = productFeatures.getName();
list = new ArrayList<>();
this.specificationLimit = new SpecificationLimit(
productFeatures.getUsl()==null?null:productFeatures.getUsl(),
productFeatures.getSl()==null?null:productFeatures.getSl(),
productFeatures.getLsl()==null?null:productFeatures.getLsl()
);
}
private Double[] toDoubleArray(Object[] o){
Double[] res= new Double[o.length];
for(int i=0;i<o.length;i++){
res[i] = (Double) o[i];
}
return res;
}
private Double computePbar(List<FluxTable> query){
Double totalFailNum = (double)0;
Double totalN = (double)0;
for (FluxTable fluxTable : query) {
List<FluxRecord> records = fluxTable.getRecords();
Integer failNum = 0;
Integer n = records.size();
for (FluxRecord fluxRecord : records) {
//因为 传进去的就是Double 类型所以取出来自然而然就是Double
Double value = Double.parseDouble(fluxRecord.getValueByKey("_value").toString());
if(value.equals((double) 0)){
failNum+=1;
}
}
totalFailNum =totalFailNum + (double)failNum;
totalN = totalN + (double)n;
}
return totalFailNum/totalN;
}
public static void main(String[] args) {
//2022-08-04 T06:59:55.628Z
String name = "2022-08-04 T06:59:55.628Z";
String[] s = name.split(" ");
String[] split = s[0].split("-");
System.out.println(name);
}
/**
* name : 初始化数据函数
* desc : 从influxdb 里面读取数据,然后 加工处理成 我需要的
* 步骤:
* ①
* */
public void initialDate(QueryDataGroupByTimeParam queryDataParam){
queryDataParam.setBucket(Constant.bucket);
List<String> dropNames = new ArrayList<>();
dropNames.add("transationId");
dropNames.add("inspectionSheetId");
dropNames.add("batchNum");
queryDataParam.setDropedTagNames(dropNames);
queryDataParam.setTag(new Tag("argName",argName));
List<FluxTable> query = InfluxClient.Client.queryGroupByTime(queryDataParam);
//1. 先从fluxdb 里面提取原始数据
//计算p bar
this.pbar = computePbar(query);
//2.计算各项式
for(int i=0 ;i<query.size();i++){
List<FluxRecord> records = query.get(i).getRecords();
Integer failNum = 0;
Integer n = records.size();
String name = DataUtils.splitToNeed(records.get(0).getTime().toString(),queryDataParam.getTimeType());
for (FluxRecord fluxRecord : records) {
//因为 传进去的就是Double 类型所以取出来自然而然就是Double
Double value = Double.parseDouble(fluxRecord.getValueByKey("_value").toString());
if(value.equals((double) 0)){
failNum+=1;
}
}
Double pi = (double)failNum / (double)n;
list.add(new PPoint(
getCL((double)n),
i,
pi,
name
));
}
}
/**
* desc: get Xbar控制图 的控制限
* 注意:此函数 要在 initialDate()函数执行之后
* */
public ControlLimit getCL(Double n){
Double mul = 3 * Math.sqrt( ( this.pbar * (1-this.pbar) ) / n );
Double lcl = (this.pbar-mul)<0?0:(this.pbar-mul);
return new ControlLimit(
this.pbar + mul,
this.pbar,
lcl
);
}
}

View File

@@ -0,0 +1,161 @@
package com.cnbm.processInspection.graphAnalyzed.forCount.u;
import com.cnbm.basic.entity.ProductFeatures;
import com.cnbm.common.spc.util.DataUtils;
import com.cnbm.influx.config.InfluxClient;
import com.cnbm.influx.constant.Constant;
import com.cnbm.influx.param.QueryDataGroupByTimeParam;
import com.cnbm.influx.param.Tag;
import com.cnbm.qualityPlanning.entity.ControlLimit;
import com.cnbm.qualityPlanning.entity.PPoint;
import com.cnbm.qualityPlanning.entity.SpecificationLimit;
import com.cnbm.qualityPlanning.entity.UPoint;
import com.influxdb.query.FluxRecord;
import com.influxdb.query.FluxTable;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* @Desc: "均值标准差 控制图 , 计算类"
* @Author: caixiang
* @DATE: 2022/7/20 14:26
* 使用方式:① 先new MeanStandardDeviationGraph 对象 ;② 再initialData 初始化数据;③ 再get 控制限
*
* 步骤:
* ① 先读mysql表查询 product_features 表,先读到 sample_size样本量
* ② 再依据 influx.argName == mysql.product_feature.name && 时间段 查询所有的 参数数据
* ③ 拿到参数数据后,分组 整合成List<Point>,
* 计算控制限
* 计算 母体 的 \sigma 、 bar{x} 。。。
* 计算CPK 、CPU 、CPL这些
* ④ 如果配置了判读方案,还要 调用 StatisticalControlledTest Function 检验。
* ⑤
*/
@Data
public class UGraph {
//计数型,不能用判读方案校验,,因为 当每个样本n不同控制限 都不一定相同。
// private List<InterpretationListArgForCount> interpretationScheme;
private String argName;
private List<UPoint> list;
private Double ubar;
private SpecificationLimit specificationLimit;
public UGraph(ProductFeatures productFeatures) throws Exception {
this.argName = productFeatures.getName();
list = new ArrayList<>();
this.specificationLimit = new SpecificationLimit(
productFeatures.getUsl()==null?null:productFeatures.getUsl(),
productFeatures.getSl()==null?null:productFeatures.getSl(),
productFeatures.getLsl()==null?null:productFeatures.getLsl()
);
}
private Double[] toDoubleArray(Object[] o){
Double[] res= new Double[o.length];
for(int i=0;i<o.length;i++){
res[i] = (Double) o[i];
}
return res;
}
private Double computeUbar(List<FluxTable> query){
Double totalFailNum = (double)0;
Double totalN = (double)0;
for (FluxTable fluxTable : query) {
List<FluxRecord> records = fluxTable.getRecords();
Integer failNum = 0;
Integer n = records.size();
for (FluxRecord fluxRecord : records) {
//因为 传进去的就是Double 类型所以取出来自然而然就是Double
Double value = Double.parseDouble(fluxRecord.getValueByKey("_value").toString());
if(value.equals((double) 0)){
failNum+=1;
}
}
totalFailNum =totalFailNum + (double)failNum;
totalN = totalN + (double)n;
}
return totalFailNum/totalN;
}
public static void main(String[] args) {
//2022-08-04 T06:59:55.628Z
String name = "2022-08-04 T06:59:55.628Z";
String[] s = name.split(" ");
String[] split = s[0].split("-");
System.out.println(name);
}
/**
* name : 初始化数据函数
* desc : 从influxdb 里面读取数据,然后 加工处理成 我需要的
* 步骤:
* ①
* */
public void initialDate(QueryDataGroupByTimeParam queryDataParam){
queryDataParam.setBucket(Constant.bucket);
List<String> dropNames = new ArrayList<>();
dropNames.add("transationId");
dropNames.add("inspectionSheetId");
dropNames.add("batchNum");
queryDataParam.setDropedTagNames(dropNames);
queryDataParam.setTag(new Tag("argName",argName));
List<FluxTable> query = InfluxClient.Client.queryGroupByTime(queryDataParam);
//1. 先从fluxdb 里面提取原始数据
//计算p bar
this.ubar = computeUbar(query);
//2.计算各项式
for(int i=0 ;i<query.size();i++){
List<FluxRecord> records = query.get(i).getRecords();
Integer failNum = 0;
Integer n = records.size();
String name = DataUtils.splitToNeed(records.get(0).getTime().toString(),queryDataParam.getTimeType());
for (FluxRecord fluxRecord : records) {
//因为 传进去的就是Double 类型所以取出来自然而然就是Double
Double value = Double.parseDouble(fluxRecord.getValueByKey("_value").toString());
if(value.equals((double) 0)){
failNum+=1;
}
}
Double ui = (double)failNum / (double)n;
list.add(new UPoint(
getCL((double)n),
i,
ui,
name
));
}
}
/**
* desc: get Xbar控制图 的控制限
* 注意:此函数 要在 initialDate()函数执行之后
* */
public ControlLimit getCL(Double n){
Double mul = 3 * Math.sqrt( this.ubar / n );
Double lcl = (this.ubar-mul)<0?0:(this.ubar-mul);
return new ControlLimit(
this.ubar + mul,
this.ubar,
lcl
);
}
}

View File

@@ -75,7 +75,7 @@ public class MeanRGraph {
this.specificationLimit = new SpecificationLimit(
productFeatures.getUsl()==null?null:productFeatures.getUsl(),
productFeatures.getSl()==null?null:productFeatures.getSl(),
productFeatures.getUsl()==null?null:productFeatures.getUsl()
productFeatures.getLsl()==null?null:productFeatures.getLsl()
);
}
@@ -102,6 +102,7 @@ public class MeanRGraph {
List<String> dropNames = new ArrayList<>();
dropNames.add("transationId");
dropNames.add("inspectionSheetId");
dropNames.add("batchNum");
queryDataParam.setDropedTagNames(dropNames);
queryDataParam.setTag(new Tag("argName",argName));

View File

@@ -72,7 +72,7 @@ public class MeanStandardDeviationGraph {
this.specificationLimit = new SpecificationLimit(
productFeatures.getUsl()==null?null:productFeatures.getUsl(),
productFeatures.getSl()==null?null:productFeatures.getSl(),
productFeatures.getUsl()==null?null:productFeatures.getUsl()
productFeatures.getLsl()==null?null:productFeatures.getLsl()
);
}
@@ -99,6 +99,7 @@ public class MeanStandardDeviationGraph {
List<String> dropNames = new ArrayList<>();
dropNames.add("transationId");
dropNames.add("inspectionSheetId");
dropNames.add("batchNum");
queryDataParam.setDropedTagNames(dropNames);
queryDataParam.setTag(new Tag("argName",argName));

View File

@@ -69,7 +69,7 @@ public class XMRGraph {
this.specificationLimit = new SpecificationLimit(
productFeatures.getUsl()==null?null:productFeatures.getUsl(),
productFeatures.getSl()==null?null:productFeatures.getSl(),
productFeatures.getUsl()==null?null:productFeatures.getUsl()
productFeatures.getLsl()==null?null:productFeatures.getLsl()
);
}
@@ -96,6 +96,7 @@ public class XMRGraph {
List<String> dropNames = new ArrayList<>();
dropNames.add("transationId");
dropNames.add("inspectionSheetId");
dropNames.add("batchNum");
queryDataParam.setDropedTagNames(dropNames);
queryDataParam.setTag(new Tag("argName",argName));