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 45692d4..eb8dc4a 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/**", + // "/basic/**", // "/qualityPlanning/**", // "/processInspection/**", diff --git a/ym-common/pom.xml b/ym-common/pom.xml index e71100a..2e5bb82 100644 --- a/ym-common/pom.xml +++ b/ym-common/pom.xml @@ -15,5 +15,12 @@ ${project.artifactId} + + + org.apache.commons + commons-math3 + 3.6.1 + + \ No newline at end of file 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 602548e..386fb4a 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 @@ -28,7 +28,6 @@ public class Math { d[6] = new Double(10.2); d[7] = new Double(11.7); - ; System.out.println("均值: "+getMean(d)+",,标准差:"+StandardDiviation(d)+",极差:"+range(d)); } diff --git a/ym-common/src/main/java/com/cnbm/common/spc/math/Matrix.java b/ym-common/src/main/java/com/cnbm/common/spc/math/Matrix.java new file mode 100644 index 0000000..2476988 --- /dev/null +++ b/ym-common/src/main/java/com/cnbm/common/spc/math/Matrix.java @@ -0,0 +1,793 @@ +package com.cnbm.common.spc.math; + +import com.cnbm.common.spc.math.entity.T2GraphEntity; +import org.apache.commons.math3.distribution.FDistribution; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Arrays; +import java.util.List; + +/** + * @Desc: "" + * @Author: caixiang + * @DATE: 2022/9/2 15:33 + */ +public class Matrix { +// public static void main(String[] args) { +// double[] xbarbar = new double[2]; +// xbarbar[0] = 115.6084; +// xbarbar[1] = 1.0564; +// +// double[] xi = new double[2]; +// xi[0] = 115.84; +// xi[1] = 1.078; +// +// double[] xi2 = new double[2]; +// xi2[0] = 115.76; +// xi2[1] = 1.072; +// +// double[] xi3 = new double[2]; +// xi3[0] = 115.11; +// xi3[1] = 1.015; +// +// double[] xi4 = new double[2]; +// xi4[0] = 116.02; +// xi4[1] = 1.089; +// +// double[] xi5 = new double[2]; +// xi5[0] = 115.80; +// xi5[1] = 1.090; +// +// System.out.println("Ti1:"+ forTi2(xi,xbarbar)*10); +// System.out.println("Ti2:"+ forTi2(xi2,xbarbar)*10); +// System.out.println("Ti3:"+ forTi2(xi3,xbarbar)*10); +// System.out.println("Ti4:"+ forTi2(xi4,xbarbar)*10); +// System.out.println("Ti4:"+ forTi2(xi5,xbarbar)*10); +//// double ti = 10*() +// +// +// +// //创建一个F分布对象,参数为自由度 +// FDistribution fd = new FDistribution(2,179); +// //当α=0.05时,参数为1-α=0.95 +// double v = fd.inverseCumulativeProbability(0.99865); +// //输出值 +// System.out.println("v: "+v*342/179); +// +// +// //m = 25 n = 1 p = 3 +// FDistribution fd2 = new FDistribution(3,21); +// //当α=0.05时,参数为1-α=0.95 +// double v2 = fd2.inverseCumulativeProbability(0.99865); +// //输出值 +// System.out.println("v2: "+v2); +// } + +// public static void main(String[] args) { +// +// double[] xlv = new double[5]; +// xlv[0] = 155; +// xlv[1] = 170; +// xlv[2] = 160; +// xlv[3] = 162; +// xlv[4] = 163; +// +// double[] weigth = new double[5]; +// weigth[0] = 125; +// weigth[1] = 162; +// weigth[2] = 139; +// weigth[3] = 150; +// weigth[4] = 146; +// +// double x1bar = getBar(xlv); +// double x2bar = getBar(weigth); +// System.out.println(); +// double s11 = forS11(xlv,x1bar); +// double s12 = forS12(weigth,x1bar,xlv,x2bar); +// double s22 = forS22(weigth,x2bar); +// System.out.println(); +// +// } + + + public static double[][] initialDemoSource(){ + double[][] source = new double[60][6]; + source[0][0] = 1; + source[0][1] = 1; + source[0][2] = 155; + source[0][3] = 100; + source[0][4] = 60; + source[0][5] = 125; + + source[1][0] = 1; + source[1][1] = 2; + source[1][2] = 170; + source[1][3] = 120; + source[1][4] = 82; + source[1][5] = 162; + + source[2][0] = 1; + source[2][1] = 3; + source[2][2] = 160; + source[2][3] = 132; + source[2][4] = 71; + source[2][5] = 139; + + source[3][0] = 1; + source[3][1] = 4; + source[3][2] = 162; + source[3][3] = 139; + source[3][4] = 70; + source[3][5] = 150; + + source[4][0] = 1; + source[4][1] = 5; + source[4][2] = 163; + source[4][3] = 110; + source[4][4] = 80; + source[4][5] = 146; + + source[5][0] = 2; + source[5][1] = 1; + source[5][2] = 157; + source[5][3] = 110; + source[5][4] = 59; + source[5][5] = 124; + + source[6][0] = 2; + source[6][1] = 2; + source[6][2] = 171; + source[6][3] = 122; + source[6][4] = 81; + source[6][5] = 163; + + source[7][0] = 2; + source[7][1] = 3; + source[7][2] = 162; + source[7][3] = 133; + source[7][4] = 73; + source[7][5] = 139; + + source[8][0] = 2; + source[8][1] = 4; + source[8][2] = 165; + source[8][3] = 140; + source[8][4] = 72; + source[8][5] = 152; + + source[9][0] = 2; + source[9][1] = 5; + source[9][2] = 161; + source[9][3] = 112; + source[9][4] = 81; + source[9][5] = 147; + + source[10][0] = 3; + source[10][1] = 1; + source[10][2] = 153; + source[10][3] = 110; + source[10][4] = 63; + source[10][5] = 123; + + + source[11][0] = 3; + source[11][1] = 2; + source[11][2] = 169; + source[11][3] = 120; + source[11][4] = 86; + source[11][5] = 161; + + + source[12][0] = 3; + source[12][1] = 3; + source[12][2] = 161; + source[12][3] = 133; + source[12][4] = 79; + source[12][5] = 141; + + + source[13][0] = 3; + source[13][1] = 4; + source[13][2] = 160; + source[13][3] = 140; + source[13][4] = 72; + source[13][5] = 153; + + + source[14][0] = 3; + source[14][1] = 5; + source[14][2] = 159; + source[14][3] = 118; + source[14][4] = 82; + source[14][5] = 149; + + source[15][0] = 4; + source[15][1] = 1; + source[15][2] = 157; + source[15][3] = 109; + source[15][4] = 60; + source[15][5] = 126; + + + source[16][0] = 4; + source[16][1] = 2; + source[16][2] = 171; + source[16][3] = 126; + source[16][4] = 81; + source[16][5] = 163; + + + source[17][0] = 4; + source[17][1] = 3; + source[17][2] = 162; + source[17][3] = 135; + source[17][4] = 72; + source[17][5] = 142; + + + source[18][0] = 4; + source[18][1] = 4; + source[18][2] = 163; + source[18][3] = 135; + source[18][4] = 70; + source[18][5] = 151; + + + source[19][0] = 4; + source[19][1] = 5; + source[19][2] = 164; + source[19][3] = 108; + source[19][4] = 72; + source[19][5] = 147; + + source[20][0] = 5; + source[20][1] = 1; + source[20][2] = 156; + source[20][3] = 108; + source[20][4] = 70; + source[20][5] = 126; + + + source[21][0] = 5; + source[21][1] = 2; + source[21][2] = 172; + source[21][3] = 113; + source[21][4] = 80; + source[21][5] = 162; + + + source[22][0] = 5; + source[22][1] = 3; + source[22][2] = 162; + source[22][3] = 130; + source[22][4] = 70; + source[22][5] = 141; + + + source[23][0] = 5; + source[23][1] = 4; + source[23][2] = 162; + source[23][3] = 142; + source[23][4] = 76; + source[23][5] = 150; + + + source[24][0] = 5; + source[24][1] = 5; + source[24][2] = 164; + source[24][3] = 110; + source[24][4] = 83; + source[24][5] = 146; + + source[25][0] = 6; + source[25][1] = 1; + source[25][2] = 157; + source[25][3] = 100; + source[25][4] = 60; + source[25][5] = 128; + + + source[26][0] = 6; + source[26][1] = 2; + source[26][2] = 167; + source[26][3] = 122; + source[26][4] = 80; + source[26][5] = 162; + + + source[27][0] = 6; + source[27][1] = 3; + source[27][2] = 156; + source[27][3] = 133; + source[27][4] = 73; + source[27][5] = 142; + + + source[28][0] = 6; + source[28][1] = 4; + source[28][2] = 161; + source[28][3] = 140; + source[28][4] = 76; + source[28][5] = 150; + + + source[29][0] = 6; + source[29][1] = 5; + source[29][2] = 164; + source[29][3] = 111; + source[29][4] = 82; + source[29][5] = 147; + + source[30][0] = 7; + source[30][1] = 1; + source[30][2] = 157; + source[30][3] = 106; + source[30][4] = 62; + source[30][5] = 127; + + + source[31][0] = 7; + source[31][1] = 2; + source[31][2] = 167; + source[31][3] = 130; + source[31][4] = 83; + source[31][5] = 162; + + + source[32][0] = 7; + source[32][1] = 3; + source[32][2] = 162; + source[32][3] = 125; + source[32][4] = 73; + source[32][5] = 142; + + + source[33][0] = 7; + source[33][1] = 4; + source[33][2] = 161; + source[33][3] = 144; + source[33][4] = 76; + source[33][5] = 152; + + + source[34][0] = 7; + source[34][1] = 5; + source[34][2] = 160; + source[34][3] = 118; + source[34][4] = 85; + source[34][5] = 147; + + source[35][0] = 8; + source[35][1] = 1; + source[35][2] = 159; + source[35][3] = 108; + source[35][4] = 62; + source[35][5] = 128; + + + source[36][0] = 8; + source[36][1] = 2; + source[36][2] = 167; + source[36][3] = 118; + source[36][4] = 84; + source[36][5] = 162; + + + source[37][0] = 8; + source[37][1] = 3; + source[37][2] = 161; + source[37][3] = 120; + source[37][4] = 73; + source[37][5] = 144; + + + source[38][0] = 8; + source[38][1] = 4; + source[38][2] = 164; + source[38][3] = 135; + source[38][4] = 76; + source[38][5] = 151; + + + source[39][0] = 8; + source[39][1] = 5; + source[39][2] = 160; + source[39][3] = 101; + source[39][4] = 81; + source[39][5] = 146; + + source[40][0] = 9; + source[40][1] = 1; + source[40][2] = 157; + source[40][3] = 97; + source[40][4] = 57; + source[40][5] = 126; + + + source[41][0] = 9; + source[41][1] = 2; + source[41][2] = 171; + source[41][3] = 130; + source[41][4] = 72; + source[41][5] = 162; + + + source[42][0] = 9; + source[42][1] = 3; + source[42][2] = 162; + source[42][3] = 134; + source[42][4] = 68; + source[42][5] = 144; + + + source[43][0] = 9; + source[43][1] = 4; + source[43][2] = 164; + source[43][3] = 143; + source[43][4] = 70; + source[43][5] = 150; + + + source[44][0] = 9; + source[44][1] = 5; + source[44][2] = 166; + source[44][3] = 114; + source[44][4] = 80; + source[44][5] = 147; + + + source[45][0] = 10; + source[45][1] = 1; + source[45][2] = 157; + source[45][3] = 107; + source[45][4] = 62; + source[45][5] = 124; + + + source[46][0] = 10; + source[46][1] = 2; + source[46][2] = 172; + source[46][3] = 122; + source[46][4] = 81; + source[46][5] = 160; + + + source[47][0] = 10; + source[47][1] = 3; + source[47][2] = 163; + source[47][3] = 135; + source[47][4] = 72; + source[47][5] = 143; + + + source[48][0] = 10; + source[48][1] = 4; + source[48][2] = 164; + source[48][3] = 141; + source[48][4] = 70; + source[48][5] = 148; + + + source[49][0] = 10; + source[49][1] = 5; + source[49][2] = 166; + source[49][3] = 118; + source[49][4] = 82; + source[49][5] = 146; + + source[50][0] = 11; + source[50][1] = 1; + source[50][2] = 152; + source[50][3] = 106; + source[50][4] = 62; + source[50][5] = 124; + + + source[51][0] = 11; + source[51][1] = 2; + source[51][2] = 167; + source[51][3] = 122; + source[51][4] = 82; + source[51][5] = 162; + + + source[52][0] = 11; + source[52][1] = 3; + source[52][2] = 158; + source[52][3] = 137; + source[52][4] = 74; + source[52][5] = 146; + + + source[53][0] = 11; + source[53][1] = 4; + source[53][2] = 159; + source[53][3] = 146; + source[53][4] = 72; + source[53][5] = 150; + + + source[54][0] = 11; + source[54][1] = 5; + source[54][2] = 160; + source[54][3] = 98; + source[54][4] = 82; + source[54][5] = 145; + + source[55][0] = 12; + source[55][1] = 1; + source[55][2] = 153; + source[55][3] = 106; + source[55][4] = 62; + source[55][5] = 122; + + + source[56][0] = 12; + source[56][1] = 2; + source[56][2] = 168; + source[56][3] = 125; + source[56][4] = 85; + source[56][5] = 164; + + + source[57][0] = 12; + source[57][1] = 3; + source[57][2] = 159; + source[57][3] = 137; + source[57][4] = 72; + source[57][5] = 144; + + + source[58][0] = 12; + source[58][1] = 4; + source[58][2] = 162; + source[58][3] = 146; + source[58][4] = 73; + source[58][5] = 149; + + + source[59][0] = 12; + source[59][1] = 5; + source[59][2] = 167; + source[59][3] = 99; + source[59][4] = 70; + source[59][5] = 148; + return source; + } + + public static void main(String[] args) { + double[][] source = initialDemoSource(); + + T2GraphEntity[] all = new T2GraphEntity[12]; + + //取值 + for(int i=1;i<=12;i++){ + T2GraphEntity t = new T2GraphEntity(); + + for(int j=0;j list){ + Double[] doubles=new Double[list.size()]; + list.toArray(doubles); + if(doubles==null){ + return null; + } + double[] result=new double[doubles.length]; + for(int i=0;i x1Source; + private List x2Source; + + public T2GraphEntity(){ + x1Source = new ArrayList<>(); + x2Source = new ArrayList<>(); + + } + +} diff --git a/ym-gateway/src/main/resources/application-dev.yml b/ym-gateway/src/main/resources/application-dev.yml index be3f5ed..e7cc7d1 100644 --- a/ym-gateway/src/main/resources/application-dev.yml +++ b/ym-gateway/src/main/resources/application-dev.yml @@ -65,16 +65,16 @@ spring: # username: postgres # password: 123456 -influx: - url: http://192.168.0.170:8086 # URL to connect to InfluxDB. - username: caixiang # Username to use in the basic auth. - password: 251128856 # Password to use in the basic auth. - token: lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw== # Token to use for the authorization. - org: qgs # Default destination organization for writes and queries. - bucket: qgs-bucket # Default destination bucket for writes. - logLevel: BODY # The log level for logging the HTTP request and HTTP response. (Default: NONE) - readTimeout: 5s # Read timeout for OkHttpClient. (Default: 10s) - writeTimeout: 5s # Write timeout for OkHttpClient. (Default: 10s) - connectTimeout: 5s # Connection timeout for OkHttpClient. (Default: 10s) +#influx: +# url: http://192.168.0.170:8086 # URL to connect to InfluxDB. +# username: caixiang # Username to use in the basic auth. +# password: 251128856 # Password to use in the basic auth. +# token: lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw== # Token to use for the authorization. +# org: qgs # Default destination organization for writes and queries. +# bucket: qgs-bucket # Default destination bucket for writes. +# logLevel: BODY # The log level for logging the HTTP request and HTTP response. (Default: NONE) +# readTimeout: 5s # Read timeout for OkHttpClient. (Default: 10s) +# writeTimeout: 5s # Write timeout for OkHttpClient. (Default: 10s) +# connectTimeout: 5s # Connection timeout for OkHttpClient. (Default: 10s) # management.health.influx.enabled=true # Whether to enable InfluxDB 2.x health check. \ No newline at end of file diff --git a/ym-influx/pom.xml b/ym-influx/pom.xml index 423bd98..23b5b7e 100644 --- a/ym-influx/pom.xml +++ b/ym-influx/pom.xml @@ -23,6 +23,8 @@ influxdb-client-java 6.3.0 + + com.cnbm ym-common diff --git a/ym-influx/src/main/java/com/cnbm/influx/config/InfluxClient.java b/ym-influx/src/main/java/com/cnbm/influx/config/InfluxClient.java index f88342c..6f04fae 100644 --- a/ym-influx/src/main/java/com/cnbm/influx/config/InfluxClient.java +++ b/ym-influx/src/main/java/com/cnbm/influx/config/InfluxClient.java @@ -92,13 +92,25 @@ public enum InfluxClient { public void batchInsert(List events, String measurement){ List list = new ArrayList<>(); for(Event event:events){ - Point point = Point.measurement(measurement) - .addTag("transationId", event.getTransationId()) - .addTag("inspectionSheetId", event.getInspectionSheetId()) - .addTag("batchNum", event.getBatchNum().toString()) - .addTag("argName", event.getArgName()) - .addField("argValue", event.getArgValue()) - .time(event.getTime().toEpochMilli(), WritePrecision.MS); + Point point = null; + if(event.getBatchNum()==null){ + point = Point.measurement(measurement) + .addTag("transationId", event.getTransationId()) + .addTag("inspectionSheetId", event.getInspectionSheetId()) + .addTag("argName", event.getArgName()) + .addField("argValue", event.getArgValue()) + .time(event.getTime().toEpochMilli(), WritePrecision.MS); + }else { + point = Point.measurement(measurement) + .addTag("transationId", event.getTransationId()) + .addTag("inspectionSheetId", event.getInspectionSheetId()) + .addTag("batchNum", event.getBatchNum().toString()) + .addTag("argName", event.getArgName()) + .addField("argValue", event.getArgValue()) + .time(event.getTime().toEpochMilli(), WritePrecision.MS); + } + + list.add(point); } writeApi.writePoints(list); @@ -125,16 +137,31 @@ public enum InfluxClient { if(pageInfo!=null){ flux += "|> limit(n: "+pageInfo.getSize()+", offset: "+(pageInfo.getCurrent()-1)* pageInfo.getSize()+")"; } + return queryApi.query(flux); + } + public List queryByGroup(QueryDataParam param){ + String measurement = param.getMeasurement(); + List dropedTagNames = param.getDropedTagNames(); + Range range = param.getRange(); + String bucket = param.getBucket(); + String tagName = param.getTag().getTagName(); + String tagValue = param.getTag().getTagValue(); + String groupName = param.getGroupName(); + PageInfo pageInfo = param.getPageInfo(); -// 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()); -// -// } -// } + String flux = "from(bucket:\""+bucket+"\")"; + flux += "|> range(start: "+range.getBegin()+",stop:"+range.getEnd()+")"; + flux += "|> filter(fn: (r) => r[\"_measurement\"] == \""+measurement+"\")"; + flux += "|> filter(fn: (r) => r[\""+tagName+"\"] == \""+tagValue+"\")"; + flux += "|> group(columns: [\""+groupName+"\"], mode: \"except\")"; + for(String dropName:dropedTagNames){ + flux += "|> drop(columns: [\""+dropName+"\"])"; + } + flux += "|> sort(columns: [\"_time\"], desc: true)"; + if(pageInfo!=null){ + flux += "|> limit(n: "+pageInfo.getSize()+", offset: "+(pageInfo.getCurrent()-1)* pageInfo.getSize()+")"; + } return queryApi.query(flux); } diff --git a/ym-influx/src/main/java/com/cnbm/influx/constant/Constant.java b/ym-influx/src/main/java/com/cnbm/influx/constant/Constant.java index ebf4cbf..2c3f07a 100644 --- a/ym-influx/src/main/java/com/cnbm/influx/constant/Constant.java +++ b/ym-influx/src/main/java/com/cnbm/influx/constant/Constant.java @@ -18,7 +18,7 @@ public class Constant { public static final LogLevel readTimeout = LogLevel.BODY; public static final LogLevel writeTimeout = LogLevel.BODY; public static final LogLevel connectTimeout = LogLevel.BODY; - public static final String measurement = "WeightHeiHei"; + public static final String measurement = "Weights"; } diff --git a/ym-influx/src/main/java/com/cnbm/influx/controller/S7DemoController.java b/ym-influx/src/main/java/com/cnbm/influx/controller/S7DemoController.java index aadadcc..838bc47 100644 --- a/ym-influx/src/main/java/com/cnbm/influx/controller/S7DemoController.java +++ b/ym-influx/src/main/java/com/cnbm/influx/controller/S7DemoController.java @@ -1,6 +1,8 @@ package com.cnbm.influx.controller; 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.param.PageInfo; import com.cnbm.influx.param.QueryDataParam; @@ -43,6 +45,27 @@ public class S7DemoController { event.setArgName("LTWeight"); Double d = r.nextDouble() * 2.5 + 66; event.setArgValue(d); + + list.add(event); + } + InfluxClient.Client.batchInsert(list,"Weight"); + } + + @PostMapping("/forTestInsertBatch") + public void forTestInsertBatch() throws InterruptedException { + List list = new ArrayList<>(); + Random r = new Random(); + + for(int i=0;i<99;i++){ + Thread.sleep(10); + Event event = new Event(); + event.setTime(Instant.now()); + event.setTransationId("forbatch"+i); + event.setArgName("LTWeight"); + Double d = r.nextDouble() * 2.5 + 66; + event.setArgValue(d); + event.setBatchNum(4); + event.setInspectionSheetId(i+""); list.add(event); } InfluxClient.Client.batchInsert(list,"Weight"); @@ -71,6 +94,8 @@ public class S7DemoController { InfluxClient.Client.batchInsert(list,"WeightHei"); } + + @PostMapping("/insertBatchJYDForTest") public void insertBatchJYDForTest() throws InterruptedException { List list = new ArrayList<>(); @@ -88,13 +113,39 @@ public class S7DemoController { }else { event.setArgValue(new Double(1)); } - event.setInspectionSheetId(i+""); event.setBatchNum(i); list.add(event); } - InfluxClient.Client.batchInsert(list,"WeightHeiHei"); + InfluxClient.Client.batchInsert(list,"Weights"); + } + + @PostMapping("/insertBatchForNew") + public void insertBatchForNew() throws InterruptedException { + List list = new ArrayList<>(); + Random r = new Random(); + + for(int i=0;i<999;i++){ + Thread.sleep(10); + Event event = new Event(); + event.setTime(new Date().toInstant()); + event.setTransationId("asas"+i); + event.setArgName("LiuWeight"); +// int i1 = r.nextInt(10); +// if(i1<4){ +// event.setArgValue(new Double(0)); +// }else { +// event.setArgValue(new Double(1)); +// } + Double d = r.nextDouble() * 2.5 + 66; + event.setArgValue(d); + event.setInspectionSheetId(i+""); + + event.setBatchNum(i); + list.add(event); + } + InfluxClient.Client.batchInsert(list,"Weights"); } /** @@ -131,7 +182,6 @@ public class S7DemoController { List records = fluxTable.getRecords(); for (FluxRecord fluxRecord : records) { System.out.println("value: " + fluxRecord.getValueByKey("_value")); - } } System.out.println(); @@ -157,7 +207,6 @@ public class S7DemoController { List records = fluxTable.getRecords(); for (FluxRecord fluxRecord : records) { System.out.println("value: " + fluxRecord.getValueByKey("_value")); - } } } diff --git a/ym-influx/src/main/java/com/cnbm/influx/param/QueryDataParam.java b/ym-influx/src/main/java/com/cnbm/influx/param/QueryDataParam.java index 67b1746..f88ce6c 100644 --- a/ym-influx/src/main/java/com/cnbm/influx/param/QueryDataParam.java +++ b/ym-influx/src/main/java/com/cnbm/influx/param/QueryDataParam.java @@ -29,5 +29,6 @@ public class QueryDataParam extends BaseParam{ //查询的时候,需要忽略的字段。(transationId是唯一标识会对 最终的查询结果集产生影响) private List dropedTagNames; private String bucket; + private String groupName; } 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 index fb870b4..2de9d4d 100644 --- 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 @@ -6,10 +6,13 @@ import com.cnbm.basic.service.IProductFeaturesService; import com.cnbm.common.spc.math.StandardDiviation; import com.cnbm.common.spc.util.DataUtils; import com.cnbm.common.vo.R; +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.Range; +import com.cnbm.influx.param.Tag; +import com.cnbm.influx.template.Event; import com.cnbm.processInspection.dto.*; import com.cnbm.processInspection.graphAnalyzed.forCount.c.CGraph; import com.cnbm.processInspection.graphAnalyzed.forCount.np.NPGraph; @@ -18,6 +21,8 @@ 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; +import com.influxdb.query.FluxRecord; +import com.influxdb.query.FluxTable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; @@ -30,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController; import java.time.Instant; import java.util.ArrayList; import java.util.List; +import java.util.Random; @RestController @RequestMapping("/processInspection") @@ -46,7 +52,7 @@ public class ProcessInspectionController { productFeatures.setUsl(new Float(10)); productFeatures.setLsl(new Float(1)); - productFeatures.setName("LTWeight"); + productFeatures.setName("LostDays"); productFeatures.setSampleSize(10); MeanStandardDeviationGraph meanStandardDeviationGraph = new MeanStandardDeviationGraph(productFeatures); //判读方案 @@ -58,7 +64,7 @@ public class ProcessInspectionController { QueryDataParam queryDataParam = new QueryDataParam(); queryDataParam.setMeasurement(Constant.measurement); - queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(), Instant.now())); + queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); meanStandardDeviationGraph.initialDate(queryDataParam); XbarSGraphData xbarSGraphData = new XbarSGraphData( @@ -75,12 +81,13 @@ public class ProcessInspectionController { @PostMapping("/XbarRGraphTest") public R XbarRGraphTest() throws Exception { + //todo SL/USL/LSL 和 sampleSize 需要从外面传过来。 ProductFeatures productFeatures = new ProductFeatures(); productFeatures.setSl(new Float(5)); productFeatures.setUsl(new Float(10)); productFeatures.setLsl(new Float(1)); - productFeatures.setName("LTWeight"); + productFeatures.setName("LostDays"); productFeatures.setSampleSize(10); MeanRGraph meanRGraph = new MeanRGraph(productFeatures); //判读方案 @@ -92,7 +99,7 @@ public class ProcessInspectionController { QueryDataParam queryDataParam = new QueryDataParam(); queryDataParam.setMeasurement(Constant.measurement); - queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(), Instant.now())); + queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); meanRGraph.initialDate(queryDataParam); XbarRGraphData xbarSGraphData = new XbarRGraphData( @@ -113,7 +120,7 @@ public class ProcessInspectionController { productFeatures.setUsl(new Float(10)); productFeatures.setLsl(new Float(1)); - productFeatures.setName("LTWeight"); + productFeatures.setName("LostDays"); productFeatures.setSampleSize(1); XMRGraph xmrGraph = new XMRGraph(productFeatures); //判读方案 @@ -125,7 +132,7 @@ public class ProcessInspectionController { QueryDataParam queryDataParam = new QueryDataParam(); queryDataParam.setMeasurement(Constant.measurement); - queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(), Instant.now())); + queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); xmrGraph.initialDate(queryDataParam); XMRGraphData xmrGraphData = new XMRGraphData( @@ -139,6 +146,45 @@ public class ProcessInspectionController { return R.ok("成功",xmrGraphData); } + + @PostMapping("/getBatchs") + public R> getBatchs() throws InterruptedException { + List list = new ArrayList<>(); + Random r = new Random(); + Instant instant = DataUtils.getBeforeDate(400).toInstant(); + List res = new ArrayList<>(); + + QueryDataParam queryDataParam = new QueryDataParam(); + queryDataParam.setBucket("qgs-bucket"); + queryDataParam.setMeasurement("Weight"); + List dropNames = new ArrayList<>(); + dropNames.add("transationId"); + dropNames.add("_value"); + dropNames.add("_start"); + dropNames.add("_stop"); + dropNames.add("_time"); + dropNames.add("_field"); + dropNames.add("_measurement"); + dropNames.add("inspectionSheetId"); + dropNames.add("argName"); + queryDataParam.setDropedTagNames(dropNames); + queryDataParam.setTag(new Tag("argName","LTWeight")); + queryDataParam.setRange(new Range(DataUtils.getBeforeDate(100).toInstant(),Instant.now())); +// queryDataParam.setPageInfo(new PageInfo(1,10)); + List query = InfluxClient.Client.queryByGroup(queryDataParam); + + + for (FluxTable fluxTable : query) { + List records = fluxTable.getRecords(); + if(records.size()!=0){ + res.add((String) records.get(0).getValueByKey("batchNum")); + continue; + } + } + return R.ok(res); + } + + @PostMapping("/NPGraphTest") public R NPGraphTest() throws Exception { ProductFeatures productFeatures = new ProductFeatures(); @@ -152,7 +198,7 @@ public class ProcessInspectionController { QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); queryDataParam.setMeasurement(Constant.measurement); - queryDataParam.setRange(new Range( Instant.now() , DataUtils.getAfterDate(999).toInstant() )); + queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); queryDataParam.setTimeType(1); npGraph.initialDate(queryDataParam); @@ -177,7 +223,7 @@ public class ProcessInspectionController { QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); queryDataParam.setMeasurement(Constant.measurement); - queryDataParam.setRange(new Range( Instant.now() , DataUtils.getAfterDate(999).toInstant() )); + queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); queryDataParam.setTimeType(2); pGraph.initialDate(queryDataParam); @@ -201,8 +247,10 @@ public class ProcessInspectionController { QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); + //到时候 要看前端 传的,这里的measurement 其实就是 设备名。 queryDataParam.setMeasurement(Constant.measurement); - queryDataParam.setRange(new Range( Instant.now() , DataUtils.getAfterDate(999).toInstant() )); +// queryDataParam.setRange(new Range(DataUtils.getBeforeDate(10).toInstant(), Instant.now())); + queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); queryDataParam.setTimeType(2); cGraph.initialDate(queryDataParam); @@ -228,7 +276,7 @@ public class ProcessInspectionController { QueryDataGroupByTimeParam queryDataParam = new QueryDataGroupByTimeParam(); queryDataParam.setMeasurement(Constant.measurement); - queryDataParam.setRange(new Range( Instant.now() , DataUtils.getAfterDate(999).toInstant() )); + queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(), DataUtils.getAfterDate(999).toInstant() )); queryDataParam.setTimeType(2); uGraph.initialDate(queryDataParam); diff --git a/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XMRGraphData.java b/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XMRGraphData.java index 3842102..cce81e8 100644 --- a/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XMRGraphData.java +++ b/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XMRGraphData.java @@ -15,7 +15,7 @@ import lombok.Data; * @DATE: 2022/7/22 14:18 */ @Data -@ApiModel(value = "均值极差控制图 结果类") +@ApiModel(value = "单值-移动极差 结果类") public class XMRGraphData { @ApiModelProperty(value = "控制图list数据") private XMRGraphEntity xmrGraphEntity; diff --git a/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XbarRGraphData.java b/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XbarRGraphData.java index 92132ec..4235b87 100644 --- a/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XbarRGraphData.java +++ b/ym-process-inspection/src/main/java/com/cnbm/processInspection/dto/XbarRGraphData.java @@ -15,7 +15,7 @@ import lombok.Data; * @DATE: 2022/7/22 14:18 */ @Data -@ApiModel(value = "均值极差控制图 结果类") +@ApiModel(value = "均值-极差控制图 结果类") public class XbarRGraphData { @ApiModelProperty(value = "控制图list数据") private MRGraphEntity mrGraphEntity; 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 index 2798f71..3cb827c 100644 --- 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 @@ -15,7 +15,7 @@ import lombok.Data; * @DATE: 2022/7/22 14:18 */ @Data -@ApiModel(value = "均值标准差控制图 结果类") +@ApiModel(value = "均值-标准差控制图 结果类") public class XbarSGraphData { @ApiModelProperty(value = "控制图list数据") private MSDGraphEntity msdGraphEntity;