|
|
@ -2,12 +2,11 @@ package adaptors |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"goInOut/consumers/GDJKJC" |
|
|
|
"goInOut/consumers/HBJCAS" |
|
|
|
"goInOut/consumers/HBJCAS/protoFiles_hb" |
|
|
|
"goInOut/dbOperate" |
|
|
|
"goInOut/models" |
|
|
|
"google.golang.org/protobuf/proto" |
|
|
|
|
|
|
|
"log" |
|
|
|
"math" |
|
|
|
"strconv" |
|
|
@ -33,18 +32,22 @@ func (the Adaptor_AXYES_GDJKJC) Transform(structId int64, factorId int, rawMsg s |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
Payload := the.EsAggTopToGDJKJC(structId, factorId, esAggDateHistogram) |
|
|
|
if len(Payload) == 0 { |
|
|
|
Payloads := the.EsAggTopToGDJKJC(structId, factorId, esAggDateHistogram) |
|
|
|
if len(Payloads) == 0 { |
|
|
|
return needPush |
|
|
|
} |
|
|
|
|
|
|
|
needPush = append(needPush, NeedPush{ |
|
|
|
Payload: Payload, |
|
|
|
}) |
|
|
|
for _, payload := range Payloads { |
|
|
|
needPush = append(needPush, NeedPush{ |
|
|
|
Topic: strconv.FormatInt(structId, 10), |
|
|
|
Payload: payload, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
return needPush |
|
|
|
} |
|
|
|
|
|
|
|
func (the Adaptor_AXYES_GDJKJC) EsAggTopToGDJKJC(structId int64, factorId int, esAggs HBJCAS.EsThemeAggDateHistogram) (result []byte) { |
|
|
|
func (the Adaptor_AXYES_GDJKJC) EsAggTopToGDJKJC(structId int64, factorId int, esAggs HBJCAS.EsThemeAggDateHistogram) (result [][]byte) { |
|
|
|
buckets := esAggs.Aggregations.GroupSensor.Buckets |
|
|
|
if len(buckets) == 0 { |
|
|
|
log.Printf("[s=%d,f=%d] ,es agg数据数量==0", structId, factorId) |
|
|
@ -57,35 +60,33 @@ func (the Adaptor_AXYES_GDJKJC) EsAggTopToGDJKJC(structId int64, factorId int, e |
|
|
|
return |
|
|
|
} |
|
|
|
//数据汇总
|
|
|
|
complexData := &protoFiles_hb.ComplexData{} |
|
|
|
for _, sensorBucket := range buckets { |
|
|
|
sensorId := sensorBucket.Key |
|
|
|
for _, dateBucket := range sensorBucket.GroupDate.Buckets { |
|
|
|
//优先redis获取
|
|
|
|
station := models.Station{} |
|
|
|
k1 := fmt.Sprintf("station:%d", sensorId) |
|
|
|
errRedis := the.Redis.GetObj(k1, &station) |
|
|
|
if errRedis != nil { |
|
|
|
log.Printf("redis 获取[s:%d,f:%d]测点[%d]标签异常", structId, factorId, sensorId) |
|
|
|
continue |
|
|
|
} |
|
|
|
monitorCode := the.getPointCodeFromLabel(station.Labels) |
|
|
|
if monitorCode == 0 { |
|
|
|
log.Printf("redis 获取[s:%d,f:%d]测点[%d]标签,信息转换int64异常,跳过", structId, factorId, sensorId) |
|
|
|
//station := models.Station{}
|
|
|
|
//k1 := fmt.Sprintf("station:%d", sensorId)
|
|
|
|
//errRedis := the.Redis.GetObj(k1, &station)
|
|
|
|
//if errRedis != nil {
|
|
|
|
// log.Printf("redis 获取[s:%d,f:%d]测点[%d]标签异常", structId, factorId, sensorId)
|
|
|
|
// continue
|
|
|
|
//}
|
|
|
|
monitorCode := "LJ-VIB-P01-004-01" //the.getPointCodeFromLabel(station.Labels)
|
|
|
|
if monitorCode == "" { |
|
|
|
log.Printf("redis 获取[s:%d,f:%d]测点[%d]信息,异常,跳过", structId, factorId, sensorId) |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
dataDefinition := &protoFiles_hb.DataDefinition{ |
|
|
|
DataType: protoFiles_hb.DataType_STATISTICS, |
|
|
|
UniqueCode: fmt.Sprintf("%d", uniqueCode), //乃积沟大桥
|
|
|
|
DataBody: the.EsAgg2StatisticData(factorId, monitorCode, dateBucket), |
|
|
|
} |
|
|
|
complexData.SensorData = append(complexData.SensorData, dataDefinition) |
|
|
|
dataBytes := the.EsAgg2StatisticData(factorId, monitorCode, dateBucket) |
|
|
|
//dataDefinition := &protoFiles_hb.DataDefinition{
|
|
|
|
// DataType: protoFiles_hb.DataType_STATISTICS,
|
|
|
|
// UniqueCode: fmt.Sprintf("%d", uniqueCode), //乃积沟大桥
|
|
|
|
// DataBody: the.EsAgg2StatisticData(factorId, monitorCode, dateBucket),
|
|
|
|
//}
|
|
|
|
result = append(result, dataBytes) |
|
|
|
log.Printf("[s:%d,f:%d] t=%s, 特征数据=> %s", structId, factorId, dateBucket.KeyAsString, dataBytes) |
|
|
|
} |
|
|
|
} |
|
|
|
v, _ := json.Marshal(complexData) |
|
|
|
log.Printf("[s:%d,f:%d] 特征数据=> %s", structId, factorId, v) |
|
|
|
result, _ = proto.Marshal(complexData) |
|
|
|
return result |
|
|
|
} |
|
|
|
func (the Adaptor_AXYES_GDJKJC) getMonitorTypeByFactorId(factorId int) protoFiles_hb.MonitoryType { |
|
|
@ -107,7 +108,7 @@ func (the Adaptor_AXYES_GDJKJC) getMonitorTypeByFactorId(factorId int) protoFile |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (the Adaptor_AXYES_GDJKJC) EsAgg2StatisticData(factorId int, monitorCode int64, dateBucket HBJCAS.BucketsXY) *protoFiles_hb.DataDefinition_StatisticData { |
|
|
|
func (the Adaptor_AXYES_GDJKJC) EsAgg2StatisticData(factorId int, monitorCode string, dateBucket HBJCAS.BucketsXY) (dataBytes []byte) { |
|
|
|
Atime := dateBucket.KeyAsString.Add(-8 * time.Hour).UnixMilli() |
|
|
|
maxAbsoluteValueX := max(math.Abs(dateBucket.X.Max), math.Abs(dateBucket.X.Min)) |
|
|
|
avgValueX := dateBucket.X.Avg |
|
|
@ -117,53 +118,35 @@ func (the Adaptor_AXYES_GDJKJC) EsAgg2StatisticData(factorId int, monitorCode in |
|
|
|
avgValueY := dateBucket.Y.Avg |
|
|
|
rootMeanSquareY := math.Sqrt(dateBucket.Y.SumOfSquares / float64(dateBucket.Y.Count)) |
|
|
|
|
|
|
|
monitoryType := the.getMonitorTypeByFactorId(factorId) |
|
|
|
dataDefinitionStatisticData := &protoFiles_hb.DataDefinition_StatisticData{ |
|
|
|
StatisticData: &protoFiles_hb.StatisticData{ |
|
|
|
MonitorType: monitoryType, |
|
|
|
MonitorCode: monitorCode, //测点唯一编码
|
|
|
|
EventTime: Atime, |
|
|
|
Interval: 60 * 1000, |
|
|
|
}, |
|
|
|
commonBody := GDJKJC.CommonBody{ |
|
|
|
ThirdChannelCode: monitorCode, |
|
|
|
DataTimeUnix: Atime, |
|
|
|
} |
|
|
|
|
|
|
|
var destStruct any |
|
|
|
switch factorId { |
|
|
|
case 15: //倾角
|
|
|
|
dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_hb.StatisticData_Inc{Inc: &protoFiles_hb.INCStatistic{ |
|
|
|
MaxAbsoluteValueX: float32(maxAbsoluteValueX), |
|
|
|
AvgValueX: float32(avgValueX), |
|
|
|
RootMeanSquareX: float32(rootMeanSquareX), |
|
|
|
MaxAbsoluteValueY: float32(maxAbsoluteValueY), |
|
|
|
AvgValueY: float32(avgValueY), |
|
|
|
RootMeanSquareY: float32(rootMeanSquareY), |
|
|
|
}} |
|
|
|
case 18: //裂缝监测
|
|
|
|
dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_hb.StatisticData_Crk{Crk: &protoFiles_hb.CRKStatistic{ |
|
|
|
MaxAbsoluteValue: float32(maxAbsoluteValueX), |
|
|
|
AvgValue: float32(avgValueX), |
|
|
|
RootMeanSquare: float32(rootMeanSquareX), |
|
|
|
TotalAbsoluteValue: float32(dateBucket.X.Max - dateBucket.X.Min), |
|
|
|
}} |
|
|
|
case 20: //支座位移
|
|
|
|
dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_hb.StatisticData_Dis{Dis: &protoFiles_hb.DISStatistic{ |
|
|
|
MaxAbsoluteValue: float32(maxAbsoluteValueX), |
|
|
|
AvgValue: float32(avgValueX), |
|
|
|
RootMeanSquare: float32(rootMeanSquareX), |
|
|
|
TotalAbsoluteValue: float32(dateBucket.X.Max - dateBucket.X.Min), |
|
|
|
}} |
|
|
|
destStruct = GDJKJC.A43AngleBody{ |
|
|
|
CommonBody: commonBody, |
|
|
|
XAvg: avgValueX, |
|
|
|
XMax: maxAbsoluteValueX, |
|
|
|
XRms: rootMeanSquareX, //均方根
|
|
|
|
YAvg: avgValueY, |
|
|
|
YMax: maxAbsoluteValueY, |
|
|
|
YRms: rootMeanSquareY, //均方根
|
|
|
|
} |
|
|
|
case 28: //振动
|
|
|
|
dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_hb.StatisticData_Vib{Vib: &protoFiles_hb.VIBStatistic{ |
|
|
|
MaxAbsoluteValue: float32(maxAbsoluteValueX), |
|
|
|
RootMeanSquare: float32(rootMeanSquareY), |
|
|
|
}} |
|
|
|
case 592: //加速度三项监测
|
|
|
|
dataDefinitionStatisticData.StatisticData.DataBody = &protoFiles_hb.StatisticData_Vib{Vib: &protoFiles_hb.VIBStatistic{ |
|
|
|
MaxAbsoluteValue: float32(maxAbsoluteValueX), |
|
|
|
RootMeanSquare: float32(rootMeanSquareX), |
|
|
|
}} |
|
|
|
destStruct = GDJKJC.A48Acc{ |
|
|
|
CommonBody: commonBody, |
|
|
|
Max: maxAbsoluteValueX / 100, //省平台 加速度单位 m/s² 实际设备单位 cm/s²
|
|
|
|
Rms: rootMeanSquareX / 100, //均方根
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return dataDefinitionStatisticData |
|
|
|
if destStruct != nil { |
|
|
|
dataBytes, _ = json.Marshal(destStruct) |
|
|
|
} else { |
|
|
|
log.Printf("!!! [f=%d,s=%s]无匹配 映射数据", factorId, monitorCode) |
|
|
|
} |
|
|
|
return dataBytes |
|
|
|
} |
|
|
|
|
|
|
|
func (the Adaptor_AXYES_GDJKJC) getUniqueCode(structId int64) (uniqueCode string) { |
|
|
|