add func of init component measurement recommend
This commit is contained in:
parent
7ea38615b4
commit
51f65500f3
|
|
@ -32,8 +32,8 @@ const (
|
||||||
// RedisSpecStationCompNSPATHSetKey define redis set key which store all component nspath keys under specific station
|
// RedisSpecStationCompNSPATHSetKey define redis set key which store all component nspath keys under specific station
|
||||||
RedisSpecStationCompNSPATHSetKey = "%s_component_nspath_keys"
|
RedisSpecStationCompNSPATHSetKey = "%s_component_nspath_keys"
|
||||||
|
|
||||||
// RedisSpecStationCompTagSetKey define redis set key which store all component tag keys under specific station
|
// RedisSpecCompNSPathCompTagSetKey define redis set key which store all component tag keys under specific component nspath
|
||||||
RedisSpecStationCompTagSetKey = "%s_component_tag_keys"
|
RedisSpecCompNSPathCompTagSetKey = "%s_component_tag_keys"
|
||||||
|
|
||||||
// RedisSpecCompTagMeasSetKey define redis set key which store all measurement tag keys under specific component tag
|
// RedisSpecCompTagMeasSetKey define redis set key which store all measurement tag keys under specific component tag
|
||||||
RedisSpecCompTagMeasSetKey = "%s_measurement_tag_keys"
|
RedisSpecCompTagMeasSetKey = "%s_measurement_tag_keys"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
// Package database define database operation functions
|
||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"modelRT/orm"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ZoneWithParent struct {
|
||||||
|
orm.Zone
|
||||||
|
GridTag string `gorm:"column:grid_tag"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type StationWithParent struct {
|
||||||
|
orm.Zone
|
||||||
|
ZoneTag string `gorm:"column:zone_tag"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFullMeasurementSet(db *gorm.DB) (*orm.MeasurementSet, error) {
|
||||||
|
mSet := &orm.MeasurementSet{
|
||||||
|
GridToZoneTags: make(map[string][]string),
|
||||||
|
ZoneToStationTags: make(map[string][]string),
|
||||||
|
StationToCompNSPaths: make(map[string][]string),
|
||||||
|
CompNSPathToCompTags: make(map[string][]string),
|
||||||
|
CompTagToMeasTags: make(map[string][]string),
|
||||||
|
}
|
||||||
|
|
||||||
|
var zones []struct {
|
||||||
|
orm.Zone
|
||||||
|
GridTag string `gorm:"column:grid_tag"`
|
||||||
|
}
|
||||||
|
if err := db.Table("zone").
|
||||||
|
Select("zone.*, grid.tagname as grid_tag").
|
||||||
|
Joins("left join grid on zone.grid_id = grid.id").
|
||||||
|
Scan(&zones).Error; err == nil {
|
||||||
|
for _, z := range zones {
|
||||||
|
mSet.AllZoneTags = append(mSet.AllZoneTags, z.TAGNAME)
|
||||||
|
if z.GridTag != "" {
|
||||||
|
mSet.GridToZoneTags[z.GridTag] = append(mSet.GridToZoneTags[z.GridTag], z.TAGNAME)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var stations []struct {
|
||||||
|
orm.Station
|
||||||
|
ZoneTag string `gorm:"column:zone_tag"`
|
||||||
|
}
|
||||||
|
if err := db.Table("station").
|
||||||
|
Select("station.*, zone.tagname as zone_tag").
|
||||||
|
Joins("left join zone on station.zone_id = zone.id").
|
||||||
|
Scan(&stations).Error; err == nil {
|
||||||
|
for _, s := range stations {
|
||||||
|
mSet.AllStationTags = append(mSet.AllStationTags, s.TAGNAME)
|
||||||
|
if s.ZoneTag != "" {
|
||||||
|
mSet.ZoneToStationTags[s.ZoneTag] = append(mSet.ZoneToStationTags[s.ZoneTag], s.TAGNAME)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var comps []struct {
|
||||||
|
orm.Component
|
||||||
|
StationTag string `gorm:"column:station_tag"`
|
||||||
|
}
|
||||||
|
if err := db.Table("component").
|
||||||
|
Select("component.*, station.tagname as station_tag").
|
||||||
|
Joins("left join station on component.station_id = station.id").
|
||||||
|
Scan(&comps).Error; err == nil {
|
||||||
|
for _, c := range comps {
|
||||||
|
mSet.AllCompNSPaths = append(mSet.AllCompNSPaths, c.NSPath)
|
||||||
|
mSet.AllCompTags = append(mSet.AllCompTags, c.Tag)
|
||||||
|
|
||||||
|
if c.StationTag != "" {
|
||||||
|
mSet.StationToCompNSPaths[c.StationTag] = append(mSet.StationToCompNSPaths[c.StationTag], c.NSPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.NSPath != "" {
|
||||||
|
mSet.CompNSPathToCompTags[c.NSPath] = append(mSet.CompNSPathToCompTags[c.NSPath], c.Tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var measurements []struct {
|
||||||
|
orm.Measurement
|
||||||
|
CompTag string `gorm:"column:comp_tag"`
|
||||||
|
}
|
||||||
|
if err := db.Table("measurement").
|
||||||
|
Select("measurement.*, component.tag as comp_tag").
|
||||||
|
Joins("left join component on measurement.component_uuid = component.global_uuid").
|
||||||
|
Scan(&measurements).Error; err == nil {
|
||||||
|
for _, m := range measurements {
|
||||||
|
mSet.AllMeasTags = append(mSet.AllMeasTags, m.Tag)
|
||||||
|
if m.CompTag != "" {
|
||||||
|
mSet.CompTagToMeasTags[m.CompTag] = append(mSet.CompTagToMeasTags[m.CompTag], m.Tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mSet, nil
|
||||||
|
}
|
||||||
|
|
@ -33,7 +33,7 @@ var linkSetConfigs = map[int]linkSetConfig{
|
||||||
// component nspath hierarchy
|
// component nspath hierarchy
|
||||||
3: {CurrKey: constants.RedisAllCompNSPathSetKey, PrevKeyTemplate: constants.RedisSpecStationCompNSPATHSetKey},
|
3: {CurrKey: constants.RedisAllCompNSPathSetKey, PrevKeyTemplate: constants.RedisSpecStationCompNSPATHSetKey},
|
||||||
// component tag hierarchy
|
// component tag hierarchy
|
||||||
4: {CurrKey: constants.RedisAllCompTagSetKey, PrevKeyTemplate: constants.RedisSpecStationCompTagSetKey},
|
4: {CurrKey: constants.RedisAllCompTagSetKey, PrevKeyTemplate: constants.RedisSpecCompNSPathCompTagSetKey},
|
||||||
// config hierarchy
|
// config hierarchy
|
||||||
5: {CurrKey: constants.RedisAllConfigSetKey, PrevIsNil: true},
|
5: {CurrKey: constants.RedisAllConfigSetKey, PrevIsNil: true},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
// Package model define model struct of model runtime service
|
||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"modelRT/constants"
|
||||||
|
"modelRT/diagram"
|
||||||
|
"modelRT/logger"
|
||||||
|
"modelRT/orm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TraverseMeasurementGroupTables define func to traverse component measurement group tables
|
||||||
|
func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.MeasurementSet) error {
|
||||||
|
rdb := diagram.GetRedisClientInstance()
|
||||||
|
pipe := rdb.Pipeline()
|
||||||
|
|
||||||
|
pipe.SAdd(ctx, constants.RedisAllGridSetKey, measSet.AllGridTags)
|
||||||
|
pipe.SAdd(ctx, constants.RedisAllZoneSetKey, measSet.AllZoneTags)
|
||||||
|
pipe.SAdd(ctx, constants.RedisAllStationSetKey, measSet.AllStationTags)
|
||||||
|
pipe.SAdd(ctx, constants.RedisAllGridSetKey, measSet.AllCompNSPaths)
|
||||||
|
pipe.SAdd(ctx, constants.RedisAllZoneSetKey, measSet.AllCompTags)
|
||||||
|
pipe.SAdd(ctx, constants.RedisAllConfigSetKey, "bay")
|
||||||
|
pipe.SAdd(ctx, constants.RedisAllStationSetKey, measSet.AllMeasTags)
|
||||||
|
|
||||||
|
// building the grid -> zones hierarchy
|
||||||
|
for gridTag, zoneTags := range measSet.GridToZoneTags {
|
||||||
|
key := fmt.Sprintf(constants.RedisSpecGridZoneSetKey, gridTag)
|
||||||
|
pipe.SAdd(ctx, key, zoneTags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// building the zone -> stations hierarchy
|
||||||
|
for zoneTag, stationTags := range measSet.ZoneToStationTags {
|
||||||
|
key := fmt.Sprintf(constants.RedisSpecZoneStationSetKey, zoneTag)
|
||||||
|
pipe.SAdd(ctx, key, stationTags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// building the station -> component nspaths hierarchy
|
||||||
|
for stationTag, compNSPaths := range measSet.StationToCompNSPaths {
|
||||||
|
key := fmt.Sprintf(constants.RedisSpecStationCompNSPATHSetKey, stationTag)
|
||||||
|
pipe.SAdd(ctx, key, compNSPaths)
|
||||||
|
}
|
||||||
|
|
||||||
|
// building the component nspath -> component tags hierarchy
|
||||||
|
for compNSPath, compTags := range measSet.CompNSPathToCompTags {
|
||||||
|
key := fmt.Sprintf(constants.RedisSpecCompNSPathCompTagSetKey, compNSPath)
|
||||||
|
pipe.SAdd(ctx, key, compTags)
|
||||||
|
}
|
||||||
|
|
||||||
|
// building the component tag -> measurement tags hierarchy
|
||||||
|
for compTag, measTags := range measSet.CompTagToMeasTags {
|
||||||
|
key := fmt.Sprintf(constants.RedisSpecCompTagMeasSetKey, compTag)
|
||||||
|
pipe.SAdd(ctx, key, measTags)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := pipe.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(ctx, "init component measurement group recommend content failed", "error", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
@ -367,7 +367,7 @@ func getSpecificKeyByLength(hierarchy constants.RecommendHierarchyType, keyPrefi
|
||||||
case constants.CompNSPathRecommendHierarchyType:
|
case constants.CompNSPathRecommendHierarchyType:
|
||||||
return fmt.Sprintf(constants.RedisSpecStationCompNSPATHSetKey, keyPrefix)
|
return fmt.Sprintf(constants.RedisSpecStationCompNSPATHSetKey, keyPrefix)
|
||||||
case constants.CompTagRecommendHierarchyType:
|
case constants.CompTagRecommendHierarchyType:
|
||||||
return fmt.Sprintf(constants.RedisSpecStationCompTagSetKey, keyPrefix)
|
return fmt.Sprintf(constants.RedisSpecCompNSPathCompTagSetKey, keyPrefix)
|
||||||
case constants.ConfigRecommendHierarchyType:
|
case constants.ConfigRecommendHierarchyType:
|
||||||
return constants.RedisAllConfigSetKey
|
return constants.RedisAllConfigSetKey
|
||||||
case constants.MeasTagRecommendHierarchyType:
|
case constants.MeasTagRecommendHierarchyType:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Package orm define database data struct
|
// Package orm define database data struct
|
||||||
package orm
|
package orm
|
||||||
|
|
||||||
// AttributeSet define struct to return component Tag、 NSPath field
|
// AttributeSet define struct to return component tag、component NSPath field
|
||||||
type AttributeSet struct {
|
type AttributeSet struct {
|
||||||
CompTag string
|
CompTag string
|
||||||
CompNSPath string
|
CompNSPath string
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
// Package orm define database data struct
|
||||||
|
package orm
|
||||||
|
|
||||||
|
// MeasurementSet define struct to return grid tag、zone tag、station tag、 component NSPath、component tag、measurement tag field
|
||||||
|
type MeasurementSet struct {
|
||||||
|
AllGridTags []string
|
||||||
|
AllZoneTags []string
|
||||||
|
AllStationTags []string
|
||||||
|
AllCompNSPaths []string
|
||||||
|
AllCompTags []string
|
||||||
|
AllMeasTags []string
|
||||||
|
|
||||||
|
GridToZoneTags map[string][]string // Key: GridTag, Value: ZoneTags
|
||||||
|
ZoneToStationTags map[string][]string // Key: ZoneTag, Value: StationTags
|
||||||
|
StationToCompNSPaths map[string][]string // Key: StationTag, Value: NSPaths
|
||||||
|
CompNSPathToCompTags map[string][]string // Key: NSPaths, Value: CompTags
|
||||||
|
CompTagToMeasTags map[string][]string // Key: CompTag, Value: MeasTags
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue