mirror of
https://github.com/chuot/rdio-scanner.git
synced 2026-08-13 16:33:01 -06:00
auto populate system units (issue #66)
This commit is contained in:
parent
6c15e7d47e
commit
789028ab02
|
|
@ -37,8 +37,8 @@ Call imported successfully
|
||||||
{
|
{
|
||||||
errorCount: number;
|
errorCount: number;
|
||||||
freq: number; // in hertz
|
freq: number; // in hertz
|
||||||
len: number; // in seconds
|
len: number; // in seconds
|
||||||
pos: number; // in seconds
|
pos: number; // in seconds
|
||||||
spikeCount: number;
|
spikeCount: number;
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
|
|
@ -49,7 +49,8 @@ Call imported successfully
|
||||||
|
|
||||||
{
|
{
|
||||||
pos: number; // in seconds
|
pos: number; // in seconds
|
||||||
src: number; // the unit ID
|
src: number; // unit ID
|
||||||
|
tag: number; // [optional] unit tag
|
||||||
}[];
|
}[];
|
||||||
|
|
||||||
- **system** - [optional] system ID.
|
- **system** - [optional] system ID.
|
||||||
|
|
|
||||||
|
|
@ -271,8 +271,6 @@ func (admin *Admin) GetAuthorization(r *http.Request) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (admin *Admin) GetConfig() map[string]interface{} {
|
func (admin *Admin) GetConfig() map[string]interface{} {
|
||||||
// _, docker := os.LookupEnv("DOCKER")
|
|
||||||
|
|
||||||
systems := []map[string]interface{}{}
|
systems := []map[string]interface{}{}
|
||||||
for _, system := range *admin.Controller.Systems {
|
for _, system := range *admin.Controller.Systems {
|
||||||
systems = append(systems, map[string]interface{}{
|
systems = append(systems, map[string]interface{}{
|
||||||
|
|
@ -284,14 +282,14 @@ func (admin *Admin) GetConfig() map[string]interface{} {
|
||||||
"led": system.Led,
|
"led": system.Led,
|
||||||
"order": system.Order,
|
"order": system.Order,
|
||||||
"talkgroups": system.Talkgroups,
|
"talkgroups": system.Talkgroups,
|
||||||
|
"units": system.Units,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"access": *admin.Controller.Accesses,
|
"access": *admin.Controller.Accesses,
|
||||||
"apiKeys": *admin.Controller.Apikeys,
|
"apiKeys": *admin.Controller.Apikeys,
|
||||||
"dirWatch": *admin.Controller.Dirwatches,
|
"dirWatch": *admin.Controller.Dirwatches,
|
||||||
// "docker": docker,
|
|
||||||
"downstreams": *admin.Controller.Downstreams,
|
"downstreams": *admin.Controller.Downstreams,
|
||||||
"groups": *admin.Controller.Groups,
|
"groups": *admin.Controller.Groups,
|
||||||
"options": *admin.Controller.Options,
|
"options": *admin.Controller.Options,
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ func (api *Api) CallUploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
talkgroupGroup interface{}
|
talkgroupGroup interface{}
|
||||||
talkgroupLabel interface{}
|
talkgroupLabel interface{}
|
||||||
talkgroupTag interface{}
|
talkgroupTag interface{}
|
||||||
|
units interface{}
|
||||||
)
|
)
|
||||||
|
|
||||||
mediaType, params, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
|
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)
|
src["pos"] = uint(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch v := v["src"].(type) {
|
switch s := v["src"].(type) {
|
||||||
case float64:
|
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,
|
talkgroupGroup: talkgroupGroup,
|
||||||
talkgroupLabel: talkgroupLabel,
|
talkgroupLabel: talkgroupLabel,
|
||||||
talkgroupTag: talkgroupTag,
|
talkgroupTag: talkgroupTag,
|
||||||
|
units: units,
|
||||||
}
|
}
|
||||||
|
|
||||||
if call.IsValid() {
|
if call.IsValid() {
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ type Call struct {
|
||||||
talkgroupGroup interface{}
|
talkgroupGroup interface{}
|
||||||
talkgroupLabel interface{}
|
talkgroupLabel interface{}
|
||||||
talkgroupTag interface{}
|
talkgroupTag interface{}
|
||||||
|
units interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (call *Call) IsValid() bool {
|
func (call *Call) IsValid() bool {
|
||||||
|
|
|
||||||
|
|
@ -288,6 +288,14 @@ func (controller *Controller) IngestCall(call *Call) {
|
||||||
system.Talkgroups = append(system.Talkgroups, talkgroup)
|
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 populated {
|
||||||
if err = controller.Systems.Write(controller.Database); err != nil {
|
if err = controller.Systems.Write(controller.Database); err != nil {
|
||||||
logError(err)
|
logError(err)
|
||||||
|
|
|
||||||
|
|
@ -109,22 +109,27 @@ func ParseTrunkRecorderMeta(call *Call, b []byte) error {
|
||||||
case float64:
|
case float64:
|
||||||
freq["errorCount"] = uint(v)
|
freq["errorCount"] = uint(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch v := v["freq"].(type) {
|
switch v := v["freq"].(type) {
|
||||||
case float64:
|
case float64:
|
||||||
freq["freq"] = uint(v)
|
freq["freq"] = uint(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch v := v["len"].(type) {
|
switch v := v["len"].(type) {
|
||||||
case float64:
|
case float64:
|
||||||
freq["len"] = uint(v)
|
freq["len"] = uint(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch v := v["pos"].(type) {
|
switch v := v["pos"].(type) {
|
||||||
case float64:
|
case float64:
|
||||||
freq["pos"] = uint(v)
|
freq["pos"] = uint(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch v := v["spike_count"].(type) {
|
switch v := v["spike_count"].(type) {
|
||||||
case float64:
|
case float64:
|
||||||
freq["spikeCount"] = uint(v)
|
freq["spikeCount"] = uint(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
freqs = append(freqs, freq)
|
freqs = append(freqs, freq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,10 +147,25 @@ func ParseTrunkRecorderMeta(call *Call, b []byte) error {
|
||||||
case float64:
|
case float64:
|
||||||
source["pos"] = uint(v)
|
source["pos"] = uint(v)
|
||||||
}
|
}
|
||||||
switch v := v["src"].(type) {
|
|
||||||
|
switch s := v["src"].(type) {
|
||||||
case float64:
|
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)
|
sources = append(sources, source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -167,5 +187,11 @@ func ParseTrunkRecorderMeta(call *Call, b []byte) error {
|
||||||
call.Talkgroup = uint(v)
|
call.Talkgroup = uint(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch v := m["talkgroup_tag"].(type) {
|
||||||
|
case string:
|
||||||
|
call.talkgroupTag = v
|
||||||
|
call.talkgroupLabel = v
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,23 @@ func (unit *Unit) FromMap(m map[string]interface{}) {
|
||||||
|
|
||||||
type Units []Unit
|
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 {
|
func (units *Units) FromJson(str string) error {
|
||||||
var v interface{}
|
var v interface{}
|
||||||
|
|
||||||
|
|
@ -67,6 +84,12 @@ func (units *Units) FromJson(str string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *Units) Merge(units *Units) {
|
||||||
|
for _, v := range *units {
|
||||||
|
u.Add(v.Id, v.Label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (units *Units) ToJson() (string, error) {
|
func (units *Units) ToJson() (string, error) {
|
||||||
if b, err := json.Marshal(*units); err == nil {
|
if b, err := json.Marshal(*units); err == nil {
|
||||||
return string(b), nil
|
return string(b), nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue