auto populate system units (issue #66)

This commit is contained in:
Chrystian Huot 2021-12-01 13:15:28 -05:00
parent 6c15e7d47e
commit 789028ab02
7 changed files with 85 additions and 13 deletions

View file

@ -49,7 +49,8 @@ Call imported successfully
{
pos: number; // in seconds
src: number; // the unit ID
src: number; // unit ID
tag: number; // [optional] unit tag
}[];
- **system** - [optional] system ID.

View file

@ -271,8 +271,6 @@ func (admin *Admin) GetAuthorization(r *http.Request) string {
}
func (admin *Admin) GetConfig() map[string]interface{} {
// _, docker := os.LookupEnv("DOCKER")
systems := []map[string]interface{}{}
for _, system := range *admin.Controller.Systems {
systems = append(systems, map[string]interface{}{
@ -284,6 +282,7 @@ func (admin *Admin) GetConfig() map[string]interface{} {
"led": system.Led,
"order": system.Order,
"talkgroups": system.Talkgroups,
"units": system.Units,
})
}
@ -291,7 +290,6 @@ func (admin *Admin) GetConfig() map[string]interface{} {
"access": *admin.Controller.Accesses,
"apiKeys": *admin.Controller.Apikeys,
"dirWatch": *admin.Controller.Dirwatches,
// "docker": docker,
"downstreams": *admin.Controller.Downstreams,
"groups": *admin.Controller.Groups,
"options": *admin.Controller.Options,

View file

@ -68,6 +68,7 @@ func (api *Api) CallUploadHandler(w http.ResponseWriter, r *http.Request) {
talkgroupGroup interface{}
talkgroupLabel interface{}
talkgroupTag interface{}
units interface{}
)
mediaType, params, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
@ -190,9 +191,22 @@ func (api *Api) CallUploadHandler(w http.ResponseWriter, r *http.Request) {
src["pos"] = uint(v)
}
switch v := v["src"].(type) {
switch s := v["src"].(type) {
case float64:
src["src"] = uint(v)
src["src"] = uint(s)
switch t := v["tag"].(type) {
case string:
var u Units
switch v := units.(type) {
case Units:
u = v
default:
u = Units{}
}
u.Add(uint(s), t)
units = u
}
}
}
@ -246,6 +260,7 @@ func (api *Api) CallUploadHandler(w http.ResponseWriter, r *http.Request) {
talkgroupGroup: talkgroupGroup,
talkgroupLabel: talkgroupLabel,
talkgroupTag: talkgroupTag,
units: units,
}
if call.IsValid() {

View file

@ -39,6 +39,7 @@ type Call struct {
talkgroupGroup interface{}
talkgroupLabel interface{}
talkgroupTag interface{}
units interface{}
}
func (call *Call) IsValid() bool {

View file

@ -288,6 +288,14 @@ func (controller *Controller) IngestCall(call *Call) {
system.Talkgroups = append(system.Talkgroups, talkgroup)
}
if controller.Options.AutoPopulate || system.AutoPopulate {
switch v := call.units.(type) {
case Units:
populated = true
system.Units.Merge(&v)
}
}
if populated {
if err = controller.Systems.Write(controller.Database); err != nil {
logError(err)

View file

@ -109,22 +109,27 @@ func ParseTrunkRecorderMeta(call *Call, b []byte) error {
case float64:
freq["errorCount"] = uint(v)
}
switch v := v["freq"].(type) {
case float64:
freq["freq"] = uint(v)
}
switch v := v["len"].(type) {
case float64:
freq["len"] = uint(v)
}
switch v := v["pos"].(type) {
case float64:
freq["pos"] = uint(v)
}
switch v := v["spike_count"].(type) {
case float64:
freq["spikeCount"] = uint(v)
}
freqs = append(freqs, freq)
}
}
@ -142,10 +147,25 @@ func ParseTrunkRecorderMeta(call *Call, b []byte) error {
case float64:
source["pos"] = uint(v)
}
switch v := v["src"].(type) {
switch s := v["src"].(type) {
case float64:
source["src"] = uint(v)
source["src"] = uint(s)
switch t := v["tag"].(type) {
case string:
var units Units
switch v := call.units.(type) {
case Units:
units = v
default:
units = Units{}
}
units.Add(uint(s), t)
call.units = units
}
}
sources = append(sources, source)
}
}
@ -167,5 +187,11 @@ func ParseTrunkRecorderMeta(call *Call, b []byte) error {
call.Talkgroup = uint(v)
}
switch v := m["talkgroup_tag"].(type) {
case string:
call.talkgroupTag = v
call.talkgroupLabel = v
}
return nil
}

View file

@ -39,6 +39,23 @@ func (unit *Unit) FromMap(m map[string]interface{}) {
type Units []Unit
func (units *Units) Add(id uint, label string) *Units {
found := false
for _, u := range *units {
if u.Id == id {
found = true
break
}
}
if !found {
*units = append(*units, Unit{Id: id, Label: label})
}
return units
}
func (units *Units) FromJson(str string) error {
var v interface{}
@ -67,6 +84,12 @@ func (units *Units) FromJson(str string) error {
return nil
}
func (u *Units) Merge(units *Units) {
for _, v := range *units {
u.Add(v.Id, v.Label)
}
}
func (units *Units) ToJson() (string, error) {
if b, err := json.Marshal(*units); err == nil {
return string(b), nil