Loading go-packages/meep-vis-traffic-mgr/go.mod +1 −1 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,7 @@ go 1.16 require ( require ( github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger v0.0.0 github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger v0.0.0 github.com/lib/pq v1.5.2 github.com/lib/pq v1.5.2 gopkg.in/yaml.v2 v2.4.0 github.com/spf13/viper v1.11.0 ) ) replace github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger => ../../go-packages/meep-logger replace github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger => ../../go-packages/meep-logger go-packages/meep-vis-traffic-mgr/go.sum +796 −4 File changed.Preview size limit exceeded, changes collapsed. Show changes go-packages/meep-vis-traffic-mgr/traffic-mgr.go +24 −17 Original line number Original line Diff line number Diff line Loading @@ -24,10 +24,9 @@ import ( "strings" "strings" "time" "time" "gopkg.in/yaml.v2" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" _ "github.com/lib/pq" _ "github.com/lib/pq" "github.com/spf13/viper" ) ) // DB Config // DB Config Loading Loading @@ -65,12 +64,8 @@ const ( TrafficTable = "traffic_patterns" TrafficTable = "traffic_patterns" ) ) // Grid Map file name // Grid Map data // const gridFile = "grid_map.yaml" var gridMapData map[string]map[string][]string // Open and embed grid_map.yaml file //go:embed grid_map.yaml var yamlFile []byte // Category-wise Traffic Loads // Category-wise Traffic Loads var categoriesLoads = map[string]map[string]int32{ var categoriesLoads = map[string]map[string]int32{ Loading Loading @@ -210,7 +205,8 @@ func NewTrafficMgr(name, namespace, user, pwd, host, port string) (tm *TrafficMg } } // Open grid map file // Open grid map file if yamlFile == nil { gridMapData, err = getGridMapConfig() if err != nil { log.Error("Failed to open grid map file with err: ", err.Error()) log.Error("Failed to open grid map file with err: ", err.Error()) return nil, err return nil, err } } Loading Loading @@ -314,6 +310,24 @@ func (tm *TrafficMgr) DestroyDb(name string) (err error) { return nil return nil } } func getGridMapConfig() (gridData map[string]map[string][]string, err error) { // Read grid map from grid map file gridMapFile := "/grid_map.yaml" gridMap := viper.New() gridMap.SetConfigFile(gridMapFile) err = gridMap.ReadInConfig() if err != nil { return nil, err } var config map[string]map[string][]string err = gridMap.Unmarshal(config) if err != nil { return nil, err } return config, nil } func (tm *TrafficMgr) CreateTables() (err error) { func (tm *TrafficMgr) CreateTables() (err error) { _, err = tm.db.Exec("CREATE EXTENSION IF NOT EXISTS postgis") _, err = tm.db.Exec("CREATE EXTENSION IF NOT EXISTS postgis") if err != nil { if err != nil { Loading Loading @@ -926,14 +940,7 @@ func (tm *TrafficMgr) PopulateGridMapTable() (err error) { } } // Get grid map from YAML file // Get grid map from YAML file var yamlGrid map[string]map[string][]string for category, areas := range gridMapData { err = yaml.Unmarshal(yamlFile, &yamlGrid) if err != nil { log.Error(err.Error()) return err } for category, areas := range yamlGrid { for area, points := range areas { for area, points := range areas { polygonStr := "(" polygonStr := "(" for i, pointStr := range points { for i, pointStr := range points { Loading Loading
go-packages/meep-vis-traffic-mgr/go.mod +1 −1 Original line number Original line Diff line number Diff line Loading @@ -5,7 +5,7 @@ go 1.16 require ( require ( github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger v0.0.0 github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger v0.0.0 github.com/lib/pq v1.5.2 github.com/lib/pq v1.5.2 gopkg.in/yaml.v2 v2.4.0 github.com/spf13/viper v1.11.0 ) ) replace github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger => ../../go-packages/meep-logger replace github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger => ../../go-packages/meep-logger
go-packages/meep-vis-traffic-mgr/go.sum +796 −4 File changed.Preview size limit exceeded, changes collapsed. Show changes
go-packages/meep-vis-traffic-mgr/traffic-mgr.go +24 −17 Original line number Original line Diff line number Diff line Loading @@ -24,10 +24,9 @@ import ( "strings" "strings" "time" "time" "gopkg.in/yaml.v2" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger" _ "github.com/lib/pq" _ "github.com/lib/pq" "github.com/spf13/viper" ) ) // DB Config // DB Config Loading Loading @@ -65,12 +64,8 @@ const ( TrafficTable = "traffic_patterns" TrafficTable = "traffic_patterns" ) ) // Grid Map file name // Grid Map data // const gridFile = "grid_map.yaml" var gridMapData map[string]map[string][]string // Open and embed grid_map.yaml file //go:embed grid_map.yaml var yamlFile []byte // Category-wise Traffic Loads // Category-wise Traffic Loads var categoriesLoads = map[string]map[string]int32{ var categoriesLoads = map[string]map[string]int32{ Loading Loading @@ -210,7 +205,8 @@ func NewTrafficMgr(name, namespace, user, pwd, host, port string) (tm *TrafficMg } } // Open grid map file // Open grid map file if yamlFile == nil { gridMapData, err = getGridMapConfig() if err != nil { log.Error("Failed to open grid map file with err: ", err.Error()) log.Error("Failed to open grid map file with err: ", err.Error()) return nil, err return nil, err } } Loading Loading @@ -314,6 +310,24 @@ func (tm *TrafficMgr) DestroyDb(name string) (err error) { return nil return nil } } func getGridMapConfig() (gridData map[string]map[string][]string, err error) { // Read grid map from grid map file gridMapFile := "/grid_map.yaml" gridMap := viper.New() gridMap.SetConfigFile(gridMapFile) err = gridMap.ReadInConfig() if err != nil { return nil, err } var config map[string]map[string][]string err = gridMap.Unmarshal(config) if err != nil { return nil, err } return config, nil } func (tm *TrafficMgr) CreateTables() (err error) { func (tm *TrafficMgr) CreateTables() (err error) { _, err = tm.db.Exec("CREATE EXTENSION IF NOT EXISTS postgis") _, err = tm.db.Exec("CREATE EXTENSION IF NOT EXISTS postgis") if err != nil { if err != nil { Loading Loading @@ -926,14 +940,7 @@ func (tm *TrafficMgr) PopulateGridMapTable() (err error) { } } // Get grid map from YAML file // Get grid map from YAML file var yamlGrid map[string]map[string][]string for category, areas := range gridMapData { err = yaml.Unmarshal(yamlFile, &yamlGrid) if err != nil { log.Error(err.Error()) return err } for category, areas := range yamlGrid { for area, points := range areas { for area, points := range areas { polygonStr := "(" polygonStr := "(" for i, pointStr := range points { for i, pointStr := range points { Loading