Split out talkgroups
This commit is contained in:
parent
f71d9fee0d
commit
c3233f1bc8
5 changed files with 35 additions and 31 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"dynatron.me/x/stillbox/internal/audio"
|
"dynatron.me/x/stillbox/internal/audio"
|
||||||
"dynatron.me/x/stillbox/pkg/auth"
|
"dynatron.me/x/stillbox/pkg/auth"
|
||||||
"dynatron.me/x/stillbox/pkg/pb"
|
"dynatron.me/x/stillbox/pkg/pb"
|
||||||
|
"dynatron.me/x/stillbox/pkg/talkgroups"
|
||||||
|
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
@ -128,3 +129,8 @@ func (c *Call) computeLength() (err error) {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Call) TalkgroupTuple() talkgroups.Talkgroup {
|
||||||
|
return talkgroups.TG(c.System, c.Talkgroup)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,16 +5,18 @@ import (
|
||||||
|
|
||||||
"dynatron.me/x/stillbox/pkg/database"
|
"dynatron.me/x/stillbox/pkg/database"
|
||||||
"dynatron.me/x/stillbox/pkg/pb"
|
"dynatron.me/x/stillbox/pkg/pb"
|
||||||
|
|
||||||
|
tgs "dynatron.me/x/stillbox/pkg/talkgroups"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TalkgroupFilter struct {
|
type TalkgroupFilter struct {
|
||||||
Talkgroups []Talkgroup `json:"talkgroups,omitempty"`
|
Talkgroups []tgs.Talkgroup `json:"talkgroups,omitempty"`
|
||||||
TalkgroupsNot []Talkgroup `json:"talkgroupsNot,omitempty"`
|
TalkgroupsNot []tgs.Talkgroup `json:"talkgroupsNot,omitempty"`
|
||||||
TalkgroupTagsAll []string `json:"talkgroupTagsAll,omitempty"`
|
TalkgroupTagsAll []string `json:"talkgroupTagsAll,omitempty"`
|
||||||
TalkgroupTagsAny []string `json:"talkgroupTagsAny,omitempty"`
|
TalkgroupTagsAny []string `json:"talkgroupTagsAny,omitempty"`
|
||||||
TalkgroupTagsNot []string `json:"talkgroupTagsNot,omitempty"`
|
TalkgroupTagsNot []string `json:"talkgroupTagsNot,omitempty"`
|
||||||
|
|
||||||
talkgroups map[Talkgroup]bool
|
talkgroups map[tgs.Talkgroup]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func TalkgroupFilterFromPB(ctx context.Context, p *pb.Filter) (*TalkgroupFilter, error) {
|
func TalkgroupFilterFromPB(ctx context.Context, p *pb.Filter) (*TalkgroupFilter, error) {
|
||||||
|
@ -25,9 +27,9 @@ func TalkgroupFilterFromPB(ctx context.Context, p *pb.Filter) (*TalkgroupFilter,
|
||||||
}
|
}
|
||||||
|
|
||||||
if l := len(p.Talkgroups); l > 0 {
|
if l := len(p.Talkgroups); l > 0 {
|
||||||
tgf.Talkgroups = make([]Talkgroup, l)
|
tgf.Talkgroups = make([]tgs.Talkgroup, l)
|
||||||
for i, t := range p.Talkgroups {
|
for i, t := range p.Talkgroups {
|
||||||
tgf.Talkgroups[i] = Talkgroup{
|
tgf.Talkgroups[i] = tgs.Talkgroup{
|
||||||
System: uint32(t.System),
|
System: uint32(t.System),
|
||||||
Talkgroup: uint32(t.Talkgroup),
|
Talkgroup: uint32(t.Talkgroup),
|
||||||
}
|
}
|
||||||
|
@ -35,9 +37,9 @@ func TalkgroupFilterFromPB(ctx context.Context, p *pb.Filter) (*TalkgroupFilter,
|
||||||
}
|
}
|
||||||
|
|
||||||
if l := len(p.TalkgroupsNot); l > 0 {
|
if l := len(p.TalkgroupsNot); l > 0 {
|
||||||
tgf.TalkgroupsNot = make([]Talkgroup, l)
|
tgf.TalkgroupsNot = make([]tgs.Talkgroup, l)
|
||||||
for i, t := range p.TalkgroupsNot {
|
for i, t := range p.TalkgroupsNot {
|
||||||
tgf.TalkgroupsNot[i] = Talkgroup{
|
tgf.TalkgroupsNot[i] = tgs.Talkgroup{
|
||||||
System: uint32(t.System),
|
System: uint32(t.System),
|
||||||
Talkgroup: uint32(t.Talkgroup),
|
Talkgroup: uint32(t.Talkgroup),
|
||||||
}
|
}
|
||||||
|
@ -51,12 +53,12 @@ func (f *TalkgroupFilter) hasTags() bool {
|
||||||
return len(f.TalkgroupTagsAny) > 0 || len(f.TalkgroupTagsAll) > 0 || len(f.TalkgroupTagsNot) > 0
|
return len(f.TalkgroupTagsAny) > 0 || len(f.TalkgroupTagsAll) > 0 || len(f.TalkgroupTagsNot) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TalkgroupFilter) GetFinalTalkgroups() map[Talkgroup]bool {
|
func (f *TalkgroupFilter) GetFinalTalkgroups() map[tgs.Talkgroup]bool {
|
||||||
return f.talkgroups
|
return f.talkgroups
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TalkgroupFilter) compile(ctx context.Context) error {
|
func (f *TalkgroupFilter) compile(ctx context.Context) error {
|
||||||
f.talkgroups = make(map[Talkgroup]bool)
|
f.talkgroups = make(map[tgs.Talkgroup]bool)
|
||||||
for _, tg := range f.Talkgroups {
|
for _, tg := range f.Talkgroups {
|
||||||
f.talkgroups[tg] = true
|
f.talkgroups[tg] = true
|
||||||
}
|
}
|
||||||
|
@ -69,7 +71,7 @@ func (f *TalkgroupFilter) compile(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tg := range tagTGs {
|
for _, tg := range tagTGs {
|
||||||
f.talkgroups[Talkgroup{System: uint32(tg.SystemID), Talkgroup: uint32(tg.Tgid)}] = true
|
f.talkgroups[tgs.Talkgroup{System: uint32(tg.SystemID), Talkgroup: uint32(tg.Tgid)}] = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package calls
|
package talkgroups
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
||||||
package calls_test
|
package talkgroups_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -8,26 +8,26 @@ import (
|
||||||
|
|
||||||
"dynatron.me/x/stillbox/internal/ruletime"
|
"dynatron.me/x/stillbox/internal/ruletime"
|
||||||
"dynatron.me/x/stillbox/internal/trending"
|
"dynatron.me/x/stillbox/internal/trending"
|
||||||
"dynatron.me/x/stillbox/pkg/calls"
|
"dynatron.me/x/stillbox/pkg/talkgroups"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAlertConfig(t *testing.T) {
|
func TestAlertConfig(t *testing.T) {
|
||||||
ac := make(calls.AlertConfig)
|
ac := make(talkgroups.AlertConfig)
|
||||||
parseTests := []struct {
|
parseTests := []struct {
|
||||||
name string
|
name string
|
||||||
tg calls.Talkgroup
|
tg talkgroups.Talkgroup
|
||||||
conf string
|
conf string
|
||||||
compare []calls.AlertRule
|
compare []talkgroups.AlertRule
|
||||||
expectErr error
|
expectErr error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "base case",
|
name: "base case",
|
||||||
tg: calls.TG(197, 3),
|
tg: talkgroups.TG(197, 3),
|
||||||
conf: `[{"times":["7:00+2h","01:00+1h","16:00+1h","19:00+4h"],"mult":0.2},{"times":["11:00+1h","15:00+30m","16:03+20m"],"mult":2.0}]`,
|
conf: `[{"times":["7:00+2h","01:00+1h","16:00+1h","19:00+4h"],"mult":0.2},{"times":["11:00+1h","15:00+30m","16:03+20m"],"mult":2.0}]`,
|
||||||
compare: []calls.AlertRule{
|
compare: []talkgroups.AlertRule{
|
||||||
{
|
{
|
||||||
Times: []ruletime.RuleTime{
|
Times: []ruletime.RuleTime{
|
||||||
ruletime.Must(ruletime.New("7:00+2h")),
|
ruletime.Must(ruletime.New("7:00+2h")),
|
||||||
|
@ -49,7 +49,7 @@ func TestAlertConfig(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bad spec",
|
name: "bad spec",
|
||||||
tg: calls.TG(197, 3),
|
tg: talkgroups.TG(197, 3),
|
||||||
conf: `[{"times":["26:00+2h","01:00+1h","19:00+4h"],"mult":0.2},{"times":["11:00+1h","15:00+30m"],"mult":2.0}]`,
|
conf: `[{"times":["26:00+2h","01:00+1h","19:00+4h"],"mult":0.2},{"times":["11:00+1h","15:00+30m"],"mult":2.0}]`,
|
||||||
expectErr: errors.New("'26:00+2h': invalid hours"),
|
expectErr: errors.New("'26:00+2h': invalid hours"),
|
||||||
},
|
},
|
||||||
|
@ -78,42 +78,42 @@ func TestAlertConfig(t *testing.T) {
|
||||||
|
|
||||||
evalTests := []struct {
|
evalTests := []struct {
|
||||||
name string
|
name string
|
||||||
tg calls.Talkgroup
|
tg talkgroups.Talkgroup
|
||||||
t time.Time
|
t time.Time
|
||||||
origScore float64
|
origScore float64
|
||||||
expectScore float64
|
expectScore float64
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "base eval",
|
name: "base eval",
|
||||||
tg: calls.TG(197, 3),
|
tg: talkgroups.TG(197, 3),
|
||||||
t: tMust("1:20"),
|
t: tMust("1:20"),
|
||||||
origScore: 3,
|
origScore: 3,
|
||||||
expectScore: 0.6,
|
expectScore: 0.6,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "base eval",
|
name: "base eval",
|
||||||
tg: calls.TG(197, 3),
|
tg: talkgroups.TG(197, 3),
|
||||||
t: tMust("23:03"),
|
t: tMust("23:03"),
|
||||||
origScore: 3,
|
origScore: 3,
|
||||||
expectScore: 3,
|
expectScore: 3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "base eval",
|
name: "base eval",
|
||||||
tg: calls.TG(197, 3),
|
tg: talkgroups.TG(197, 3),
|
||||||
t: tMust("8:03"),
|
t: tMust("8:03"),
|
||||||
origScore: 1.0,
|
origScore: 1.0,
|
||||||
expectScore: 0.2,
|
expectScore: 0.2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "base eval",
|
name: "base eval",
|
||||||
tg: calls.TG(197, 3),
|
tg: talkgroups.TG(197, 3),
|
||||||
t: tMust("15:15"),
|
t: tMust("15:15"),
|
||||||
origScore: 3.0,
|
origScore: 3.0,
|
||||||
expectScore: 6.0,
|
expectScore: 6.0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "overlapping eval",
|
name: "overlapping eval",
|
||||||
tg: calls.TG(197, 3),
|
tg: talkgroups.TG(197, 3),
|
||||||
t: tMust("16:10"),
|
t: tMust("16:10"),
|
||||||
origScore: 1.0,
|
origScore: 1.0,
|
||||||
expectScore: 0.4,
|
expectScore: 0.4,
|
||||||
|
@ -122,7 +122,7 @@ func TestAlertConfig(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range evalTests {
|
for _, tc := range evalTests {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
cs := trending.Score[calls.Talkgroup]{
|
cs := trending.Score[talkgroups.Talkgroup]{
|
||||||
ID: tc.tg,
|
ID: tc.tg,
|
||||||
Score: tc.origScore,
|
Score: tc.origScore,
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package calls
|
package talkgroups
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -20,10 +20,6 @@ type Talkgroup struct {
|
||||||
Talkgroup uint32
|
Talkgroup uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Call) TalkgroupTuple() Talkgroup {
|
|
||||||
return Talkgroup{System: uint32(c.System), Talkgroup: uint32(c.Talkgroup)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TG[T int | uint | int64 | uint64 | int32 | uint32](sys, tgid T) Talkgroup {
|
func TG[T int | uint | int64 | uint64 | int32 | uint32](sys, tgid T) Talkgroup {
|
||||||
return Talkgroup{
|
return Talkgroup{
|
||||||
System: uint32(sys),
|
System: uint32(sys),
|
Loading…
Reference in a new issue