Files
tecamino-dbm/models/uuids.go
2025-07-25 18:26:36 +02:00

53 lines
1.1 KiB
Go

package models
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)
}