improve websocket ping and remodel for rename datapoint
This commit is contained in:
@@ -1,5 +1,52 @@
|
||||
package models
|
||||
|
||||
import "github.com/google/uuid"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
json_dataModels "github.com/tecamino/tecamino-json_data/models"
|
||||
)
|
||||
|
||||
type Uuids map[uuid.UUID]*Datapoint
|
||||
|
||||
func NewUuids() *Uuids {
|
||||
return &Uuids{}
|
||||
}
|
||||
|
||||
func (u *Uuids) AddDatapoint(parentDp, newDp *Datapoint) {
|
||||
if odp, ok := (*u)[newDp.Uuid]; ok {
|
||||
if odp.Path == newDp.Path {
|
||||
return
|
||||
}
|
||||
newDp.Datapoints = odp.Datapoints
|
||||
newDp.HasChild = len(odp.Datapoints) > 0
|
||||
odp.Datapoints = map[string]*Datapoint{}
|
||||
newDp.RenamePaths(odp.Path)
|
||||
rmDps, _ := parentDp.RemoveDatapoint(json_dataModels.Set{Path: odp.Path})
|
||||
datapoints := u.GetDatapointByPath("System:Datapoints")
|
||||
datapoints.UpdateValue(datapoints.Value.(uint64) - uint64(len(rmDps)))
|
||||
fmt.Println(11, newDp.HasChild)
|
||||
}
|
||||
|
||||
(*u)[newDp.Uuid] = newDp
|
||||
}
|
||||
|
||||
func (u *Uuids) GetDatapoint(uuid uuid.UUID) *Datapoint {
|
||||
if dp, ok := (*u)[uuid]; ok {
|
||||
return dp
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Uuids) GetDatapointByPath(path string) *Datapoint {
|
||||
for _, dp := range *u {
|
||||
if dp.Path == path {
|
||||
return dp
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *Uuids) RemoveDatapoint(uuid uuid.UUID) {
|
||||
delete(*u, uuid)
|
||||
}
|
||||
|
Reference in New Issue
Block a user