mark
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package com.cnbm.processInspection.controller;
|
||||
|
||||
import com.cnbm.basic.dto.UnitDTO;
|
||||
import com.cnbm.basic.entity.ProductFeatures;
|
||||
import com.cnbm.common.spc.math.StandardDiviation;
|
||||
import com.cnbm.common.spc.util.DataUtils;
|
||||
import com.cnbm.common.utils.Result;
|
||||
import com.cnbm.common.vo.R;
|
||||
import com.cnbm.influx.config.InfluxClient;
|
||||
import com.cnbm.influx.constant.Constant;
|
||||
import com.cnbm.influx.param.PageInfo;
|
||||
import com.cnbm.influx.param.QueryDataParam;
|
||||
import com.cnbm.influx.param.Range;
|
||||
import com.cnbm.influx.param.Tag;
|
||||
import com.cnbm.influx.template.Event;
|
||||
import com.cnbm.processInspection.dto.XbarSGraphData;
|
||||
import com.cnbm.processInspection.graphAnalyzed.MeanStandardDeviationGraph;
|
||||
import com.cnbm.qualityPlanning.entity.SpecificationLimit;
|
||||
import com.influxdb.client.domain.WritePrecision;
|
||||
import com.influxdb.client.write.Point;
|
||||
import com.influxdb.query.FluxRecord;
|
||||
import com.influxdb.query.FluxTable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/processInspection")
|
||||
public class ProcessInspectionController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProcessInspectionController.class);
|
||||
|
||||
|
||||
|
||||
@PostMapping("/XbarSGraph")
|
||||
public R<XbarSGraphData> xbarSGraph() throws Exception {
|
||||
ProductFeatures productFeatures = new ProductFeatures();
|
||||
productFeatures.setSl(new Float(5));
|
||||
productFeatures.setUsl(new Float(10));
|
||||
productFeatures.setLsl(new Float(1));
|
||||
|
||||
productFeatures.setName("LTWeight");
|
||||
productFeatures.setSampleSize(BigDecimal.TEN);
|
||||
MeanStandardDeviationGraph meanStandardDeviationGraph = new MeanStandardDeviationGraph(productFeatures);
|
||||
|
||||
QueryDataParam queryDataParam = new QueryDataParam();
|
||||
queryDataParam.setMeasurement("Weight");
|
||||
queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(), Instant.now()));
|
||||
meanStandardDeviationGraph.initialDate(queryDataParam);
|
||||
XbarSGraphData xbarSGraphData = new XbarSGraphData(
|
||||
meanStandardDeviationGraph.getMsdGraphEntity(),
|
||||
meanStandardDeviationGraph.getXbarCL(),
|
||||
meanStandardDeviationGraph.getSCL(),
|
||||
meanStandardDeviationGraph.getSpecificationLimit(),
|
||||
meanStandardDeviationGraph.getProcessCapacity(),
|
||||
new StandardDiviation(meanStandardDeviationGraph.getXigma(),meanStandardDeviationGraph.getTotalXigma())
|
||||
);
|
||||
|
||||
return R.ok("成功",xbarSGraphData);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.cnbm.processInspection.dto;
|
||||
|
||||
import com.cnbm.common.spc.math.StandardDiviation;
|
||||
import com.cnbm.processInspection.graphAnalyzed.MSDGraphEntity;
|
||||
import com.cnbm.qualityPlanning.entity.ControlLimit;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @Desc: ""
|
||||
* @Author: caixiang
|
||||
* @DATE: 2022/7/22 14:18
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "均值标准差控制图 结果类")
|
||||
public class XbarSGraphData {
|
||||
@ApiModelProperty(value = "控制图list数据")
|
||||
private MSDGraphEntity msdGraphEntity;
|
||||
@ApiModelProperty(value = "xbar控制图 控制限")
|
||||
private ControlLimit XBarCL;
|
||||
@ApiModelProperty(value = "s控制图 控制限")
|
||||
private ControlLimit SCL;
|
||||
|
||||
@ApiModelProperty(value = "工艺规格限")
|
||||
private SpecificationLimit SL;
|
||||
|
||||
@ApiModelProperty(value = "工序能力")
|
||||
private ProcessCapability processCapability;
|
||||
|
||||
@ApiModelProperty(value = "标准差/总体标准差")
|
||||
private StandardDiviation standardDiviation;
|
||||
|
||||
|
||||
public XbarSGraphData(MSDGraphEntity msdGraphEntity,ControlLimit xBarCL,ControlLimit sCL,SpecificationLimit sl,ProcessCapability processCapability,StandardDiviation standardDiviation){
|
||||
this.msdGraphEntity = msdGraphEntity;
|
||||
this.XBarCL = xBarCL;
|
||||
this.SCL = sCL;
|
||||
this.SL = sl;
|
||||
this.processCapability = processCapability;
|
||||
this.standardDiviation = standardDiviation;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.cnbm.processInspection.entity;
|
||||
|
||||
|
||||
import com.cnbm.qualityPlanning.entity.Point;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Desc: ""
|
||||
* @Author: caixiang
|
||||
* @DATE: 2022/7/21 9:43
|
||||
*/
|
||||
public class XbarSPoint extends Point {
|
||||
public XbarSPoint(Integer position, Double value) {
|
||||
super(position, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPosition() {
|
||||
return super.getPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getValue() {
|
||||
return super.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Integer> getUnsatisfiedRules() {
|
||||
return super.getUnsatisfiedRules();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(Integer position) {
|
||||
super.setPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Double value) {
|
||||
super.setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUnsatisfiedRules(Set<Integer> unsatisfiedRules) {
|
||||
super.setUnsatisfiedRules(unsatisfiedRules);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.cnbm.processInspection.graphAnalyzed;
|
||||
|
||||
|
||||
|
||||
import com.cnbm.qualityPlanning.entity.XbarSPoint;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Desc: ""
|
||||
* @Author: caixiang
|
||||
* @DATE: 2022/7/21 16:26
|
||||
*/
|
||||
public class MSDGraphEntity {
|
||||
private List<XbarSPoint> list;
|
||||
private Double xbarbar;
|
||||
private Double sbar;
|
||||
private Double Rbar;
|
||||
|
||||
public MSDGraphEntity(List<XbarSPoint> list,Double xbarbar,Double sbar,Double Rbar){
|
||||
this.list = list;
|
||||
this.Rbar = Rbar;
|
||||
this.sbar = sbar;
|
||||
this.xbarbar = xbarbar;
|
||||
}
|
||||
|
||||
public List<XbarSPoint> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<XbarSPoint> list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
public Double getXbarbar() {
|
||||
return xbarbar;
|
||||
}
|
||||
|
||||
public void setXbarbar(Double xbarbar) {
|
||||
this.xbarbar = xbarbar;
|
||||
}
|
||||
|
||||
public Double getSbar() {
|
||||
return sbar;
|
||||
}
|
||||
|
||||
public void setSbar(Double sbar) {
|
||||
this.sbar = sbar;
|
||||
}
|
||||
|
||||
public Double getRbar() {
|
||||
return Rbar;
|
||||
}
|
||||
|
||||
public void setRbar(Double rbar) {
|
||||
Rbar = rbar;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.cnbm.processInspection.graphAnalyzed;
|
||||
|
||||
import com.cnbm.basic.entity.ProductFeatures;
|
||||
import com.cnbm.common.spc.math.Math;
|
||||
import com.cnbm.common.spc.math.StandardDiviation;
|
||||
import com.cnbm.common.spc.util.DataUtils;
|
||||
import com.cnbm.common.utils.DateUtils;
|
||||
import com.cnbm.influx.config.InfluxClient;
|
||||
@@ -10,16 +12,25 @@ import com.cnbm.influx.param.QueryDataParam;
|
||||
import com.cnbm.influx.param.Range;
|
||||
import com.cnbm.influx.param.Tag;
|
||||
import com.cnbm.processInspection.controlCoefficientConstant.XBarSCoefficients;
|
||||
|
||||
import com.cnbm.qualityPlanning.entity.ControlLimit;
|
||||
import com.cnbm.qualityPlanning.entity.ProcessCapability;
|
||||
import com.cnbm.qualityPlanning.entity.SpecificationLimit;
|
||||
import com.cnbm.qualityPlanning.entity.XbarSPoint;
|
||||
import com.influxdb.query.FluxRecord;
|
||||
import com.influxdb.query.FluxTable;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Desc: ""
|
||||
* @Desc: "均值标准差 控制图 , 计算类"
|
||||
* @Author: caixiang
|
||||
* @DATE: 2022/7/20 14:26
|
||||
* 使用方式:① 先new MeanStandardDeviationGraph 对象 ;② 再initialData 初始化数据;③ 再get 控制限
|
||||
*
|
||||
* 步骤:
|
||||
* ① 先读mysql表,查询 product_features 表,先读到 sample_size(样本量)
|
||||
@@ -31,8 +42,16 @@ import java.util.List;
|
||||
* ④ 如果配置了判读方案,还要 调用 StatisticalControlledTest Function 检验。
|
||||
* ⑤
|
||||
*/
|
||||
|
||||
@Data
|
||||
public class MeanStandardDeviationGraph {
|
||||
//母体的 μ = xbarbar
|
||||
private Double miu;
|
||||
//母体的 xigma ,全局计算的;
|
||||
private Double xigma;
|
||||
//母体的 xigma ,全局计算的;
|
||||
private Double totalXigma;
|
||||
|
||||
|
||||
private Double sbar;
|
||||
private Double xbarbar;
|
||||
private Double as;
|
||||
@@ -41,16 +60,32 @@ public class MeanStandardDeviationGraph {
|
||||
private Integer sampleSize;
|
||||
private String argName;
|
||||
|
||||
private SpecificationLimit specificationLimit;
|
||||
private MSDGraphEntity msdGraphEntity;
|
||||
|
||||
MeanStandardDeviationGraph(ProductFeatures productFeatures) throws Exception {
|
||||
|
||||
public MeanStandardDeviationGraph(ProductFeatures productFeatures) throws Exception {
|
||||
if(productFeatures.getSampleSize()==null || productFeatures.getName()==null){
|
||||
throw new Exception("ProductFeatures 参数异常");
|
||||
}
|
||||
|
||||
this.argName = productFeatures.getName();
|
||||
this.sampleSize = productFeatures.getSampleSize().intValue();
|
||||
this.as = XBarSCoefficients.getAS(sampleSize);
|
||||
this.bu = XBarSCoefficients.getBU(sampleSize);
|
||||
this.bl = XBarSCoefficients.getBU(sampleSize);
|
||||
this.specificationLimit = new SpecificationLimit(
|
||||
productFeatures.getUsl()==null?null:productFeatures.getUsl(),
|
||||
productFeatures.getSl()==null?null:productFeatures.getSl(),
|
||||
productFeatures.getUsl()==null?null:productFeatures.getUsl()
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,24 +94,130 @@ public class MeanStandardDeviationGraph {
|
||||
* 步骤:
|
||||
* ①
|
||||
* */
|
||||
public void initialDate(){
|
||||
QueryDataParam queryDataParam = new QueryDataParam();
|
||||
public void initialDate(QueryDataParam queryDataParam){
|
||||
queryDataParam.setBucket(Constant.bucket);
|
||||
queryDataParam.setMeasurement("Weight");
|
||||
queryDataParam.setDropedTagName("transationId");
|
||||
queryDataParam.setTag(new Tag("argName","LTWeight"));
|
||||
queryDataParam.setTag(new Tag("argName",argName));
|
||||
queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(), Instant.now()));
|
||||
queryDataParam.setPageInfo(new PageInfo(1,10));
|
||||
|
||||
List<FluxTable> query = InfluxClient.Client.query(queryDataParam);
|
||||
List<List<FluxTable>> lists = DataUtils.fixedGroup(query, sampleSize);
|
||||
|
||||
|
||||
//1. 先从fluxdb 里面提取原始数据
|
||||
List<Double> originData = new ArrayList<>();
|
||||
for (FluxTable fluxTable : query) {
|
||||
List<FluxRecord> records = fluxTable.getRecords();
|
||||
for (FluxRecord fluxRecord : records) {
|
||||
System.out.println("value: " + fluxRecord.getValueByKey("_value"));
|
||||
|
||||
//因为 传进去的就是Double 类型,所以取出来,自然而然就是Double
|
||||
originData.add(Double.parseDouble(fluxRecord.getValueByKey("_value").toString()));
|
||||
}
|
||||
}
|
||||
|
||||
//2. convert to XbarSPoint
|
||||
List<List<Double>> doubleListList = DataUtils.fixedGroup(originData, sampleSize);
|
||||
List<XbarSPoint> list = new ArrayList<>();
|
||||
List<Double> xbarArray = new ArrayList<>();
|
||||
List<Double> sArray = new ArrayList<>();
|
||||
List<Double> rArray = new ArrayList<>();
|
||||
for(int i=0;i<doubleListList.size();i++){
|
||||
Double[] doubleList = toDoubleArray(doubleListList.get(i).toArray());
|
||||
|
||||
Double xbar = Math.getMean(doubleList);
|
||||
Double s = Math.StandardDiviation(doubleList).getNormal();
|
||||
Double r = Math.range(doubleList);
|
||||
xbarArray.add(xbar);
|
||||
sArray.add(s);
|
||||
rArray.add(r);
|
||||
list.add(new XbarSPoint(
|
||||
i,
|
||||
new Double(0),
|
||||
xbar,
|
||||
s,
|
||||
r
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
//3. 以及一些 控制图的全局参数。
|
||||
Double xbarbar = Math.getMean(toDoubleArray(xbarArray.toArray()));
|
||||
this.miu = xbarbar;
|
||||
StandardDiviation standardDiviation =Math.StandardDiviation(toDoubleArray(originData.toArray()));
|
||||
this.xigma = standardDiviation.getNormal();
|
||||
this.totalXigma = standardDiviation.getTotality();
|
||||
Double sbar = Math.getMean(toDoubleArray(sArray.toArray()));
|
||||
Double rbar = Math.getMean(toDoubleArray(rArray.toArray()));
|
||||
this.msdGraphEntity = new MSDGraphEntity(list,xbarbar,sbar,rbar);
|
||||
}
|
||||
|
||||
/**
|
||||
* desc: get Xbar控制图 的控制限
|
||||
* 注意:此函数 要在 initialDate()函数执行之后
|
||||
* */
|
||||
public ControlLimit getXbarCL(){
|
||||
return new ControlLimit(
|
||||
(as*this.msdGraphEntity.getSbar() + this.msdGraphEntity.getXbarbar()),
|
||||
this.msdGraphEntity.getXbarbar(),
|
||||
(this.msdGraphEntity.getXbarbar() - as*this.msdGraphEntity.getSbar())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* desc: get S控制图 的控制限
|
||||
* 注意:此函数 要在 initialDate()函数执行之后
|
||||
* */
|
||||
public ControlLimit getSCL(){
|
||||
return new ControlLimit(
|
||||
( bu * this.msdGraphEntity.getSbar() ) ,
|
||||
this.msdGraphEntity.getSbar() ,
|
||||
(bl * this.msdGraphEntity.getSbar())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* desc: get 工序能力
|
||||
* 注意:此函数 要在 initialDate()函数执行之后
|
||||
* */
|
||||
public ProcessCapability getProcessCapacity(){
|
||||
SpecificationLimit sp = this.specificationLimit;
|
||||
List<String> warming = new ArrayList<>();
|
||||
Float usl = sp.getUSL();
|
||||
Float lsl = sp.getLSL();
|
||||
if(usl==null || lsl==null){
|
||||
if(usl==null && lsl!=null){
|
||||
if(this.miu<lsl){
|
||||
warming.add("平均值已不能满足规范要求, 有相当多数据均为不合格, 则表示完全没有工序能力");
|
||||
return new ProcessCapability(null,null,null,(double)0,warming);
|
||||
}
|
||||
Double cpl = ( (this.miu-lsl) / (3 * this.xigma) );
|
||||
return new ProcessCapability(null,null,null,cpl,warming);
|
||||
} else if (lsl == null && usl!=null) {
|
||||
if(this.miu>usl){
|
||||
warming.add("平均值已不能满足规范要求, 有相当多数据均为不合格, 则表示完全没有工序能力");
|
||||
return new ProcessCapability(null,null,(double)0,null,warming);
|
||||
}
|
||||
|
||||
Double cpu = ( (usl-this.miu) / (3 * this.xigma) );
|
||||
return new ProcessCapability(null,null,cpu,null,warming);
|
||||
}else {
|
||||
return new ProcessCapability(null,null,null,null,warming);
|
||||
}
|
||||
}
|
||||
|
||||
//下面就是 usl 和 lsl 都部位null的情况
|
||||
Float k1 = usl-lsl;
|
||||
Float k2 = usl+lsl;
|
||||
|
||||
Double cp = ( k1 / (6*this.xigma) );
|
||||
Double k = ( java.lang.Math.abs( (this.miu-k2/2) ) / (k1/2) );
|
||||
if(k>1){
|
||||
warming.add("此工艺参数K 大于1, 说明均值μ已经偏离到规范范围意外,即相当多的工艺参数均不满足规范要求,这说明工艺加工结果很差,该设备根本不适用于批量生产");
|
||||
}
|
||||
Double cpk = cp * ( 1- k);
|
||||
if(cpk<0){
|
||||
warming.add("Cpk=0,该工序完全没有能力 批量生产");
|
||||
cpk = (double) 0;
|
||||
}
|
||||
Double cpu = ( (usl-this.miu) / (3 * this.xigma) );
|
||||
Double cpl = ( (this.miu-lsl) / (3 * this.xigma) );
|
||||
|
||||
return new ProcessCapability(cp,cpk,cpu,cpl,warming);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user