修改判读方案算法
This commit is contained in:
@@ -1,14 +1,8 @@
|
||||
import com.cnbm.influx.config.InfluxClient;
|
||||
import com.cnbm.influx.template.Event;
|
||||
import com.influxdb.client.InfluxDBClient;
|
||||
import com.influxdb.client.InfluxDBClientFactory;
|
||||
import com.influxdb.client.WriteApi;
|
||||
import com.influxdb.client.domain.WritePrecision;
|
||||
import com.influxdb.client.write.Point;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Desc: ""
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
package com.cnbm.influx;
|
||||
|
||||
import com.cnbm.influx.config.InfluxClient;
|
||||
import com.cnbm.influx.param.QueryDataParam;
|
||||
|
||||
import com.cnbm.influx.param.PageInfo;
|
||||
import com.cnbm.influx.param.Range;
|
||||
import com.cnbm.influx.param.Tag;
|
||||
|
||||
import com.cnbm.influx.template.Event;
|
||||
import com.influxdb.client.*;
|
||||
import com.influxdb.client.domain.WritePrecision;
|
||||
import com.influxdb.client.write.Point;
|
||||
import com.influxdb.query.FluxRecord;
|
||||
import com.influxdb.query.FluxTable;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -131,6 +125,8 @@ public class Main {
|
||||
// |> filter(fn: (r) => r["argName"] == "arg4")
|
||||
// |> drop(columns: ["transationId"])
|
||||
// |> sort(columns: ["_time"], desc: true)
|
||||
|
||||
// |> timeShift(duration: 12h) //用于时区转换
|
||||
// 取前10条数据
|
||||
// |> limit(n: 10, offset: 0)
|
||||
//
|
||||
@@ -142,31 +138,31 @@ public class Main {
|
||||
|
||||
|
||||
|
||||
QueryDataParam queryDataParam = new QueryDataParam();
|
||||
queryDataParam.setBucket("qgs-bucket");
|
||||
queryDataParam.setRange(new Range(getDate().toInstant(),new Date().toInstant()));
|
||||
queryDataParam.setMeasurement("WeightHeiHei");
|
||||
queryDataParam.setTag(new Tag("argName","LTWeight"));
|
||||
// queryDataParam.setDropedTagName("transationId");
|
||||
List<String> dropNames = new ArrayList<>();
|
||||
dropNames.add("transationId");
|
||||
dropNames.add("inspectionSheetId");
|
||||
dropNames.add("batchNum");
|
||||
queryDataParam.setDropedTagNames(dropNames);
|
||||
queryDataParam.setPageInfo(new PageInfo(1,10000));
|
||||
|
||||
List<FluxTable> tables = query(queryDataParam,influxDBClient);
|
||||
List<FluxRecord> records1 = tables.get(0).getRecords();
|
||||
// List<List<FluxRecord>> lists = Utils.fixedGroup(records1, 10);
|
||||
|
||||
for (FluxTable fluxTable : tables) {
|
||||
List<FluxRecord> records = fluxTable.getRecords();
|
||||
for (FluxRecord fluxRecord : records) {
|
||||
Instant timms = fluxRecord.getTime();
|
||||
System.out.println("time: "+fluxRecord.getTime() +" key:"+fluxRecord.getField()+" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement());
|
||||
|
||||
}
|
||||
}
|
||||
// QueryDataParam queryDataParam = new QueryDataParam();
|
||||
// queryDataParam.setBucket("qgs-bucket");
|
||||
// queryDataParam.setRange(new Range(getDate().toInstant(),new Date().toInstant()));
|
||||
// queryDataParam.setMeasurement("WeightHeiHei");
|
||||
// queryDataParam.setTag(new Tag("argName","LTWeight"));
|
||||
//// queryDataParam.setDropedTagName("transationId");
|
||||
// List<String> dropNames = new ArrayList<>();
|
||||
// dropNames.add("transationId");
|
||||
// dropNames.add("inspectionSheetId");
|
||||
// dropNames.add("batchNum");
|
||||
// queryDataParam.setDropedTagNames(dropNames);
|
||||
// queryDataParam.setPageInfo(new PageInfo(1,10000));
|
||||
//
|
||||
// List<FluxTable> tables = query(queryDataParam,influxDBClient);
|
||||
// List<FluxRecord> records1 = tables.get(0).getRecords();
|
||||
//// List<List<FluxRecord>> lists = Utils.fixedGroup(records1, 10);
|
||||
//
|
||||
// for (FluxTable fluxTable : tables) {
|
||||
// List<FluxRecord> records = fluxTable.getRecords();
|
||||
// for (FluxRecord fluxRecord : records) {
|
||||
// Instant timms = fluxRecord.getTime();
|
||||
// System.out.println("time: "+fluxRecord.getTime() +" key:"+fluxRecord.getField()+" value: " + fluxRecord.getValueByKey("_value")+" measurement: " + fluxRecord.getMeasurement());
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
influxDBClient.close();
|
||||
}
|
||||
@@ -221,4 +217,6 @@ public class Main {
|
||||
|
||||
return tables;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -77,12 +77,24 @@ public enum InfluxClient {
|
||||
}
|
||||
|
||||
public void insert(Event event, String measurement){
|
||||
Point 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);
|
||||
|
||||
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);
|
||||
}
|
||||
writeApi.writePoint(point);
|
||||
|
||||
}
|
||||
@@ -103,7 +115,7 @@ public enum InfluxClient {
|
||||
}else {
|
||||
point = Point.measurement(measurement)
|
||||
.addTag("transationId", event.getTransationId())
|
||||
.addTag("inspectionSheetId", event.getInspectionSheetId())
|
||||
//.addTag("inspectionSheetId", event.getInspectionSheetId())
|
||||
.addTag("batchNum", event.getBatchNum().toString())
|
||||
.addTag("argName", event.getArgName())
|
||||
.addField("argValue", event.getArgValue())
|
||||
@@ -130,6 +142,8 @@ public enum InfluxClient {
|
||||
flux += "|> range(start: "+range.getBegin()+",stop:"+range.getEnd()+")";
|
||||
flux += "|> filter(fn: (r) => r[\"_measurement\"] == \""+measurement+"\")";
|
||||
flux += "|> filter(fn: (r) => r[\""+tagName+"\"] == \""+tagValue+"\")";
|
||||
//调整时区,查询出的结果 +8个小时
|
||||
flux += "|> timeShift(duration: 8h)";
|
||||
for(String dropName:dropedTagNames){
|
||||
flux += "|> drop(columns: [\""+dropName+"\"])";
|
||||
}
|
||||
@@ -154,6 +168,7 @@ public enum InfluxClient {
|
||||
flux += "|> range(start: "+range.getBegin()+",stop:"+range.getEnd()+")";
|
||||
flux += "|> filter(fn: (r) => r[\"_measurement\"] == \""+measurement+"\")";
|
||||
flux += "|> filter(fn: (r) => r[\""+tagName+"\"] == \""+tagValue+"\")";
|
||||
flux += "|> timeShift(duration: 8h)";
|
||||
flux += "|> group(columns: [\""+groupName+"\"], mode: \"except\")";
|
||||
for(String dropName:dropedTagNames){
|
||||
flux += "|> drop(columns: [\""+dropName+"\"])";
|
||||
@@ -178,6 +193,7 @@ public enum InfluxClient {
|
||||
flux += "|> range(start: "+range.getBegin()+",stop:"+range.getEnd()+")";
|
||||
flux += "|> filter(fn: (r) => r[\"_measurement\"] == \""+measurement+"\")";
|
||||
flux += "|> filter(fn: (r) => r[\""+tagName+"\"] == \""+tagValue+"\")";
|
||||
flux += "|> timeShift(duration: 8h)";
|
||||
for(String dropName:dropedTagNames){
|
||||
flux += "|> drop(columns: [\""+dropName+"\"])";
|
||||
}
|
||||
@@ -205,4 +221,4 @@ public enum InfluxClient {
|
||||
// }
|
||||
return queryApi.query(flux);
|
||||
}
|
||||
}
|
||||
}
|
||||
78
ym-influx/src/main/java/com/cnbm/influx/config/Main.java
Normal file
78
ym-influx/src/main/java/com/cnbm/influx/config/Main.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package com.cnbm.influx.config;
|
||||
|
||||
import com.cnbm.common.spc.util.DataUtils;
|
||||
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.influxdb.client.InfluxDBClient;
|
||||
import com.influxdb.client.InfluxDBClientFactory;
|
||||
import com.influxdb.client.WriteApi;
|
||||
import com.influxdb.client.domain.WritePrecision;
|
||||
import com.influxdb.client.write.Point;
|
||||
import com.influxdb.query.FluxTable;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Desc: ""
|
||||
* @Author: caixiang
|
||||
* @DATE: 2022/11/30 16:56
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//方式一
|
||||
// char[] token = "lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw==".toCharArray();
|
||||
// String org = "qgs";
|
||||
// String bucket = "qgs-bucket";
|
||||
// InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://192.168.0.170:8086", token, org, bucket);
|
||||
//
|
||||
//
|
||||
// WriteApi writeApi = influxDBClient.makeWriteApi();
|
||||
//
|
||||
//
|
||||
//
|
||||
// Point point2 = Point.measurement("FORUPDATE")
|
||||
// .addTag("transationId", "222312")
|
||||
// .addTag("argName", "forUpdate")
|
||||
// .addField("argValue", 4D)
|
||||
// .time(Instant.now().toEpochMilli(), WritePrecision.MS);
|
||||
// List<Point> list = new ArrayList<>();
|
||||
// list.add(point2);
|
||||
//
|
||||
// writeApi.writePoints(list);
|
||||
|
||||
|
||||
//方式二
|
||||
Event event = new Event();
|
||||
|
||||
event.setTime(new Date().toInstant());
|
||||
event.setTransationId("2344");
|
||||
event.setBatchNum("22");
|
||||
event.setArgName("forUpdate");
|
||||
event.setArgValue("124.1");
|
||||
InfluxClient.Client.insert(event,"FORUPDATE");
|
||||
// Thread.sleep(50000);
|
||||
//
|
||||
// event.setArgValue(333.3);
|
||||
// InfluxClient.Client.insert(event,"FORUPDATE");
|
||||
|
||||
|
||||
QueryDataParam queryDataParam = new QueryDataParam();
|
||||
queryDataParam.setBucket("qgs-bucket");
|
||||
queryDataParam.setMeasurement("FORUPDATE");
|
||||
List<String> dropNames = new ArrayList<>();
|
||||
dropNames.add("transationId");
|
||||
dropNames.add("inspectionSheetId");
|
||||
queryDataParam.setDropedTagNames(dropNames);
|
||||
queryDataParam.setTag(new Tag("argName","forUpdate"));
|
||||
queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(),DataUtils.getAfterDate(999).toInstant()));
|
||||
queryDataParam.setPageInfo(new PageInfo(1,10));
|
||||
List<FluxTable> query = InfluxClient.Client.query(queryDataParam);
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
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;
|
||||
@@ -19,7 +17,6 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -40,11 +37,19 @@ public class S7DemoController {
|
||||
for(int i=0;i<999;i++){
|
||||
Thread.sleep(10);
|
||||
Event event = new Event();
|
||||
event.setTime(Instant.now());
|
||||
event.setTime(DataUtils.getAfterDate(i).toInstant());
|
||||
event.setTransationId("asas"+i);
|
||||
event.setArgName("LTWeight");
|
||||
Double d = r.nextDouble() * 2.5 + 66;
|
||||
event.setArgValue(d);
|
||||
event.setArgName("failDay");
|
||||
|
||||
int i1 = r.nextInt(10);
|
||||
if(i1<4){
|
||||
event.setArgValue("0");
|
||||
}else {
|
||||
event.setArgValue("1");
|
||||
}
|
||||
|
||||
// Double d = r.nextDouble() * 2.5 + 66;
|
||||
// event.setArgValue(d);
|
||||
|
||||
list.add(event);
|
||||
}
|
||||
@@ -63,8 +68,8 @@ public class S7DemoController {
|
||||
event.setTransationId("forbatch"+i);
|
||||
event.setArgName("LTWeight");
|
||||
Double d = r.nextDouble() * 2.5 + 66;
|
||||
event.setArgValue(d);
|
||||
event.setBatchNum(4);
|
||||
event.setArgValue(d.toString());
|
||||
event.setBatchNum(4+"");
|
||||
event.setInspectionSheetId(i+"");
|
||||
list.add(event);
|
||||
}
|
||||
@@ -86,14 +91,44 @@ public class S7DemoController {
|
||||
event.setArgName("LTWeight");
|
||||
Double d = r.nextDouble() * 2.5 + 66;
|
||||
event.setInspectionSheetId(j+"");
|
||||
event.setArgValue(d);
|
||||
event.setBatchNum(i);
|
||||
event.setArgValue(d.toString());
|
||||
event.setBatchNum(i+"");
|
||||
list.add(event);
|
||||
}
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list,"WeightHei");
|
||||
}
|
||||
|
||||
@PostMapping("/insertAndQuery")
|
||||
public void insertAndQuery() throws InterruptedException {
|
||||
Event event = new Event();
|
||||
|
||||
event.setTime(new Date().toInstant());
|
||||
event.setTransationId("2344");
|
||||
event.setBatchNum("22");
|
||||
event.setArgName("forUpdate");
|
||||
event.setArgValue("124.1");
|
||||
InfluxClient.Client.insert(event,"FORUPDATEEEE");
|
||||
// Thread.sleep(50000);
|
||||
//
|
||||
// event.setArgValue(333.3);
|
||||
// InfluxClient.Client.insert(event,"FORUPDATE");
|
||||
|
||||
|
||||
QueryDataParam queryDataParam = new QueryDataParam();
|
||||
queryDataParam.setBucket("qgs-bucket");
|
||||
queryDataParam.setMeasurement("FORUPDATEEEE");
|
||||
List<String> dropNames = new ArrayList<>();
|
||||
dropNames.add("transationId");
|
||||
dropNames.add("inspectionSheetId");
|
||||
queryDataParam.setDropedTagNames(dropNames);
|
||||
queryDataParam.setTag(new Tag("argName","forUpdate"));
|
||||
queryDataParam.setRange(new Range(DataUtils.getBeforeDate(999).toInstant(),DataUtils.getAfterDate(999).toInstant()));
|
||||
queryDataParam.setPageInfo(new PageInfo(1,10));
|
||||
List<FluxTable> query = InfluxClient.Client.query(queryDataParam);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/insertBatchJYDForTest")
|
||||
@@ -109,13 +144,13 @@ public class S7DemoController {
|
||||
event.setArgName("LostDays");
|
||||
int i1 = r.nextInt(10);
|
||||
if(i1<4){
|
||||
event.setArgValue(new Double(0));
|
||||
event.setArgValue("0");
|
||||
}else {
|
||||
event.setArgValue(new Double(1));
|
||||
event.setArgValue("1");
|
||||
}
|
||||
event.setInspectionSheetId(i+"");
|
||||
|
||||
event.setBatchNum(i);
|
||||
event.setBatchNum(i+"");
|
||||
list.add(event);
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list,"Weights");
|
||||
@@ -139,10 +174,10 @@ public class S7DemoController {
|
||||
// event.setArgValue(new Double(1));
|
||||
// }
|
||||
Double d = r.nextDouble() * 2.5 + 66;
|
||||
event.setArgValue(d);
|
||||
event.setArgValue(d.toString());
|
||||
event.setInspectionSheetId(i+"");
|
||||
|
||||
event.setBatchNum(i);
|
||||
event.setBatchNum(i+"");
|
||||
list.add(event);
|
||||
}
|
||||
InfluxClient.Client.batchInsert(list,"Weights");
|
||||
@@ -227,7 +262,7 @@ public class S7DemoController {
|
||||
event.setTime(Instant.now());
|
||||
event.setTransationId("asasd11");
|
||||
event.setArgName("argName11");
|
||||
event.setArgValue(900001d);
|
||||
event.setArgValue("900001");
|
||||
Point asProcessCompleteEvent = insert(event, "ASProcessCompleteEvent");
|
||||
InfluxClient.Client.insert(event,"ASProcessCompleteEvent");
|
||||
}
|
||||
|
||||
@@ -17,14 +17,18 @@ public class Event {
|
||||
|
||||
private Instant time;
|
||||
|
||||
private String inspectionSheetId;
|
||||
|
||||
private String transationId;
|
||||
|
||||
private String argName;
|
||||
|
||||
private Double argValue;
|
||||
private String argValue;
|
||||
|
||||
//批次号,可选的
|
||||
private Integer batchNum;
|
||||
private String BatchNum;
|
||||
|
||||
private String InspectionSheetId;
|
||||
|
||||
public Event() {
|
||||
BatchNum = "1";
|
||||
InspectionSheetId = "1";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user