diff --git a/adaptors/知物云es主题特征to中交华联.go b/adaptors/知物云es主题特征to中交华联.go index 024853b..c9349bc 100644 --- a/adaptors/知物云es主题特征to中交华联.go +++ b/adaptors/知物云es主题特征to中交华联.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "goInOut/consumers/GZG2ZJHL/protoFiles_zjhl" + "strconv" + "strings" //"goInOut/consumers/GZG2ZJHL/protoFiles_zjhl" "goInOut/consumers/HBJCAS" @@ -12,8 +14,6 @@ import ( "google.golang.org/protobuf/proto" "log" "math" - "strconv" - "strings" "time" ) @@ -77,22 +77,30 @@ func (the Adaptor_ZWYES_ZJHL) EsAggTopToHBJCAS(structId int64, factorId int, esA continue } + dataBody := the.EsAgg2StatisticData(factorId, monitorCode, dateBucket) + if dataBody == nil { + log.Printf("[s:%d,f:%d]测点[%d] 特征数据组包异常,跳过", structId, factorId, sensorId) + continue + } dataDefinition := &protoFiles_zjhl.DataDefinition{ DataType: protoFiles_zjhl.DataType_STATISTICS, //BridgeCode: fmt.Sprintf("%d", uniqueCode), //提示 不传该字段 - DataBody: the.EsAgg2StatisticData(factorId, monitorCode, dateBucket), + DataBody: dataBody, } + complexData.SensorData = append(complexData.SensorData, dataDefinition) } } v, _ := json.Marshal(complexData) - log.Printf("[s:%d,f:%d] 特征数据=> %s", structId, factorId, v) + log.Printf("[struct:%d,factor:%d] 特征数据=> %s", structId, factorId, v) result, _ = proto.Marshal(complexData) return result } func (the Adaptor_ZWYES_ZJHL) getMonitorTypeByFactorId(factorId int) protoFiles_zjhl.MonitoryType { - //桥墩倾斜 15 裂缝18 支座位移20 桥面振动28 加速度三项监测592 + //结构温度4 桥墩倾斜 15 裂缝18 支座位移20 桥面振动28 加速度三项监测592 switch factorId { + case 4: + return protoFiles_zjhl.MonitoryType_TMP case 15: return protoFiles_zjhl.MonitoryType_INC case 18: @@ -130,6 +138,25 @@ func (the Adaptor_ZWYES_ZJHL) EsAgg2StatisticData(factorId int, monitorCode int6 } switch factorId { + case 4: //结构温度 + dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_zjhl.StatisticData_Tmp{Tmp: &protoFiles_zjhl.TMPStatistic{ + MaxTemperature: float32(dateBucket.X.Max), + MinTemperature: float32(dateBucket.X.Min), + AvgTemperature: float32(avgValueX), + MaxDifference: float32(dateBucket.X.Max - dateBucket.X.Min), + }} + case 6: //索力 + dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_zjhl.StatisticData_Vic{Vic: &protoFiles_zjhl.VICStatistic{ + MaxValue: float32(dateBucket.X.Max), + MinValue: float32(dateBucket.X.Min), + AvgValue: float32(avgValueX), + RootMeanSquare: float32(rootMeanSquareX), + }} + case 11: //应变 + dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_zjhl.StatisticData_Rsg{Rsg: &protoFiles_zjhl.RSGStatistic{ + MaxAbsoluteValue: float32(maxAbsoluteValueX), + AvgValue: float32(avgValueX), + }} case 15: //倾角 dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_zjhl.StatisticData_Inc{Inc: &protoFiles_zjhl.INCStatistic{ MaxAbsoluteValueX: float32(maxAbsoluteValueX), @@ -176,10 +203,10 @@ func (the Adaptor_ZWYES_ZJHL) getUniqueCode(structId int64) (uniqueCode int64) { } func (the Adaptor_ZWYES_ZJHL) getPointCodeFromLabel(label string) int64 { - //解析label {13010600001} + //解析label {ID:6500030042} pointUniqueCode := int64(0) - if len(label) > 2 { - newLabel := strings.TrimLeft(label, "{") + if len(label) > 5 { + newLabel := strings.TrimLeft(label, "{ID:") str := strings.TrimRight(newLabel, "}") codeInt64, err := strconv.ParseInt(str, 10, 64) if err != nil { diff --git a/consumers/consumerGZG2ZJHL.go b/consumers/consumerGZG2ZJHL.go index 3083ce8..d216c21 100644 --- a/consumers/consumerGZG2ZJHL.go +++ b/consumers/consumerGZG2ZJHL.go @@ -131,7 +131,7 @@ func (the *consumerGZG2ZJHL) getStructIds() []int64 { func (the *consumerGZG2ZJHL) getEs1HourAggData() { start, end := utils.GetTimeRangeByHour(-1) log.Printf("查询数据时间范围 %s - %s", start, end) - hourFactorIds := []int{4} // 15, 18, 20 + hourFactorIds := []int{4, 6, 11} //4(温度),6索力, 15, 18, 20 structIds := the.getStructIds() for _, structId := range structIds { for _, factorId := range hourFactorIds { @@ -200,7 +200,7 @@ func (the *consumerGZG2ZJHL) crc16rc4(transBytes []byte) []byte { return dest1 } func (the *consumerGZG2ZJHL) getESQueryStrByHour(structureId int64, factorId int, start, end string) string { - aggSubSql := getEsAggSubSqlByFactorId(factorId) + aggSubSql := getEsAggSubSqlByZwyFactorId(factorId) esQuery := fmt.Sprintf(` { "size": 0, @@ -257,7 +257,7 @@ func (the *consumerGZG2ZJHL) getESQueryStrByHour(structureId int64, factorId int } func (the *consumerGZG2ZJHL) getESQueryStrBy10min(structureId int64, factorId int, start, end string) string { - aggSubSql := getEsAggSubSqlByFactorId(factorId) + aggSubSql := getEsAggSubSqlByZwyFactorId(factorId) esQuery := fmt.Sprintf(` { "size": 0, @@ -313,6 +313,96 @@ func (the *consumerGZG2ZJHL) getESQueryStrBy10min(structureId int64, factorId in return esQuery } +func getEsAggSubSqlByZwyFactorId(factorId int) string { + //桥墩倾斜 15 裂缝 18 支座位移20 桥面振动28 加速度三项监测592(承德隧道专用) + subAggSQl := "" + switch factorId { + case 4: //结构温度 + subAggSQl = ` +{ + "x": { + "extended_stats": { + "field": "data.temperature" + } + } +}` + case 6: // 索力 + subAggSQl = ` +{ + "x": { + "extended_stats": { + "field": "data.cableForce" + } + } +}` + case 11: //应变 + subAggSQl = ` +{ + "x": { + "extended_stats": { + "field": "data.strain" + } + } +}` + case 15: + subAggSQl = ` +{ + "x": { + "extended_stats": { + "field": "data.x" + } + }, + "y": { + "extended_stats": { + "field": "data.y" + } + } +}` + case 18: + subAggSQl = ` +{ + "x": { + "extended_stats": { + "field": "data.crack" + } + } +}` + case 20: + subAggSQl = ` +{ + "x": { + "extended_stats": { + "field": "data.displacement" + } + } +}` + case 28: + subAggSQl = ` +{ + "x": { + "extended_stats": { + "field": "data.pv" + } + }, + "y": { + "extended_stats": { + "field": "data.trms" + } + } +}` + case 592: + subAggSQl = ` +{ + "x": { + "extended_stats": { + "field": "data.z_acc_speed" + } + } +}` + } + return subAggSQl +} + func (the *consumerGZG2ZJHL) getStructureId() string { structureId, ok := the.Info.OtherInfo["structureId"] if !ok { diff --git a/consumers/consumerHBJCAS.go b/consumers/consumerHBJCAS.go index d0069ff..de30dc8 100644 --- a/consumers/consumerHBJCAS.go +++ b/consumers/consumerHBJCAS.go @@ -202,7 +202,7 @@ func (the *consumerHBJCAS) crc16rc4(transBytes []byte) []byte { return dest1 } func (the *consumerHBJCAS) getESQueryStrByHour(structureId int64, factorId int, start, end string) string { - aggSubSql := getEsAggSubSqlByFactorId(factorId) + aggSubSql := getEsAggSubSqlByAxyFactorId(factorId) esQuery := fmt.Sprintf(` { "size": 0, @@ -259,7 +259,7 @@ func (the *consumerHBJCAS) getESQueryStrByHour(structureId int64, factorId int, } func (the *consumerHBJCAS) getESQueryStrBy10min(structureId int64, factorId int, start, end string) string { - aggSubSql := getEsAggSubSqlByFactorId(factorId) + aggSubSql := getEsAggSubSqlByAxyFactorId(factorId) esQuery := fmt.Sprintf(` { "size": 0, @@ -315,12 +315,11 @@ func (the *consumerHBJCAS) getESQueryStrBy10min(structureId int64, factorId int, return esQuery } -func getEsAggSubSqlByFactorId(factorId int) string { +func getEsAggSubSqlByAxyFactorId(factorId int) string { //桥墩倾斜 15 裂缝 18 支座位移20 桥面振动28 加速度三项监测592(承德隧道专用) - //温度4 果子沟上报 subAggSQl := "" switch factorId { - case 4: + case 4: //结构温度 subAggSQl = ` { "x": { @@ -328,6 +327,24 @@ func getEsAggSubSqlByFactorId(factorId int) string { "field": "data.temperature" } } +}` + case 6: // 索力 + subAggSQl = ` +{ + "x": { + "extended_stats": { + "field": "data.cableForce" + } + } +}` + case 11: //应变 + subAggSQl = ` +{ + "x": { + "extended_stats": { + "field": "data.strain" + } + } }` case 15: subAggSQl = `