diff --git a/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java b/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java index 587a917..2203625 100644 --- a/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java +++ b/ym-admin/src/main/java/com/cnbm/admin/config/SecurityConfig.java @@ -73,6 +73,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { "/webjars/**", "/websocket/**", "/influx/**", + "/processInspection/**", "/captcha").anonymous() // .antMatchers("/testCors").hasAuthority("system:dept:list222") // 除上面外的所有请求全部需要鉴权认证 diff --git a/ym-common/src/main/java/com/cnbm/common/spc/math/Math.java b/ym-common/src/main/java/com/cnbm/common/spc/math/Math.java index 4faf392..602548e 100644 --- a/ym-common/src/main/java/com/cnbm/common/spc/math/Math.java +++ b/ym-common/src/main/java/com/cnbm/common/spc/math/Math.java @@ -2,6 +2,7 @@ package com.cnbm.common.spc.math; import java.math.RoundingMode; import java.text.DecimalFormat; +import java.util.List; public class Math { @@ -17,7 +18,7 @@ public class Math { // } //8.1 10.6 9.8 9.0 9.4 9.3 10.2 11.7 - double[] d = new double[8]; + Double[] d = new Double[8]; d[0] = new Double(8.1) ; d[1] = new Double(10.6); d[2] = new Double(9.8); @@ -32,12 +33,12 @@ public class Math { } //平均值 - public static double getMean(double...numbers) { + public static double getMean(Double...numbers) { return format(getSum(numbers) / numbers.length); } //极差 - public static double range(double[] in) { + public static double range(Double[] in) { if (in == null) { throw new NumberFormatException(); } @@ -51,14 +52,14 @@ public class Math { //return Mutil.subtract(max, min); } - public static double format(double value) { + public static double format(Double value) { DecimalFormat df = new DecimalFormat("0.00");//创建一个df对象,传入0.00表示构造一个保留小数点后两位的df对象 df.setRoundingMode(RoundingMode.HALF_UP);//设置规则,这里采用的也是四舍五入规则 return Double.parseDouble(df.format(value));//返回value(在返回之前使用df对象的格式化方法将数据格式化) } //方差s^2=[(x1-x)^2 +...(xn-x)^2]/n 或者s^2=[(x1-x)^2 +...(xn-x)^2]/(n-1) - public static double Variance(double[] x) { + public static double Variance(Double[] x) { int m=x.length; double sum=0; for(int i=0;i list = new ArrayList<>(); - list.add(point); - list.add(point2); - - writeApi.writePoints(list); +// Point point = Point.measurement("ASProcessCompleteEvent") +// .addTag("transationId", "112311") +// .addTag("argName", "argName11") +// .addField("argValue", 3D) +// .time(Instant.now().toEpochMilli(), WritePrecision.MS); +// +// +// Point point2 = Point.measurement("ASProcessCompleteEvent") +// .addTag("transationId", "222312") +// .addTag("argName", "argName11") +// .addField("argValue", 4D) +// .time(Instant.now().toEpochMilli(), WritePrecision.MS); +// List list = new ArrayList<>(); +// list.add(point); +// list.add(point2); +// +// writeApi.writePoints(list); //todo api.writeMeasurements(WritePrecision.NS, Arrays.asList(new H2OFeetMeasurement("coyote_creek", 15.0D, null, Instant.ofEpochSecond(0, 15)), new H2OFeetMeasurement("coyote_creek", 16.0D, null, Instant.ofEpochSecond(0, 16)))); // List events = new ArrayList<>(); @@ -105,23 +105,24 @@ public class Main { // } -// String flux = "from(bucket:\"mytest\") |> range(start: -60m)"; -// flux += "|> filter(fn: (r) =>\n" + -// " r._measurement == \"ASProcessCompleteEvent\" and \n" + -//// " r._field == \"type\" and \n" + //对应 Field key -// " r.argName == \"arg3\"\n" + //对应 Tags key (Tag 信息无法在FluxRecord 里面获取。) -// " )"; -// QueryApi queryApi = influxDBClient.getQueryApi(); -// -// List tables = queryApi.query(flux); -// for (FluxTable fluxTable : tables) { -// List records = fluxTable.getRecords(); -// for (FluxRecord fluxRecord : records) { -// System.out.println("time: "+fluxRecord.getTime() +" key:"+fluxRecord.getField()+" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement()); -//// System.out.println("time: "+fluxRecord.getTime() +" key:"++" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement()); -// -// } -// } + String flux = "from(bucket:\"mytest\") |> range(start: -6000000000000000m)"; + flux += "|> filter(fn: (r) =>\n" + + " r._measurement == \"ASProcessCompleteEvent\" and \n" + +// " r._field == \"type\" and \n" + //对应 Field key + " r.argName == \"arg3\"\n" + //对应 Tags key (Tag 信息无法在FluxRecord 里面获取。) + " )"; + QueryApi queryApi = influxDBClient.getQueryApi(); + + List tables = queryApi.query(flux); + for (FluxTable fluxTable : tables) { + List records = fluxTable.getRecords(); + for (FluxRecord fluxRecord : records) { + Double o = (Double)fluxRecord.getValueByKey("_value"); + System.out.println("time: "+fluxRecord.getTime() +" key:"+fluxRecord.getField()+" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement()); +// System.out.println("time: "+fluxRecord.getTime() +" key:"++" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement()); + + } + } // from(bucket: "mytest") diff --git a/ym-process-inspection/src/main/java/com/cnbm/processInspection/controller/ProcessInspectionController.java b/ym-process-inspection/src/main/java/com/cnbm/processInspection/controller/ProcessInspectionController.java new file mode 100644 index 0000000..ff9bc96 --- /dev/null +++ b/ym-process-inspection/src/main/java/com/cnbm/processInspection/controller/ProcessInspectionController.java @@ -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 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); + } + +} diff --git a/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XbarSGraphData.java b/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XbarSGraphData.java new file mode 100644 index 0000000..eb2f8e8 --- /dev/null +++ b/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XbarSGraphData.java @@ -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; + } +} diff --git a/ym-process-inspection/src/main/java/com/cnbm/processInspection/entity/XbarSPoint.java b/ym-process-inspection/src/main/java/com/cnbm/processInspection/entity/XbarSPoint.java deleted file mode 100644 index 38ae6fe..0000000 --- a/ym-process-inspection/src/main/java/com/cnbm/processInspection/entity/XbarSPoint.java +++ /dev/null @@ -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 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 unsatisfiedRules) { - super.setUnsatisfiedRules(unsatisfiedRules); - } -} diff --git a/ym-process-inspection/src/main/java/com/cnbm/processInspection/graphAnalyzed/MSDGraphEntity.java b/ym-process-inspection/src/main/java/com/cnbm/processInspection/graphAnalyzed/MSDGraphEntity.java new file mode 100644 index 0000000..ccdaf77 --- /dev/null +++ b/ym-process-inspection/src/main/java/com/cnbm/processInspection/graphAnalyzed/MSDGraphEntity.java @@ -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 list; + private Double xbarbar; + private Double sbar; + private Double Rbar; + + public MSDGraphEntity(List list,Double xbarbar,Double sbar,Double Rbar){ + this.list = list; + this.Rbar = Rbar; + this.sbar = sbar; + this.xbarbar = xbarbar; + } + + public List getList() { + return list; + } + + public void setList(List 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; + } +} diff --git a/ym-process-inspection/src/main/java/com/cnbm/processInspection/graphAnalyzed/MeanStandardDeviationGraph.java b/ym-process-inspection/src/main/java/com/cnbm/processInspection/graphAnalyzed/MeanStandardDeviationGraph.java index feed3a1..2a574a3 100644 --- a/ym-process-inspection/src/main/java/com/cnbm/processInspection/graphAnalyzed/MeanStandardDeviationGraph.java +++ b/ym-process-inspection/src/main/java/com/cnbm/processInspection/graphAnalyzed/MeanStandardDeviationGraph.java @@ -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 query = InfluxClient.Client.query(queryDataParam); - List> lists = DataUtils.fixedGroup(query, sampleSize); - - + //1. 先从fluxdb 里面提取原始数据 + List originData = new ArrayList<>(); for (FluxTable fluxTable : query) { List 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> doubleListList = DataUtils.fixedGroup(originData, sampleSize); + List list = new ArrayList<>(); + List xbarArray = new ArrayList<>(); + List sArray = new ArrayList<>(); + List rArray = new ArrayList<>(); + for(int i=0;i warming = new ArrayList<>(); + Float usl = sp.getUSL(); + Float lsl = sp.getLSL(); + if(usl==null || lsl==null){ + if(usl==null && lsl!=null){ + if(this.miuusl){ + 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); } } diff --git a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/common/StatisticalControlledTest.java b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/common/StatisticalControlledTest.java index 24b6ff5..62d0949 100644 --- a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/common/StatisticalControlledTest.java +++ b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/common/StatisticalControlledTest.java @@ -4,6 +4,8 @@ package com.cnbm.qualityPlanning.common; import com.cnbm.qualityPlanning.entity.ControlLimit; import com.cnbm.qualityPlanning.entity.ControlLimitDetail; import com.cnbm.qualityPlanning.entity.Point; +import com.cnbm.qualityPlanning.entity.XbarSPoint; + import java.util.*; @@ -38,6 +40,15 @@ public class StatisticalControlledTest { Point point10 = new Point(10,new Double(3.7)); Point point11 = new Point(11,new Double(3.7)); Point point12 = new Point(12,new Double(3.7)); + Point point13 = new Point(13,new Double(3.7)); + Point point14 = new Point(14,new Double(3.7)); + Point point15 = new Point(15,new Double(3.7)); + Point point16 = new Point(16,new Double(3.7)); + Point point17 = new Point(17,new Double(3.7)); + Point point18 = new Point(18,new Double(3.7)); + Point point19 = new Point(19,new Double(3.7)); + Point point20 = new Point(20,new Double(3.7)); + List list = new ArrayList<>(); list.add(point); list.add(point2); @@ -53,16 +64,68 @@ public class StatisticalControlledTest { list.add(point12); return list; } + public static List createData2(){ + XbarSPoint point = new XbarSPoint(1, new Double(2.5)); + XbarSPoint point2 = new XbarSPoint(2, new Double(2.5)); + XbarSPoint point3 = new XbarSPoint(3, new Double(2.5)); + XbarSPoint point4 = new XbarSPoint(4, new Double(2.5)); + XbarSPoint point5 = new XbarSPoint(5, new Double(2.5)); + XbarSPoint point6 = new XbarSPoint(6, new Double(2.5)); + XbarSPoint point7 = new XbarSPoint(7, new Double(2.5)); + XbarSPoint point8 = new XbarSPoint(8, new Double(2)); + XbarSPoint point9 = new XbarSPoint(9, new Double(2.5)); + XbarSPoint point10 = new XbarSPoint(10, new Double(2.5)); + XbarSPoint point11 = new XbarSPoint(11, new Double(2.5)); + XbarSPoint point12 = new XbarSPoint(12, new Double(2.5)); + XbarSPoint point13 = new XbarSPoint(13,new Double(2.5)); + XbarSPoint point14 = new XbarSPoint(14,new Double(2.5)); + XbarSPoint point15 = new XbarSPoint(15,new Double(2.5)); + XbarSPoint point16 = new XbarSPoint(16,new Double(2)); + XbarSPoint point17 = new XbarSPoint(17,new Double(2.5)); + XbarSPoint point18 = new XbarSPoint(18,new Double(2.5)); + XbarSPoint point19 = new XbarSPoint(19,new Double(2.5)); + XbarSPoint point20 = new XbarSPoint(20,new Double(2.5)); + XbarSPoint point21 = new XbarSPoint(21,new Double(2.5)); + XbarSPoint point22 = new XbarSPoint(22,new Double(2.5)); + XbarSPoint point23 = new XbarSPoint(23,new Double(2.5)); + List list = new ArrayList<>(); + list.add(point); + list.add(point2); + list.add(point3); + list.add(point4); + list.add(point5); + list.add(point6); + list.add(point7); + list.add(point8); + list.add(point9); + list.add(point10); + list.add(point11); + list.add(point12); + list.add(point13); + list.add(point14); + list.add(point15); + list.add(point16); + list.add(point17); + list.add(point18); + list.add(point19); + list.add(point20); + list.add(point21); + list.add(point22); + list.add(point23); + return list; + } public static void main(String[] args) { - List list = createData(); - ControlLimit controlLimit = new ControlLimit(new Double(12),new Double(2),new Double(1)); -// +// List list = createData(); + List list = createData2(); + ControlLimit controlLimit = new ControlLimit(new Double(12),new Double(3),new Double(1)); + System.out.println("controlLimit : "+controlLimit.toString()); + // // //TEST FOR RULE1 // Boolean aBoolean1 = rule1(list, controlLimit); // //TEST FOR RULE2 -// Boolean aBoolean2 = rule2(list, controlLimit, 9); +// Boolean aBoolean2 = rule2(list, controlLimit, 5); // System.out.println(); // // @@ -72,7 +135,7 @@ public class StatisticalControlledTest { // // // //TEST FOR RULE4 -// Boolean aBoolean4 = rule4(list, 5); +// Boolean aBoolean4 = rule4(list, 6); // System.out.println(); // //TEST FOR RULE5 @@ -80,17 +143,19 @@ public class StatisticalControlledTest { // System.out.println(); // //TEST FOR RULE6 -// Boolean aBoolean6 = rule6(list, controlLimit, 3,2); + // >6 或者 <2.3 +// Boolean aBoolean6 = rule6(list, controlLimit, 5,4); // System.out.println(); //TEST FOR RULE7 //LC0 = 1.6666 ;; UC1 = 5 - Boolean aBoolean7 = rule7(list, controlLimit,7); - System.out.println(); + // //>2.33 <3 +// Boolean aBoolean7 = rule7(list, controlLimit,7); +// System.out.println(); //TEST FOR RULE8 -// Boolean aBoolean8 = rule8(list, controlLimit,8); -// System.out.println(); + Boolean aBoolean8 = rule8(list, controlLimit,8); + System.out.println(); // int[] array={1,2,3,4,5,6}; // int[] ret=new int[3]; @@ -99,6 +164,7 @@ public class StatisticalControlledTest { } /** + * status : ok * name : 规则1 * desc : 控制图上有 1 个点位于三倍标准差以外(对中心线来说)(母体的 $\sigma$ ) * 注意: 如果存在满足rule1的点,会在原数组 Point.unsatisfiedRules 里标注出来。 @@ -109,7 +175,7 @@ public class StatisticalControlledTest { private static Boolean rule1(List data, ControlLimit controlLimit){ Boolean flag = false; for(Point i:data){ - if(i.getValue() > controlLimit.getUCL() || i.getValue() < controlLimit.getLCL()){ + if(i.getValueForInterpretation() > controlLimit.getUCL() || i.getValueForInterpretation() < controlLimit.getLCL()){ i.getUnsatisfiedRules().add(rule1Number); flag = true; } @@ -124,20 +190,23 @@ public class StatisticalControlledTest { } /** + * status : ok * name : 规则2 - * desc : 连续 n 点落在中心线的用一侧 (默认:9) + * desc : 连续 n 点落在中心线的同一侧 (默认:9) * 注意: 如果存在满足rule2的点,会在原数组 Point.unsatisfiedRules 里标注出来。 * return : * 存在满足rule2的点 => true * 不存在满足rule2的点 => false * */ private static Boolean rule2(List data, ControlLimit controlLimit,Integer n){ + Boolean result = false; + List upList = new ArrayList<>(); List downList = new ArrayList<>(); for(Point i:data){ - if(i.getValue() > controlLimit.getCL()){ + if(i.getValueForInterpretation() > controlLimit.getCL()){ upList.add(i); - }else if(i.getValue() < controlLimit.getCL()){ + }else if(i.getValueForInterpretation() < controlLimit.getCL()){ downList.add(i); } } @@ -151,15 +220,17 @@ public class StatisticalControlledTest { while((upi+1) < upList.size()){ //if((upList.get(upi).getPosition()+1)==upList.get(upi+1).getPosition()){ - if(isBetween(upList.get(upi),upList.get(upi+1))){ + //|| upi==(n-1) + if( isBetween(upList.get(upi),upList.get(upi+1)) || upi==(n-1) ){ uptime +=1; forMarkPoints.add(upList.get(upi)); - if((upi+1)==upTotalSize){ + if((upi+1)==(upTotalSize-1)){ uptime +=1; forMarkPoints.add(upList.get(upi+1)); } //只要到达n 了,就return,防止中间段到达 后面又被重置了 if(uptime>=n){ + result = true; //1. for (Point key:forMarkPoints){ for(Point j:data){ @@ -169,14 +240,12 @@ public class StatisticalControlledTest { } } } - //2. -// markUnsatisfiedRulesByKeys(data,forMarkKey,rule2Number); - - return true; + //2.不考虑 return ,先把所有点都找出来。( 重置所有标志位 ) + uptime = 0; } }else { forMarkPoints = new ArrayList<>(); - upTotalSize-=1; +// upTotalSize--; uptime = 0; } upi++; @@ -189,15 +258,17 @@ public class StatisticalControlledTest { Integer totalSize = downList.size(); forMarkPoints = new ArrayList<>(); while((downi+1) < downList.size()){ - if(isBetween(downList.get(downi),downList.get(downi+1))){ + //这里之所以 要加上downi==(n-1) 是因为,在比较顺序的时候,要把最后一种可能加上。 + //|| downi==(n-1) + if(isBetween(downList.get(downi),downList.get(downi+1)) || downi==(n-1) ){ downtime +=1; forMarkPoints.add(downList.get(downi)); - if((downi+1)==totalSize){ + if((downi+1)==(totalSize-1)){ downtime++; forMarkPoints.add(downList.get(downi+1)); } if(downtime>=n){ - + result = true; for (Point key:forMarkPoints){ for(Point j:data){ if(key.getPosition().equals(j.getPosition())){ @@ -206,22 +277,22 @@ public class StatisticalControlledTest { } } } - - return true; + //2.不考虑 return ,先把所有点都找出来。( 重置所有标志位 ) + downtime = 0; } }else { - totalSize-=1; forMarkPoints = new ArrayList<>(); +// totalSize--; downtime = 0; } downi++; } - - return false; + return result; } /** + * status : ok * name : 规则3 * desc : 连续 n 点递增或者递减 (默认:6) * 注意: 如果存在满足rule3的点,会在原数组 Point.unsatisfiedRules 里标注出来。 @@ -244,7 +315,9 @@ public class StatisticalControlledTest { data.get(key).getUnsatisfiedRules().add(rule3Number); } - return true; + //不return了, 把所有不满足的点都找出来 +// return true; + uptime = 0; } }else { uptime = 0; @@ -267,7 +340,8 @@ public class StatisticalControlledTest { data.get(key).getUnsatisfiedRules().add(rule3Number); } - return true; +// return true; + downtime = 0; } }else { downtime = 0; @@ -280,18 +354,24 @@ public class StatisticalControlledTest { } /** + * status : ok * name : 规则4 - * desc : 连续 n 点中 相邻点 交替上下 ( 默认:14 ) + * desc : 连续 n 点中 相邻点 交替上下 ( 默认:14 ) (n>2) * 注意: 如果存在满足rule4的点,会在原数组 Point.unsatisfiedRules 里标注出来。 * return : * 存在满足rule4的点 => true * 不存在满足rule4的点 => false * */ private static Boolean rule4(List data, Integer n){ + if(n<=2){ + return false; + } + Boolean result = false; Integer upi = 0; Boolean current; Boolean nextNeeded; Integer times = 0; + Integer isAgain = 1; List forMarkKey = new ArrayList<>(); if(isSmall(data.get(0),data.get(1))){ current = true; @@ -303,11 +383,34 @@ public class StatisticalControlledTest { while((upi+1) < data.size()){ if(isBetween( data.get(upi),data.get(upi+1) )){ - // + //最后一个节点情况 + if((upi+1)==(data.size()-1)){ + + Double u1 = data.get(upi-1).getValueForInterpretation(); + Double u2 = data.get(upi).getValueForInterpretation(); + Double u3 = data.get(upi+1).getValueForInterpretation(); + if(isUpAndDown(u1,u2,u3)){ + forMarkKey.add(upi); + forMarkKey.add(upi+1); + times+=2; + } + if(times >= n){ + for(Integer key:forMarkKey){ + data.get(key).getUnsatisfiedRules().add(rule4Number); + } + + //set完了就重置 + result = true; + return result; + } + } + + + //formark 最后一个点的时候 if(forMarkKey.size()==(n-1)){ - Double u1 = data.get(upi-2).getValue(); - Double u2 = data.get(upi-1).getValue(); - Double u3 = data.get(upi).getValue(); + Double u1 = data.get(upi-2).getValueForInterpretation(); + Double u2 = data.get(upi-1).getValueForInterpretation(); + Double u3 = data.get(upi).getValueForInterpretation(); if(isUpAndDown(u1,u2,u3)){ forMarkKey.add(upi); times++; @@ -316,7 +419,16 @@ public class StatisticalControlledTest { for(Integer key:forMarkKey){ data.get(key).getUnsatisfiedRules().add(rule4Number); } - return true; + + //set完了就重置 + result = true; + times=0; + forMarkKey = new ArrayList<>(); + + // + isAgain =2; + // + continue; } } @@ -328,6 +440,10 @@ public class StatisticalControlledTest { }else { current = false; } + if(isAgain == 2){ + nextNeeded = current; + isAgain = 1; + } if (current.equals(nextNeeded)){ @@ -335,9 +451,9 @@ public class StatisticalControlledTest { forMarkKey.add(upi); //加入最后一个元素的判断 if((upi+1)==(data.size()-1)){ - Double u0 = data.get(upi - 1).getValue(); - Double u1 = data.get(upi).getValue(); - Double u2 = data.get(upi + 1).getValue(); + Double u0 = data.get(upi - 1).getValueForInterpretation(); + Double u1 = data.get(upi).getValueForInterpretation(); + Double u2 = data.get(upi + 1).getValueForInterpretation(); if(isUpAndDown(u0,u1,u2)){ forMarkKey.add(upi+1); times++; @@ -349,7 +465,14 @@ public class StatisticalControlledTest { for(Integer key:forMarkKey){ data.get(key).getUnsatisfiedRules().add(rule4Number); } - return true; +// return true; + result = true; + times=0; + forMarkKey = new ArrayList<>(); + // + isAgain =2; + // + continue; } }else { times=0; @@ -363,7 +486,7 @@ public class StatisticalControlledTest { upi++; } - return false; + return result; } @@ -377,6 +500,7 @@ public class StatisticalControlledTest { * 不存在满足rule5的点 => false * */ private static Boolean rule5(List data,ControlLimit controlLimit, Integer m, Integer n){ + Boolean result = false; Integer upi = 0; List upforMarkKey = new ArrayList<>(); List downforMarkKey = new ArrayList<>(); @@ -401,37 +525,43 @@ public class StatisticalControlledTest { Integer upTimes = 0; Integer downTimes = 0; for(Point i:keyList){ - if(i.getValue()>controlLimitDetail.getUB()[1]){ + if(i.getValueForInterpretation()>controlLimitDetail.getUB()[1]){ upTimes++; upforMarkKey.add(i); System.out.println(); } - if(i.getValue()=n || downTimes>=n){ + result = true; if(upTimes>=n){ for(Point i:upforMarkKey){ i.getUnsatisfiedRules().add(rule5Number); } - return true; + upforMarkKey = new ArrayList<>(); +// return true; } if(downTimes>=n){ for(Point i:downforMarkKey){ i.getUnsatisfiedRules().add(rule5Number); } - return true; + downforMarkKey = new ArrayList<>(); +// return true; } - return true; +// return true; + }else { + upforMarkKey = new ArrayList<>(); + downforMarkKey = new ArrayList<>(); } upi++; } - return false; + return result; } /** @@ -443,6 +573,7 @@ public class StatisticalControlledTest { * 不存在满足rule6的点 => false * */ private static Boolean rule6(List data,ControlLimit controlLimit, Integer m, Integer n){ + Boolean result = false; Integer upi = 0; List upforMarkKey = new ArrayList<>(); List downforMarkKey = new ArrayList<>(); @@ -467,37 +598,47 @@ public class StatisticalControlledTest { Integer upTimes = 0; Integer downTimes = 0; for(Point i:keyList){ - if(i.getValue()>controlLimitDetail.getUC()[1]){ + if(i.getValueForInterpretation()>controlLimitDetail.getUC()[1]){ upTimes++; upforMarkKey.add(i); - System.out.println(); + } - if(i.getValue()=n || downTimes>=n){ + result = true; if(upTimes>=n){ for(Point i:upforMarkKey){ + i.getUnsatisfiedRules().add(rule6Number); } - return true; + upforMarkKey = new ArrayList<>(); +// return true; } if(downTimes>=n){ for(Point i:downforMarkKey){ + if(i.getPosition() == 13){ + System.out.println(1); + } i.getUnsatisfiedRules().add(rule6Number); } - return true; +// return true; + downforMarkKey = new ArrayList<>(); } - return true; +// return true; + }else { + upforMarkKey = new ArrayList<>(); + downforMarkKey = new ArrayList<>(); } upi++; } - return false; + return result; } /** @@ -510,6 +651,7 @@ public class StatisticalControlledTest { * */ private static Boolean rule7(List data,ControlLimit controlLimit, Integer n){ + Boolean result = false; //Integer upi = 0; ControlLimitDetail controlLimitDetail = new ControlLimitDetail(controlLimit.getUCL(), controlLimit.getCL(), controlLimit.getLCL()); @@ -522,7 +664,7 @@ public class StatisticalControlledTest { //判断最后一次 if((i+1) == data.size()){ Point point = data.get(i); - if(point.getValue()>controlLimitDetail.getLC()[0] && point.getValue()controlLimitDetail.getLC()[0] && point.getValueForInterpretation()controlLimitDetail.getLC()[0] && point.getValue()controlLimitDetail.getLC()[0] && point.getValueForInterpretation()(); } }else { times = 0; @@ -559,7 +704,7 @@ public class StatisticalControlledTest { markKey = new ArrayList<>(); } } - return false; + return result; } /** @@ -572,7 +717,7 @@ public class StatisticalControlledTest { * */ private static Boolean rule8(List data,ControlLimit controlLimit, Integer n){ - + Boolean result = true; //Integer upi = 0; ControlLimitDetail controlLimitDetail = new ControlLimitDetail(controlLimit.getUCL(), controlLimit.getCL(), controlLimit.getLCL()); System.out.println(controlLimitDetail.toString()); @@ -584,7 +729,7 @@ public class StatisticalControlledTest { //判断最后一次 if((i+1) == data.size()){ Point point = data.get(i); - if( point.getValue()>controlLimitDetail.getUC()[1] || point.getValue()controlLimitDetail.getUC()[1] || point.getValueForInterpretation()controlLimitDetail.getUC()[1] || point.getValue()controlLimitDetail.getUC()[1] || point.getValueForInterpretation()(); } }else { times = 0; @@ -621,7 +768,7 @@ public class StatisticalControlledTest { markKey = new ArrayList<>(); } } - return false; + return result; } /** @@ -634,13 +781,13 @@ public class StatisticalControlledTest { * 如果 head 小于 after ==》 true * */ private static boolean isSmall(Point head,Point after){ - return (head.getValue()- after.getValue()) < 0; + return (head.getValueForInterpretation()- after.getValueForInterpretation()) < 0; } /** * 如果 head 大于 after ==》 true * */ private static boolean isBig(Point head,Point after){ - return (head.getValue()- after.getValue()) > 0; + return (head.getValueForInterpretation()- after.getValueForInterpretation()) > 0; } diff --git a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/ControlLimit.java b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/ControlLimit.java index 90552a0..979b4cf 100644 --- a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/ControlLimit.java +++ b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/ControlLimit.java @@ -1,5 +1,7 @@ package com.cnbm.qualityPlanning.entity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** @@ -8,12 +10,16 @@ import lombok.Data; * @DATE: 2022/7/12 15:17 */ @Data +@ApiModel(value = "控制限") public class ControlLimit { //控制上限 + @ApiModelProperty(value = "控制上限") private Double UCL; //控制中心线 + @ApiModelProperty(value = "控制中心线") private Double CL; //控制下限 + @ApiModelProperty(value = "控制下限") private Double LCL; public ControlLimit(Double UCL,Double CL,Double LCL){ diff --git a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/PCWarming.java b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/PCWarming.java new file mode 100644 index 0000000..45c44fe --- /dev/null +++ b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/PCWarming.java @@ -0,0 +1,9 @@ +package com.cnbm.qualityPlanning.entity; + +/** + * @Desc: "" + * @Author: caixiang + * @DATE: 2022/7/25 16:31 + */ +public class PCWarming { +} diff --git a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/Point.java b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/Point.java index 0af577b..8868ee4 100644 --- a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/Point.java +++ b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/Point.java @@ -1,10 +1,8 @@ package com.cnbm.qualityPlanning.entity; -import io.swagger.models.auth.In; import lombok.Data; import java.util.HashSet; -import java.util.List; import java.util.Set; /** @@ -15,14 +13,14 @@ import java.util.Set; @Data public class Point { private Integer position; - private Double value; + private Double valueForInterpretation; //不满足的 规则 例子 : [1,2] => 代表 不满足 规则1 和 规则2 private Set unsatisfiedRules; - public Point(Integer position , Double value){ + public Point(Integer position , Double valueForInterpretation){ this.position = position; - this.value = value; + this.valueForInterpretation = valueForInterpretation; this.unsatisfiedRules = new HashSet(); } diff --git a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/ProcessCapability.java b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/ProcessCapability.java new file mode 100644 index 0000000..5713f15 --- /dev/null +++ b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/ProcessCapability.java @@ -0,0 +1,40 @@ +package com.cnbm.qualityPlanning.entity; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @Desc: "" + * @Author: caixiang + * @DATE: 2022/7/12 15:17 + */ +@Data +@ApiModel(value = "工序能力") +public class ProcessCapability { + //工序能力指数CP + @ApiModelProperty(value = "工序能力指数CP") + private Double CP; + //实际工序能力指数CPK + @ApiModelProperty(value = "实际工序能力指数CPK") + private Double CPK; + //上侧规范 工序能力指数CPU + @ApiModelProperty(value = "上侧规范 工序能力指数CPU") + private Double CPU; + //下侧规范 工序能力指数CPL + @ApiModelProperty(value = "下侧规范 工序能力指数CPL") + private Double CPL; + + @ApiModelProperty(value = "工序能力报警") + private List warming; + + public ProcessCapability(Double CP, Double CPK, Double CPU, Double CPL,List warming) { + this.CP = CP; + this.CPK = CPK; + this.CPU = CPU; + this.CPL = CPL; + this.warming = warming; + } +} diff --git a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/SpecificationLimit.java b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/SpecificationLimit.java index 592537d..138ba05 100644 --- a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/SpecificationLimit.java +++ b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/SpecificationLimit.java @@ -1,5 +1,7 @@ package com.cnbm.qualityPlanning.entity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** @@ -8,11 +10,21 @@ import lombok.Data; * @DATE: 2022/7/12 15:19 */ @Data +@ApiModel(value = "规格限") public class SpecificationLimit { //规格上限 - private Double USL; + @ApiModelProperty(value = "规格上限") + private Float USL; //规格中心线 - private Double SL; + @ApiModelProperty(value = "规格中心限") + private Float SL; //规格下限 - private Double LSL; + @ApiModelProperty(value = "规格下限") + private Float LSL; + + public SpecificationLimit(Float USL, Float SL, Float LSL) { + this.USL = USL; + this.SL = SL; + this.LSL = LSL; + } } diff --git a/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/XbarSPoint.java b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/XbarSPoint.java new file mode 100644 index 0000000..200f9cc --- /dev/null +++ b/ym-quality-planning/src/main/java/com/cnbm/qualityPlanning/entity/XbarSPoint.java @@ -0,0 +1,84 @@ +package com.cnbm.qualityPlanning.entity; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * @Desc: "整合,处理好 后的一行数据 (sampleSize 后的数据) " + * @Author: caixiang + * @DATE: 2022/7/21 9:43 + */ +public class XbarSPoint extends Point { + List data = new ArrayList<>(); + private Double xbar; + private Double s; + private Double r; + //position 是这个数据在数组中的位置 ;; value 是待被判读方案 分析的value(从 xbar、s、r 中选一) + public XbarSPoint(Integer position, Double value) { + super(position, value); + } +// + + + public Double getXbar() { + return xbar; + } + + public void setXbar(Double xbar) { + this.xbar = xbar; + } + + public Double getS() { + return s; + } + + public void setS(Double s) { + this.s = s; + } + + public Double getR() { + return r; + } + + public void setR(Double r) { + this.r = r; + } + + public XbarSPoint(Integer position, Double value, Double xbar, Double s, Double r) { + super(position,value); + this.xbar = xbar; + this.s = s; + this.r = r; + } + + @Override + public Integer getPosition() { + return super.getPosition(); + } + + @Override + public Double getValueForInterpretation() { + return super.getValueForInterpretation(); + } + + @Override + public Set getUnsatisfiedRules() { + return super.getUnsatisfiedRules(); + } + + @Override + public void setPosition(Integer position) { + super.setPosition(position); + } + + @Override + public void setValueForInterpretation(Double valueForInterpretation) { + super.setValueForInterpretation(valueForInterpretation); + } + + @Override + public void setUnsatisfiedRules(Set unsatisfiedRules) { + super.setUnsatisfiedRules(unsatisfiedRules); + } +}