Alert Rules rename

This commit is contained in:
Daniel Ponte 2025-01-07 22:14:30 -05:00
parent aabc383678
commit 7c3ef1badf
12 changed files with 113 additions and 113 deletions

View file

@ -61,7 +61,7 @@ export class Talkgroup {
tags!: string[]; tags!: string[];
alert!: boolean; alert!: boolean;
system?: System; system?: System;
alert_config!: AlertRule[]; alert_rules!: AlertRule[];
weight!: number; weight!: number;
learned?: boolean; learned?: boolean;
icon?: string; icon?: string;
@ -77,7 +77,7 @@ export class Talkgroup {
metadata: Metadata | null, metadata: Metadata | null,
tags: string[], tags: string[],
alert: boolean, alert: boolean,
alert_config: AlertRule[], alert_rules: AlertRule[],
weight: number, weight: number,
system?: System, system?: System,
learned?: boolean, learned?: boolean,
@ -113,6 +113,6 @@ export interface TalkgroupUpdate {
metadata: Object | null; metadata: Object | null;
tags: string[] | null; tags: string[] | null;
alert: boolean | null; alert: boolean | null;
alert_config: AlertRule[] | null; alert_rules: AlertRule[] | null;
weight: number | null; weight: number | null;
} }

View file

@ -108,7 +108,7 @@
> >
</div> </div>
<div class="alert"> <div class="alert">
<alert-rule-builder [rules]="tg.alert_config" /> <alert-rule-builder [rules]="tg.alert_rules" />
</div> </div>
</form> </form>
} @else { } @else {

View file

@ -16,7 +16,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestAlertConfig(t *testing.T) { func TestAlertRules(t *testing.T) {
parseTests := []struct { parseTests := []struct {
name string name string
tg talkgroups.ID tg talkgroups.ID

View file

@ -30,7 +30,7 @@ INSERT INTO talkgroup_versions(time, created_by,
metadata, metadata,
tags, tags,
alert, alert,
alert_config, alert_rules,
weight, weight,
learned learned
) SELECT NOW(), $1, ) SELECT NOW(), $1,
@ -43,7 +43,7 @@ INSERT INTO talkgroup_versions(time, created_by,
tg.metadata, tg.metadata,
tg.tags, tg.tags,
tg.alert, tg.alert,
tg.alert_config, tg.alert_rules,
tg.weight, tg.weight,
tg.learned tg.learned
FROM talkgroups tg WHERE tg.system_id = $2 AND tg.tgid = $3 FROM talkgroups tg WHERE tg.system_id = $2 AND tg.tgid = $3
@ -98,7 +98,7 @@ func (b *StoreTGVersionBatchResults) Close() error {
const upsertTalkgroup = `-- name: UpsertTalkgroup :batchone const upsertTalkgroup = `-- name: UpsertTalkgroup :batchone
INSERT INTO talkgroups AS tg ( INSERT INTO talkgroups AS tg (
system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_rules, weight, learned
) VALUES ( ) VALUES (
$1, $1,
$2, $2,
@ -122,10 +122,10 @@ SET
metadata = COALESCE($7, tg.metadata), metadata = COALESCE($7, tg.metadata),
tags = COALESCE($8, tg.tags), tags = COALESCE($8, tg.tags),
alert = COALESCE($9, tg.alert), alert = COALESCE($9, tg.alert),
alert_config = COALESCE($10, tg.alert_config), alert_rules = COALESCE($10, tg.alert_rules),
weight = COALESCE($11, tg.weight), weight = COALESCE($11, tg.weight),
learned = COALESCE($12, tg.learned) learned = COALESCE($12, tg.learned)
RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned, ignored RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_rules, weight, learned, ignored
` `
type UpsertTalkgroupBatchResults struct { type UpsertTalkgroupBatchResults struct {
@ -135,18 +135,18 @@ type UpsertTalkgroupBatchResults struct {
} }
type UpsertTalkgroupParams struct { type UpsertTalkgroupParams struct {
SystemID int32 `json:"system_id"` SystemID int32 `json:"system_id"`
TGID int32 `json:"tgid"` TGID int32 `json:"tgid"`
Name *string `json:"name"` Name *string `json:"name"`
AlphaTag *string `json:"alpha_tag"` AlphaTag *string `json:"alpha_tag"`
TGGroup *string `json:"tg_group"` TGGroup *string `json:"tg_group"`
Frequency *int32 `json:"frequency"` Frequency *int32 `json:"frequency"`
Metadata jsontypes.Metadata `json:"metadata"` Metadata jsontypes.Metadata `json:"metadata"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
Alert interface{} `json:"alert"` Alert interface{} `json:"alert"`
AlertConfig rules.AlertRules `json:"alert_config"` AlertRules rules.AlertRules `json:"alert_rules"`
Weight pgtype.Numeric `json:"weight"` Weight pgtype.Numeric `json:"weight"`
Learned *bool `json:"learned"` Learned *bool `json:"learned"`
} }
func (q *Queries) UpsertTalkgroup(ctx context.Context, arg []UpsertTalkgroupParams) *UpsertTalkgroupBatchResults { func (q *Queries) UpsertTalkgroup(ctx context.Context, arg []UpsertTalkgroupParams) *UpsertTalkgroupBatchResults {
@ -162,7 +162,7 @@ func (q *Queries) UpsertTalkgroup(ctx context.Context, arg []UpsertTalkgroupPara
a.Metadata, a.Metadata,
a.Tags, a.Tags,
a.Alert, a.Alert,
a.AlertConfig, a.AlertRules,
a.Weight, a.Weight,
a.Learned, a.Learned,
} }
@ -194,7 +194,7 @@ func (b *UpsertTalkgroupBatchResults) QueryRow(f func(int, Talkgroup, error)) {
&i.Metadata, &i.Metadata,
&i.Tags, &i.Tags,
&i.Alert, &i.Alert,
&i.AlertConfig, &i.AlertRules,
&i.Weight, &i.Weight,
&i.Learned, &i.Learned,
&i.Ignored, &i.Ignored,

View file

@ -107,40 +107,40 @@ type System struct {
} }
type Talkgroup struct { type Talkgroup struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
SystemID int32 `json:"system_id,omitempty"` SystemID int32 `json:"system_id,omitempty"`
TGID int32 `json:"tgid,omitempty"` TGID int32 `json:"tgid,omitempty"`
Name *string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
AlphaTag *string `json:"alpha_tag,omitempty"` AlphaTag *string `json:"alpha_tag,omitempty"`
TGGroup *string `json:"tg_group,omitempty"` TGGroup *string `json:"tg_group,omitempty"`
Frequency *int32 `json:"frequency,omitempty"` Frequency *int32 `json:"frequency,omitempty"`
Metadata jsontypes.Metadata `json:"metadata,omitempty"` Metadata jsontypes.Metadata `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"` Tags []string `json:"tags,omitempty"`
Alert bool `json:"alert,omitempty"` Alert bool `json:"alert,omitempty"`
AlertConfig rules.AlertRules `json:"alert_config,omitempty"` AlertRules rules.AlertRules `json:"alert_rules,omitempty"`
Weight float32 `json:"weight,omitempty"` Weight float32 `json:"weight,omitempty"`
Learned bool `json:"learned,omitempty"` Learned bool `json:"learned,omitempty"`
Ignored bool `json:"ignored,omitempty"` Ignored bool `json:"ignored,omitempty"`
} }
type TalkgroupVersion struct { type TalkgroupVersion struct {
ID int `json:"id,omitempty"` ID int `json:"id,omitempty"`
Time pgtype.Timestamptz `json:"time,omitempty"` Time pgtype.Timestamptz `json:"time,omitempty"`
CreatedBy *int32 `json:"created_by,omitempty"` CreatedBy *int32 `json:"created_by,omitempty"`
Deleted *bool `json:"deleted,omitempty"` Deleted *bool `json:"deleted,omitempty"`
SystemID *int32 `json:"system_id,omitempty"` SystemID *int32 `json:"system_id,omitempty"`
TGID *int32 `json:"tgid,omitempty"` TGID *int32 `json:"tgid,omitempty"`
Name *string `json:"name,omitempty"` Name *string `json:"name,omitempty"`
AlphaTag *string `json:"alpha_tag,omitempty"` AlphaTag *string `json:"alpha_tag,omitempty"`
TGGroup *string `json:"tg_group,omitempty"` TGGroup *string `json:"tg_group,omitempty"`
Frequency *int32 `json:"frequency,omitempty"` Frequency *int32 `json:"frequency,omitempty"`
Metadata []byte `json:"metadata,omitempty"` Metadata []byte `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"` Tags []string `json:"tags,omitempty"`
Alert *bool `json:"alert,omitempty"` Alert *bool `json:"alert,omitempty"`
AlertConfig []byte `json:"alert_config,omitempty"` AlertRules []byte `json:"alert_rules,omitempty"`
Weight *float32 `json:"weight,omitempty"` Weight *float32 `json:"weight,omitempty"`
Learned *bool `json:"learned,omitempty"` Learned *bool `json:"learned,omitempty"`
Ignored *bool `json:"ignored,omitempty"` Ignored *bool `json:"ignored,omitempty"`
} }
type User struct { type User struct {

View file

@ -52,7 +52,7 @@ func (t *TGTuples) Append(sys, tg uint32) {
// Below queries are here because sqlc refuses to parse unnest(x, y) // Below queries are here because sqlc refuses to parse unnest(x, y)
const getTalkgroupsWithLearnedBySysTGID = `SELECT const getTalkgroupsWithLearnedBySysTGID = `SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, sys.id, sys.name, tg.learned, tg.ignored tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_rules, tg.weight, sys.id, sys.name, tg.learned, tg.ignored
FROM talkgroups tg FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id JOIN systems sys ON tg.system_id = sys.id
JOIN UNNEST($1::INT4[], $2::INT4[]) AS tgt(sys, tg) ON (tg.system_id = tgt.sys AND tg.tgid = tgt.tg);` JOIN UNNEST($1::INT4[], $2::INT4[]) AS tgt(sys, tg) ON (tg.system_id = tgt.sys AND tg.tgid = tgt.tg);`
@ -82,7 +82,7 @@ func (q *Queries) GetTalkgroupsWithLearnedBySysTGID(ctx context.Context, ids TGT
&i.Talkgroup.Metadata, &i.Talkgroup.Metadata,
&i.Talkgroup.Tags, &i.Talkgroup.Tags,
&i.Talkgroup.Alert, &i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig, &i.Talkgroup.AlertRules,
&i.Talkgroup.Weight, &i.Talkgroup.Weight,
&i.System.ID, &i.System.ID,
&i.System.Name, &i.System.Name,
@ -99,7 +99,7 @@ func (q *Queries) GetTalkgroupsWithLearnedBySysTGID(ctx context.Context, ids TGT
return items, nil return items, nil
} }
const getTalkgroupsBySysTGID = `SELECT tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name FROM talkgroups tg const getTalkgroupsBySysTGID = `SELECT tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_rules, tg.weight, tg.learned, tg.ignored, sys.id, sys.name FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id JOIN systems sys ON tg.system_id = sys.id
JOIN UNNEST($1::INT4[], $2::INT4[]) AS tgt(sys, tg) ON (tg.system_id = tgt.sys AND tg.tgid = tgt.tg) JOIN UNNEST($1::INT4[], $2::INT4[]) AS tgt(sys, tg) ON (tg.system_id = tgt.sys AND tg.tgid = tgt.tg)
WHERE tg.learned IS NOT TRUE;` WHERE tg.learned IS NOT TRUE;`
@ -124,7 +124,7 @@ func (q *Queries) GetTalkgroupsBySysTGID(ctx context.Context, ids TGTuples) ([]G
&i.Talkgroup.Metadata, &i.Talkgroup.Metadata,
&i.Talkgroup.Tags, &i.Talkgroup.Tags,
&i.Talkgroup.Alert, &i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig, &i.Talkgroup.AlertRules,
&i.Talkgroup.Weight, &i.Talkgroup.Weight,
&i.Talkgroup.Learned, &i.Talkgroup.Learned,
&i.Talkgroup.Ignored, &i.Talkgroup.Ignored,

View file

@ -27,7 +27,7 @@ INSERT INTO talkgroups(
$3, $3,
$4, $4,
$5 $5
) RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned, ignored ) RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_rules, weight, learned, ignored
` `
type AddLearnedTalkgroupParams struct { type AddLearnedTalkgroupParams struct {
@ -58,7 +58,7 @@ func (q *Queries) AddLearnedTalkgroup(ctx context.Context, arg AddLearnedTalkgro
&i.Metadata, &i.Metadata,
&i.Tags, &i.Tags,
&i.Alert, &i.Alert,
&i.AlertConfig, &i.AlertRules,
&i.Weight, &i.Weight,
&i.Learned, &i.Learned,
&i.Ignored, &i.Ignored,
@ -129,7 +129,7 @@ func (q *Queries) GetSystemName(ctx context.Context, systemID int) (string, erro
} }
const getTalkgroup = `-- name: GetTalkgroup :one const getTalkgroup = `-- name: GetTalkgroup :one
SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight, talkgroups.learned, talkgroups.ignored FROM talkgroups SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_rules, talkgroups.weight, talkgroups.learned, talkgroups.ignored FROM talkgroups
WHERE (system_id, tgid) = ($1, $2) WHERE (system_id, tgid) = ($1, $2)
` `
@ -151,7 +151,7 @@ func (q *Queries) GetTalkgroup(ctx context.Context, systemID int32, tGID int32)
&i.Talkgroup.Metadata, &i.Talkgroup.Metadata,
&i.Talkgroup.Tags, &i.Talkgroup.Tags,
&i.Talkgroup.Alert, &i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig, &i.Talkgroup.AlertRules,
&i.Talkgroup.Weight, &i.Talkgroup.Weight,
&i.Talkgroup.Learned, &i.Talkgroup.Learned,
&i.Talkgroup.Ignored, &i.Talkgroup.Ignored,
@ -205,7 +205,7 @@ func (q *Queries) GetTalkgroupTags(ctx context.Context, systemID int32, tGID int
const getTalkgroupWithLearned = `-- name: GetTalkgroupWithLearned :one const getTalkgroupWithLearned = `-- name: GetTalkgroupWithLearned :one
SELECT SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_rules, tg.weight, tg.learned, tg.ignored, sys.id, sys.name
FROM talkgroups tg FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id JOIN systems sys ON tg.system_id = sys.id
WHERE (tg.system_id, tg.tgid) = ($1, $2) WHERE (tg.system_id, tg.tgid) = ($1, $2)
@ -230,7 +230,7 @@ func (q *Queries) GetTalkgroupWithLearned(ctx context.Context, systemID int32, t
&i.Talkgroup.Metadata, &i.Talkgroup.Metadata,
&i.Talkgroup.Tags, &i.Talkgroup.Tags,
&i.Talkgroup.Alert, &i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig, &i.Talkgroup.AlertRules,
&i.Talkgroup.Weight, &i.Talkgroup.Weight,
&i.Talkgroup.Learned, &i.Talkgroup.Learned,
&i.Talkgroup.Ignored, &i.Talkgroup.Ignored,
@ -241,7 +241,7 @@ func (q *Queries) GetTalkgroupWithLearned(ctx context.Context, systemID int32, t
} }
const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many
SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight, talkgroups.learned, talkgroups.ignored FROM talkgroups SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_rules, talkgroups.weight, talkgroups.learned, talkgroups.ignored FROM talkgroups
WHERE tags && ARRAY[$1] WHERE tags && ARRAY[$1]
` `
@ -269,7 +269,7 @@ func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) (
&i.Talkgroup.Metadata, &i.Talkgroup.Metadata,
&i.Talkgroup.Tags, &i.Talkgroup.Tags,
&i.Talkgroup.Alert, &i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig, &i.Talkgroup.AlertRules,
&i.Talkgroup.Weight, &i.Talkgroup.Weight,
&i.Talkgroup.Learned, &i.Talkgroup.Learned,
&i.Talkgroup.Ignored, &i.Talkgroup.Ignored,
@ -285,7 +285,7 @@ func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) (
} }
const getTalkgroupsWithAnyTags = `-- name: GetTalkgroupsWithAnyTags :many const getTalkgroupsWithAnyTags = `-- name: GetTalkgroupsWithAnyTags :many
SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_config, talkgroups.weight, talkgroups.learned, talkgroups.ignored FROM talkgroups SELECT talkgroups.id, talkgroups.system_id, talkgroups.tgid, talkgroups.name, talkgroups.alpha_tag, talkgroups.tg_group, talkgroups.frequency, talkgroups.metadata, talkgroups.tags, talkgroups.alert, talkgroups.alert_rules, talkgroups.weight, talkgroups.learned, talkgroups.ignored FROM talkgroups
WHERE tags @> ARRAY[$1] WHERE tags @> ARRAY[$1]
` `
@ -313,7 +313,7 @@ func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) (
&i.Talkgroup.Metadata, &i.Talkgroup.Metadata,
&i.Talkgroup.Tags, &i.Talkgroup.Tags,
&i.Talkgroup.Alert, &i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig, &i.Talkgroup.AlertRules,
&i.Talkgroup.Weight, &i.Talkgroup.Weight,
&i.Talkgroup.Learned, &i.Talkgroup.Learned,
&i.Talkgroup.Ignored, &i.Talkgroup.Ignored,
@ -330,7 +330,7 @@ func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) (
const getTalkgroupsWithLearned = `-- name: GetTalkgroupsWithLearned :many const getTalkgroupsWithLearned = `-- name: GetTalkgroupsWithLearned :many
SELECT SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_rules, tg.weight, tg.learned, tg.ignored, sys.id, sys.name
FROM talkgroups tg FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id JOIN systems sys ON tg.system_id = sys.id
WHERE ignored IS NOT TRUE WHERE ignored IS NOT TRUE
@ -361,7 +361,7 @@ func (q *Queries) GetTalkgroupsWithLearned(ctx context.Context) ([]GetTalkgroups
&i.Talkgroup.Metadata, &i.Talkgroup.Metadata,
&i.Talkgroup.Tags, &i.Talkgroup.Tags,
&i.Talkgroup.Alert, &i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig, &i.Talkgroup.AlertRules,
&i.Talkgroup.Weight, &i.Talkgroup.Weight,
&i.Talkgroup.Learned, &i.Talkgroup.Learned,
&i.Talkgroup.Ignored, &i.Talkgroup.Ignored,
@ -380,7 +380,7 @@ func (q *Queries) GetTalkgroupsWithLearned(ctx context.Context) ([]GetTalkgroups
const getTalkgroupsWithLearnedBySystem = `-- name: GetTalkgroupsWithLearnedBySystem :many const getTalkgroupsWithLearnedBySystem = `-- name: GetTalkgroupsWithLearnedBySystem :many
SELECT SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_rules, tg.weight, tg.learned, tg.ignored, sys.id, sys.name
FROM talkgroups tg FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id JOIN systems sys ON tg.system_id = sys.id
WHERE tg.system_id = $1 WHERE tg.system_id = $1
@ -411,7 +411,7 @@ func (q *Queries) GetTalkgroupsWithLearnedBySystem(ctx context.Context, system i
&i.Talkgroup.Metadata, &i.Talkgroup.Metadata,
&i.Talkgroup.Tags, &i.Talkgroup.Tags,
&i.Talkgroup.Alert, &i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig, &i.Talkgroup.AlertRules,
&i.Talkgroup.Weight, &i.Talkgroup.Weight,
&i.Talkgroup.Learned, &i.Talkgroup.Learned,
&i.Talkgroup.Ignored, &i.Talkgroup.Ignored,
@ -448,7 +448,7 @@ func (q *Queries) GetTalkgroupsWithLearnedBySystemCount(ctx context.Context, sys
const getTalkgroupsWithLearnedBySystemP = `-- name: GetTalkgroupsWithLearnedBySystemP :many const getTalkgroupsWithLearnedBySystemP = `-- name: GetTalkgroupsWithLearnedBySystemP :many
SELECT SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_rules, tg.weight, tg.learned, tg.ignored, sys.id, sys.name
FROM talkgroups tg FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id JOIN systems sys ON tg.system_id = sys.id
WHERE tg.system_id = $1 AND WHERE tg.system_id = $1 AND
@ -512,7 +512,7 @@ func (q *Queries) GetTalkgroupsWithLearnedBySystemP(ctx context.Context, arg Get
&i.Talkgroup.Metadata, &i.Talkgroup.Metadata,
&i.Talkgroup.Tags, &i.Talkgroup.Tags,
&i.Talkgroup.Alert, &i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig, &i.Talkgroup.AlertRules,
&i.Talkgroup.Weight, &i.Talkgroup.Weight,
&i.Talkgroup.Learned, &i.Talkgroup.Learned,
&i.Talkgroup.Ignored, &i.Talkgroup.Ignored,
@ -549,7 +549,7 @@ func (q *Queries) GetTalkgroupsWithLearnedCount(ctx context.Context, filter *str
const getTalkgroupsWithLearnedP = `-- name: GetTalkgroupsWithLearnedP :many const getTalkgroupsWithLearnedP = `-- name: GetTalkgroupsWithLearnedP :many
SELECT SELECT
tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_config, tg.weight, tg.learned, tg.ignored, sys.id, sys.name tg.id, tg.system_id, tg.tgid, tg.name, tg.alpha_tag, tg.tg_group, tg.frequency, tg.metadata, tg.tags, tg.alert, tg.alert_rules, tg.weight, tg.learned, tg.ignored, sys.id, sys.name
FROM talkgroups tg FROM talkgroups tg
JOIN systems sys ON tg.system_id = sys.id JOIN systems sys ON tg.system_id = sys.id
WHERE ignored IS NOT TRUE AND WHERE ignored IS NOT TRUE AND
@ -611,7 +611,7 @@ func (q *Queries) GetTalkgroupsWithLearnedP(ctx context.Context, arg GetTalkgrou
&i.Talkgroup.Metadata, &i.Talkgroup.Metadata,
&i.Talkgroup.Tags, &i.Talkgroup.Tags,
&i.Talkgroup.Alert, &i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig, &i.Talkgroup.AlertRules,
&i.Talkgroup.Weight, &i.Talkgroup.Weight,
&i.Talkgroup.Learned, &i.Talkgroup.Learned,
&i.Talkgroup.Ignored, &i.Talkgroup.Ignored,
@ -639,7 +639,7 @@ INSERT INTO talkgroups(
metadata, metadata,
tags, tags,
alert, alert,
alert_config, alert_rules,
weight, weight,
learned, learned,
ignored ignored
@ -654,7 +654,7 @@ SELECT
metadata, metadata,
tags, tags,
alert, alert,
alert_config, alert_rules,
weight, weight,
learned, learned,
ignored ignored
@ -665,12 +665,12 @@ FROM talkgroup_versions tgv ON CONFLICT (system_id, tgid) DO UPDATE SET
metadata = excluded.metadata, metadata = excluded.metadata,
tags = excluded.tags, tags = excluded.tags,
alert = excluded.alert, alert = excluded.alert,
alert_config = excluded.alert_config, alert_rules = excluded.alert_rules,
weight = excluded.weight, weight = excluded.weight,
learned = excluded.learner, learned = excluded.learner,
ignored = excluded.ignored ignored = excluded.ignored
WHERE tgv.id = ANY($1) WHERE tgv.id = ANY($1)
RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned, ignored RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_rules, weight, learned, ignored
` `
func (q *Queries) RestoreTalkgroupVersion(ctx context.Context, versionIds int) (Talkgroup, error) { func (q *Queries) RestoreTalkgroupVersion(ctx context.Context, versionIds int) (Talkgroup, error) {
@ -687,7 +687,7 @@ func (q *Queries) RestoreTalkgroupVersion(ctx context.Context, versionIds int) (
&i.Metadata, &i.Metadata,
&i.Tags, &i.Tags,
&i.Alert, &i.Alert,
&i.AlertConfig, &i.AlertRules,
&i.Weight, &i.Weight,
&i.Learned, &i.Learned,
&i.Ignored, &i.Ignored,
@ -730,27 +730,27 @@ SET
metadata = COALESCE($5, metadata), metadata = COALESCE($5, metadata),
tags = COALESCE($6, tags), tags = COALESCE($6, tags),
alert = COALESCE($7, alert), alert = COALESCE($7, alert),
alert_config = COALESCE($8, alert_config), alert_rules = COALESCE($8, alert_rules),
weight = COALESCE($9, weight), weight = COALESCE($9, weight),
learned = COALESCE($10, learned) learned = COALESCE($10, learned)
WHERE id = $11 OR (system_id = $12 AND tgid = $13) WHERE id = $11 OR (system_id = $12 AND tgid = $13)
RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned, ignored RETURNING id, system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_rules, weight, learned, ignored
` `
type UpdateTalkgroupParams struct { type UpdateTalkgroupParams struct {
Name *string `json:"name"` Name *string `json:"name"`
AlphaTag *string `json:"alpha_tag"` AlphaTag *string `json:"alpha_tag"`
TGGroup *string `json:"tg_group"` TGGroup *string `json:"tg_group"`
Frequency *int32 `json:"frequency"` Frequency *int32 `json:"frequency"`
Metadata jsontypes.Metadata `json:"metadata"` Metadata jsontypes.Metadata `json:"metadata"`
Tags []string `json:"tags"` Tags []string `json:"tags"`
Alert *bool `json:"alert"` Alert *bool `json:"alert"`
AlertConfig rules.AlertRules `json:"alert_config"` AlertRules rules.AlertRules `json:"alert_rules"`
Weight *float32 `json:"weight"` Weight *float32 `json:"weight"`
Learned *bool `json:"learned"` Learned *bool `json:"learned"`
ID *int32 `json:"id"` ID *int32 `json:"id"`
SystemID *int32 `json:"system_id"` SystemID *int32 `json:"system_id"`
TGID *int32 `json:"tgid"` TGID *int32 `json:"tgid"`
} }
func (q *Queries) UpdateTalkgroup(ctx context.Context, arg UpdateTalkgroupParams) (Talkgroup, error) { func (q *Queries) UpdateTalkgroup(ctx context.Context, arg UpdateTalkgroupParams) (Talkgroup, error) {
@ -762,7 +762,7 @@ func (q *Queries) UpdateTalkgroup(ctx context.Context, arg UpdateTalkgroupParams
arg.Metadata, arg.Metadata,
arg.Tags, arg.Tags,
arg.Alert, arg.Alert,
arg.AlertConfig, arg.AlertRules,
arg.Weight, arg.Weight,
arg.Learned, arg.Learned,
arg.ID, arg.ID,
@ -781,7 +781,7 @@ func (q *Queries) UpdateTalkgroup(ctx context.Context, arg UpdateTalkgroupParams
&i.Metadata, &i.Metadata,
&i.Tags, &i.Tags,
&i.Alert, &i.Alert,
&i.AlertConfig, &i.AlertRules,
&i.Weight, &i.Weight,
&i.Learned, &i.Learned,
&i.Ignored, &i.Ignored,

View file

@ -414,7 +414,7 @@ func (t *cache) Weight(ctx context.Context, id tgsp.ID, tm time.Time) float64 {
m := float64(tg.Weight) m := float64(tg.Weight)
m *= tg.AlertConfig.Apply(tm) m *= tg.AlertRules.Apply(tm)
return float64(m) return float64(m)
} }

File diff suppressed because one or more lines are too long

View file

@ -35,7 +35,7 @@ CREATE TABLE IF NOT EXISTS talkgroups(
metadata JSONB, metadata JSONB,
tags TEXT[] NOT NULL DEFAULT '{}', tags TEXT[] NOT NULL DEFAULT '{}',
alert BOOLEAN NOT NULL DEFAULT 'true', alert BOOLEAN NOT NULL DEFAULT 'true',
alert_config JSONB, alert_rules JSONB,
weight REAL NOT NULL DEFAULT 1.0, weight REAL NOT NULL DEFAULT 1.0,
learned BOOLEAN NOT NULL DEFAULT FALSE, learned BOOLEAN NOT NULL DEFAULT FALSE,
ignored BOOLEAN NOT NULL DEFAULT FALSE, ignored BOOLEAN NOT NULL DEFAULT FALSE,
@ -62,7 +62,7 @@ CREATE TABLE IF NOT EXISTS talkgroup_versions(
metadata JSONB, metadata JSONB,
tags TEXT[], tags TEXT[],
alert BOOLEAN, alert BOOLEAN,
alert_config JSONB, alert_rules JSONB,
weight REAL, weight REAL,
learned BOOLEAN, learned BOOLEAN,
ignored BOOLEAN ignored BOOLEAN

View file

@ -137,7 +137,7 @@ SET
metadata = COALESCE(sqlc.narg('metadata'), metadata), metadata = COALESCE(sqlc.narg('metadata'), metadata),
tags = COALESCE(sqlc.narg('tags'), tags), tags = COALESCE(sqlc.narg('tags'), tags),
alert = COALESCE(sqlc.narg('alert'), alert), alert = COALESCE(sqlc.narg('alert'), alert),
alert_config = COALESCE(sqlc.narg('alert_config'), alert_config), alert_rules = COALESCE(sqlc.narg('alert_rules'), alert_rules),
weight = COALESCE(sqlc.narg('weight'), weight), weight = COALESCE(sqlc.narg('weight'), weight),
learned = COALESCE(sqlc.narg('learned'), learned) learned = COALESCE(sqlc.narg('learned'), learned)
WHERE id = sqlc.narg('id') OR (system_id = sqlc.narg('system_id') AND tgid = sqlc.narg('tgid')) WHERE id = sqlc.narg('id') OR (system_id = sqlc.narg('system_id') AND tgid = sqlc.narg('tgid'))
@ -145,7 +145,7 @@ RETURNING *;
-- name: UpsertTalkgroup :batchone -- name: UpsertTalkgroup :batchone
INSERT INTO talkgroups AS tg ( INSERT INTO talkgroups AS tg (
system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_config, weight, learned system_id, tgid, name, alpha_tag, tg_group, frequency, metadata, tags, alert, alert_rules, weight, learned
) VALUES ( ) VALUES (
@system_id, @system_id,
@tgid, @tgid,
@ -156,7 +156,7 @@ INSERT INTO talkgroups AS tg (
sqlc.narg('metadata'), sqlc.narg('metadata'),
COALESCE(sqlc.narg('tags'), '{}'::text[])::text[], COALESCE(sqlc.narg('tags'), '{}'::text[])::text[],
COALESCE(sqlc.narg('alert'), TRUE), COALESCE(sqlc.narg('alert'), TRUE),
sqlc.narg('alert_config'), sqlc.narg('alert_rules'),
COALESCE(sqlc.narg('weight'), 1.0)::numeric, COALESCE(sqlc.narg('weight'), 1.0)::numeric,
COALESCE(sqlc.narg('learned'), FALSE)::boolean COALESCE(sqlc.narg('learned'), FALSE)::boolean
) )
@ -169,7 +169,7 @@ SET
metadata = COALESCE(sqlc.narg('metadata'), tg.metadata), metadata = COALESCE(sqlc.narg('metadata'), tg.metadata),
tags = COALESCE(sqlc.narg('tags'), tg.tags), tags = COALESCE(sqlc.narg('tags'), tg.tags),
alert = COALESCE(sqlc.narg('alert'), tg.alert), alert = COALESCE(sqlc.narg('alert'), tg.alert),
alert_config = COALESCE(sqlc.narg('alert_config'), tg.alert_config), alert_rules = COALESCE(sqlc.narg('alert_rules'), tg.alert_rules),
weight = COALESCE(sqlc.narg('weight'), tg.weight), weight = COALESCE(sqlc.narg('weight'), tg.weight),
learned = COALESCE(sqlc.narg('learned'), tg.learned) learned = COALESCE(sqlc.narg('learned'), tg.learned)
RETURNING *; RETURNING *;
@ -185,7 +185,7 @@ INSERT INTO talkgroup_versions(time, created_by,
metadata, metadata,
tags, tags,
alert, alert,
alert_config, alert_rules,
weight, weight,
learned learned
) SELECT NOW(), @submitter, ) SELECT NOW(), @submitter,
@ -198,7 +198,7 @@ INSERT INTO talkgroup_versions(time, created_by,
tg.metadata, tg.metadata,
tg.tags, tg.tags,
tg.alert, tg.alert,
tg.alert_config, tg.alert_rules,
tg.weight, tg.weight,
tg.learned tg.learned
FROM talkgroups tg WHERE tg.system_id = @system_id AND tg.tgid = @tgid; FROM talkgroups tg WHERE tg.system_id = @system_id AND tg.tgid = @tgid;
@ -231,7 +231,7 @@ INSERT INTO talkgroups(
metadata, metadata,
tags, tags,
alert, alert,
alert_config, alert_rules,
weight, weight,
learned, learned,
ignored ignored
@ -246,7 +246,7 @@ SELECT
metadata, metadata,
tags, tags,
alert, alert,
alert_config, alert_rules,
weight, weight,
learned, learned,
ignored ignored
@ -257,7 +257,7 @@ FROM talkgroup_versions tgv ON CONFLICT (system_id, tgid) DO UPDATE SET
metadata = excluded.metadata, metadata = excluded.metadata,
tags = excluded.tags, tags = excluded.tags,
alert = excluded.alert, alert = excluded.alert,
alert_config = excluded.alert_config, alert_rules = excluded.alert_rules,
weight = excluded.weight, weight = excluded.weight,
learned = excluded.learner, learned = excluded.learner,
ignored = excluded.ignored ignored = excluded.ignored

View file

@ -27,7 +27,7 @@ sql:
go_type: "time.Time" go_type: "time.Time"
- db_type: "pg_catalog.text" - db_type: "pg_catalog.text"
go_type: "string" go_type: "string"
- column: "talkgroups.alert_config" - column: "talkgroups.alert_rules"
go_type: go_type:
import: "dynatron.me/x/stillbox/pkg/alerting/rules" import: "dynatron.me/x/stillbox/pkg/alerting/rules"
type: "AlertRules" type: "AlertRules"