|
@ -6,21 +6,21 @@ import ( |
|
|
"goInOut/consumers/HBJCAS/protoFiles_hb" |
|
|
"goInOut/consumers/HBJCAS/protoFiles_hb" |
|
|
"goInOut/models" |
|
|
"goInOut/models" |
|
|
"google.golang.org/protobuf/proto" |
|
|
"google.golang.org/protobuf/proto" |
|
|
|
|
|
"math" |
|
|
|
|
|
"strconv" |
|
|
"time" |
|
|
"time" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// Adaptor_AXYES_HBGL 统一采集软件数据 转换 湘潭健康监测平台
|
|
|
// Adaptor_AXYES_HBGL 统一采集软件数据 转换 湘潭健康监测平台
|
|
|
type Adaptor_AXYES_HBGL struct { |
|
|
type Adaptor_AXYES_HBGL struct { |
|
|
//传感器code转换信息
|
|
|
//传感器code转换信息
|
|
|
GnssMap map[string]string |
|
|
PointInfo map[int64]map[int64]int64 |
|
|
RainMap map[string]string |
|
|
StructInfo map[int64]int64 |
|
|
NBWYMap map[string]string |
|
|
|
|
|
DXSWMap map[string]string |
|
|
|
|
|
//一些必要信息
|
|
|
//一些必要信息
|
|
|
Info map[string]string |
|
|
Info map[string]string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (the Adaptor_AXYES_HBGL) Transform(rawMsg string) []NeedPush { |
|
|
func (the Adaptor_AXYES_HBGL) Transform(structId int64, factorId int, rawMsg string) []NeedPush { |
|
|
esAggDateHistogram := models.EsThemeAggDateHistogram{} |
|
|
esAggDateHistogram := models.EsThemeAggDateHistogram{} |
|
|
var needPush []NeedPush |
|
|
var needPush []NeedPush |
|
|
err := json.Unmarshal([]byte(rawMsg), &esAggDateHistogram) |
|
|
err := json.Unmarshal([]byte(rawMsg), &esAggDateHistogram) |
|
@ -28,44 +28,41 @@ func (the Adaptor_AXYES_HBGL) Transform(rawMsg string) []NeedPush { |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
needPush = append(needPush, NeedPush{ |
|
|
needPush = append(needPush, NeedPush{ |
|
|
Payload: the.EsAggTopToHBJCAS(esAggDateHistogram), |
|
|
Payload: the.EsAggTopToHBJCAS(structId, factorId, esAggDateHistogram), |
|
|
}) |
|
|
}) |
|
|
return needPush |
|
|
return needPush |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (the Adaptor_AXYES_HBGL) EsAggTopToHBJCAS(esAggs models.EsThemeAggDateHistogram) (result []byte) { |
|
|
func (the Adaptor_AXYES_HBGL) EsAggTopToHBJCAS(structId int64, factorId int, esAggs models.EsThemeAggDateHistogram) (result []byte) { |
|
|
buckets := esAggs.Aggregations.GroupSensor.Buckets |
|
|
buckets := esAggs.Aggregations.GroupSensor.Buckets |
|
|
if len(buckets) == 0 { |
|
|
if len(buckets) == 0 { |
|
|
log.Info("es agg数据数量==0") |
|
|
log.Info("es agg数据数量==0") |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
//设施唯一编码(省平台)
|
|
|
|
|
|
uniqueCode := the.getUniqueCode(structId) |
|
|
|
|
|
if uniqueCode == 0 { |
|
|
|
|
|
log.Printf("structId=%d,无匹配省平台uniqueCode", structId) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
//数据汇总
|
|
|
//数据汇总
|
|
|
complexData := &protoFiles_hb.ComplexData{} |
|
|
complexData := &protoFiles_hb.ComplexData{} |
|
|
for _, sensorBucket := range buckets { |
|
|
for _, sensorBucket := range buckets { |
|
|
//sensorId := sensorBucket.Key
|
|
|
sensorId := sensorBucket.Key |
|
|
|
|
|
monitorCode := int64(0) |
|
|
for _, dateBucket := range sensorBucket.GroupDate.Buckets { |
|
|
for _, dateBucket := range sensorBucket.GroupDate.Buckets { |
|
|
Atime := dateBucket.KeyAsString |
|
|
if _, ok := the.PointInfo[structId]; !ok { |
|
|
dataDefinitionStatisticData := &protoFiles_hb.DataDefinition_StatisticData{ |
|
|
continue |
|
|
StatisticData: &protoFiles_hb.StatisticData{ |
|
|
|
|
|
MonitorType: protoFiles_hb.MonitoryType_INC, |
|
|
|
|
|
MonitorCode: 13000100001, //测点唯一编码
|
|
|
|
|
|
EventTime: Atime.Add(-8 * time.Hour).UnixMilli(), |
|
|
|
|
|
Interval: 60 * 1000, |
|
|
|
|
|
DataBody: &protoFiles_hb.StatisticData_Inc{Inc: &protoFiles_hb.INCStatistic{ |
|
|
|
|
|
MaxAbsoluteValueX: 0, |
|
|
|
|
|
AvgValueX: 0, |
|
|
|
|
|
RootMeanSquareX: 0, |
|
|
|
|
|
MaxAbsoluteValueY: 0, |
|
|
|
|
|
AvgValueY: 0, |
|
|
|
|
|
RootMeanSquareY: 0, |
|
|
|
|
|
}}, |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
if _, ok := the.PointInfo[structId][sensorId]; !ok { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
monitorCode = the.PointInfo[structId][sensorId] |
|
|
|
|
|
|
|
|
dataDefinition := &protoFiles_hb.DataDefinition{ |
|
|
dataDefinition := &protoFiles_hb.DataDefinition{ |
|
|
DataType: protoFiles_hb.DataType_STATISTICS, |
|
|
DataType: protoFiles_hb.DataType_STATISTICS, |
|
|
UniqueCode: "130109", //乃积沟大桥
|
|
|
UniqueCode: strconv.FormatInt(uniqueCode, 10), //乃积沟大桥
|
|
|
DataBody: dataDefinitionStatisticData, |
|
|
DataBody: the.EsAgg2StatisticData(factorId, monitorCode, dateBucket), |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
complexData.SensorData = append(complexData.SensorData, dataDefinition) |
|
|
complexData.SensorData = append(complexData.SensorData, dataDefinition) |
|
@ -76,3 +73,53 @@ func (the Adaptor_AXYES_HBGL) EsAggTopToHBJCAS(esAggs models.EsThemeAggDateHisto |
|
|
result, _ = proto.Marshal(complexData) |
|
|
result, _ = proto.Marshal(complexData) |
|
|
return result |
|
|
return result |
|
|
} |
|
|
} |
|
|
|
|
|
func (the Adaptor_AXYES_HBGL) getMonitorTypeByFactorId(factorId int) protoFiles_hb.MonitoryType { |
|
|
|
|
|
//桥墩倾斜 15 支座位移20 桥面振动28
|
|
|
|
|
|
switch factorId { |
|
|
|
|
|
case 15: |
|
|
|
|
|
return protoFiles_hb.MonitoryType_INC |
|
|
|
|
|
case 20: |
|
|
|
|
|
return protoFiles_hb.MonitoryType_AND |
|
|
|
|
|
case 28: |
|
|
|
|
|
return protoFiles_hb.MonitoryType_VIB |
|
|
|
|
|
default: |
|
|
|
|
|
return protoFiles_hb.MonitoryType_CMM |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
func (the Adaptor_AXYES_HBGL) EsAgg2StatisticData(factorId int, monitorCode int64, dateBucket models.BucketsXY) *protoFiles_hb.DataDefinition_StatisticData { |
|
|
|
|
|
Atime := dateBucket.KeyAsString.Add(-8 * time.Hour).UnixMilli() |
|
|
|
|
|
maxAbsoluteValueX := max(math.Abs(dateBucket.X.Max), math.Abs(dateBucket.X.Min)) |
|
|
|
|
|
avgValueX := dateBucket.X.Avg |
|
|
|
|
|
maxAbsoluteValueY := max(math.Abs(dateBucket.Y.Max), math.Abs(dateBucket.Y.Min)) |
|
|
|
|
|
avgValueY := dateBucket.Y.Avg |
|
|
|
|
|
|
|
|
|
|
|
rootMeanSquareX := math.Sqrt(dateBucket.X.SumOfSquares / float64(dateBucket.X.Count)) |
|
|
|
|
|
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, |
|
|
|
|
|
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), |
|
|
|
|
|
}}, |
|
|
|
|
|
}, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return dataDefinitionStatisticData |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (the Adaptor_AXYES_HBGL) getUniqueCode(structId int64) (uniqueCode int64) { |
|
|
|
|
|
if v, ok := the.StructInfo[structId]; ok { |
|
|
|
|
|
uniqueCode = v |
|
|
|
|
|
} |
|
|
|
|
|
return uniqueCode |
|
|
|
|
|
} |
|
|