Begin new alert rule builder #100

Merged
amigan merged 16 commits from alertRuleBuilder91 into trunk 2025-01-11 16:47:07 -05:00
23 changed files with 203 additions and 159 deletions

View file

@ -169,7 +169,11 @@
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columns; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: columns" [ngClass]="{'in-incident': row.incidents > 0}"></tr>
<tr
mat-row
*matRowDef="let row; columns: columns"
[ngClass]="{ 'in-incident': row.incidents > 0 }"
></tr>
</table>
</div>
<div class="pagFoot">

View file

@ -394,7 +394,7 @@ export class CallsComponent {
add: this.selection.selected.map((s, i, a) => {
s.incidents++;
return s.id;
}),
}),
})
.subscribe({
next: () => {

View file

@ -1,7 +1,12 @@
@let inc = inc$ | async;
<mat-card class="incident" appearance="outlined">
<div class="cardHdr">
<h1>{{ inc?.name }}</h1>
<h1>
{{ inc?.name }}
<a [href]="'/api/incident/' + incID + '.m3u'"
><mat-icon>playlist_play</mat-icon></a
>
</h1>
<button mat-icon-button (click)="editIncident(incID)">
<mat-icon>edit</mat-icon>
</button>

View file

@ -15,12 +15,19 @@ export class AlertTime {
}
export class AlertRule {
times: AlertTime[];
mult: number;
times!: string[];
mult!: number;
constructor(times: AlertTime[], mult: number) {
this.times = times;
this.mult = mult;
public getTimes(): AlertTime[] {
let timesProc = <AlertTime[]>[];
this.times.forEach((tm) => {
let sr = tm.split('+');
timesProc.push(<AlertTime>{
time: sr[0],
duration: sr[1],
});
});
return timesProc;
}
}
@ -61,7 +68,7 @@ export class Talkgroup {
tags!: string[];
alert!: boolean;
system?: System;
alert_config!: AlertRule[];
alert_rules!: AlertRule[];
weight!: number;
learned?: boolean;
icon?: string;
@ -77,13 +84,17 @@ export class Talkgroup {
metadata: Metadata | null,
tags: string[],
alert: boolean,
alert_config: AlertRule[],
alert_rules: AlertRule[],
weight: number,
system?: System,
learned?: boolean,
icon?: string,
) {
this.iconSvg = this.iconMap(this.metadata?.icon!);
this.alert_rules = this.alert_rules.map((x) =>
Object.assign(new AlertRule(), x),
);
console.log(this.alert_rules);
}
iconMap(icon: string): string {
@ -113,6 +124,6 @@ export interface TalkgroupUpdate {
metadata: Object | null;
tags: string[] | null;
alert: boolean | null;
alert_config: AlertRule[] | null;
alert_rules: AlertRule[] | null;
weight: number | null;
}

View file

@ -1,30 +1,21 @@
<div class="container flex">
@for (rule of rules; track $index) {
<div class="">
<table class="table">
<thead>
<tr>
<td>Start</td>
<td>Duration</td>
<td></td>
</tr>
</thead>
<tbody>
@for (time of rule.times; track $index) {
<tr>
<td>
{{ time.time }}
</td>
<td>
{{ time.duration }}
</td>
</tr>
} @empty {
<tr>
<td><em>No times</em></td>
</tr>
}
</tbody>
<div class="rule">
<table mat-table [dataSource]="rule | ruleTimes">
<ng-container matColumnDef="time">
<th mat-header-cell *matHeaderCellDef>Time</th>
<td mat-cell *matCellDef="let time">{{ time.time }}</td>
</ng-container>
<ng-container matColumnDef="duration">
<th mat-header-cell *matHeaderCellDef>Duration</th>
<td mat-cell *matCellDef="let time">{{ time.duration }}</td>
</ng-container>
<ng-container matColumnDef="multiplier">
<th mat-header-cell *matHeaderCellDef>Multiplier</th>
<td mat-cell *matCellDef="let time">{{ rule.mult }}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
</table>
</div>
} @empty {

View file

@ -1,18 +1,43 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { AlertRule } from '../../../talkgroup';
import {
Component,
Input,
Output,
EventEmitter,
Pipe,
PipeTransform,
} from '@angular/core';
import { AlertRule, AlertTime } from '../../../talkgroup';
import { MatTableModule } from '@angular/material/table';
@Pipe({
name: 'ruleTimes',
standalone: true,
pure: true,
})
export class AlertRulePipe implements PipeTransform {
transform(rule: AlertRule, args?: any): AlertTime[] {
return rule.getTimes();
}
}
@Component({
selector: 'alert-rule-builder',
imports: [],
imports: [MatTableModule, AlertRulePipe],
templateUrl: './alert-rule-builder.component.html',
styleUrl: './alert-rule-builder.component.scss',
})
export class AlertRuleBuilderComponent {
@Input() rules: AlertRule[] = [];
@Input() rules!: AlertRule[];
@Output() rulesChange: EventEmitter<AlertRule[]> = new EventEmitter<
AlertRule[]
>();
displayedColumns = ['time', 'duration', 'multiplier'];
ngOnInit() {
this.rules = <AlertRule[]>this.rules;
}
emit() {
this.rulesChange.emit(this.rules);
}

View file

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

View file

@ -7,6 +7,7 @@ import {
IconMap,
iconMapping,
TGID,
AlertRule,
} from '../../talkgroup';
import { COMMA, ENTER } from '@angular/cdk/keycodes';
import { TalkgroupService } from '../talkgroups.service';
@ -157,6 +158,10 @@ export class TalkgroupRecordComponent {
.getTalkgroup(Number(this.tgid.sys), Number(this.tgid.tg))
.pipe(
tap((tg) => {
console.log('tap run');
tg.alert_rules = tg.alert_rules
? tg.alert_rules.map((x) => Object.assign(new AlertRule(), x))
: [];
this.form.patchValue(tg);
this.form.controls['tagInput'].setValue('');
this.form.controls['tagsControl'].setValue(this.tg?.tags ?? []);

View file

@ -33,7 +33,10 @@ export class TalkgroupService {
private subscriptions = new Subscription();
constructor(private http: HttpClient) {
this.tgs$ = this.fetchAll.pipe(switchMap(() => this.getTalkgroups()));
this.tags$ = this.fetchAll.pipe(switchMap(() => this.getAllTags()));
this.tags$ = this.fetchAll.pipe(
switchMap(() => this.getAllTags()),
shareReplay(),
);
this.fillTgMap();
}
@ -52,11 +55,8 @@ export class TalkgroupService {
getTalkgroup(sys: number, tg: number): Observable<Talkgroup> {
const key = this.tgKey(sys, tg);
if (!this._getTalkgroup.get(key)) {
return this.tgs$.pipe(
switchMap((talkg) =>
talkg.filter((tgv) => tgv.tgid == tg && tgv.system_id == sys),
),
);
let rs = new ReplaySubject<Talkgroup>();
this._getTalkgroup.set(key, rs);
}
return this._getTalkgroup.get(key)!;
}

View file

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

View file

@ -245,6 +245,7 @@ func (a *Auth) routeAuth(w http.ResponseWriter, r *http.Request) {
Path: "/",
HttpOnly: true,
Secure: true,
MaxAge: 60 * 60 * 24 * 30, // one month
}
cookie.Domain = r.Host

View file

@ -30,7 +30,7 @@ INSERT INTO talkgroup_versions(time, created_by,
metadata,
tags,
alert,
alert_config,
alert_rules,
weight,
learned
) SELECT NOW(), $1,
@ -43,7 +43,7 @@ INSERT INTO talkgroup_versions(time, created_by,
tg.metadata,
tg.tags,
tg.alert,
tg.alert_config,
tg.alert_rules,
tg.weight,
tg.learned
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
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 (
$1,
$2,
@ -122,10 +122,10 @@ SET
metadata = COALESCE($7, tg.metadata),
tags = COALESCE($8, tg.tags),
alert = COALESCE($9, tg.alert),
alert_config = COALESCE($10, tg.alert_config),
alert_rules = COALESCE($10, tg.alert_rules),
weight = COALESCE($11, tg.weight),
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 {
@ -135,18 +135,18 @@ type UpsertTalkgroupBatchResults struct {
}
type UpsertTalkgroupParams struct {
SystemID int32 `json:"system_id"`
TGID int32 `json:"tgid"`
Name *string `json:"name"`
AlphaTag *string `json:"alpha_tag"`
TGGroup *string `json:"tg_group"`
Frequency *int32 `json:"frequency"`
Metadata jsontypes.Metadata `json:"metadata"`
Tags []string `json:"tags"`
Alert interface{} `json:"alert"`
AlertConfig rules.AlertRules `json:"alert_config"`
Weight pgtype.Numeric `json:"weight"`
Learned *bool `json:"learned"`
SystemID int32 `json:"system_id"`
TGID int32 `json:"tgid"`
Name *string `json:"name"`
AlphaTag *string `json:"alpha_tag"`
TGGroup *string `json:"tg_group"`
Frequency *int32 `json:"frequency"`
Metadata jsontypes.Metadata `json:"metadata"`
Tags []string `json:"tags"`
Alert interface{} `json:"alert"`
AlertRules rules.AlertRules `json:"alert_rules"`
Weight pgtype.Numeric `json:"weight"`
Learned *bool `json:"learned"`
}
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.Tags,
a.Alert,
a.AlertConfig,
a.AlertRules,
a.Weight,
a.Learned,
}
@ -194,7 +194,7 @@ func (b *UpsertTalkgroupBatchResults) QueryRow(f func(int, Talkgroup, error)) {
&i.Metadata,
&i.Tags,
&i.Alert,
&i.AlertConfig,
&i.AlertRules,
&i.Weight,
&i.Learned,
&i.Ignored,

View file

@ -180,6 +180,7 @@ FROM incidents_calls ic, LATERAL (
FROM swept_calls sc WHERE sc.id = ic.swept_call_id
) c
WHERE ic.incident_id = $1
ORDER BY ic.call_date ASC
`
type GetIncidentCallsRow struct {

View file

@ -107,40 +107,40 @@ type System struct {
}
type Talkgroup struct {
ID int `json:"id,omitempty"`
SystemID int32 `json:"system_id,omitempty"`
TGID int32 `json:"tgid,omitempty"`
Name *string `json:"name,omitempty"`
AlphaTag *string `json:"alpha_tag,omitempty"`
TGGroup *string `json:"tg_group,omitempty"`
Frequency *int32 `json:"frequency,omitempty"`
Metadata jsontypes.Metadata `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"`
Alert bool `json:"alert,omitempty"`
AlertConfig rules.AlertRules `json:"alert_config,omitempty"`
Weight float32 `json:"weight,omitempty"`
Learned bool `json:"learned,omitempty"`
Ignored bool `json:"ignored,omitempty"`
ID int `json:"id,omitempty"`
SystemID int32 `json:"system_id,omitempty"`
TGID int32 `json:"tgid,omitempty"`
Name *string `json:"name,omitempty"`
AlphaTag *string `json:"alpha_tag,omitempty"`
TGGroup *string `json:"tg_group,omitempty"`
Frequency *int32 `json:"frequency,omitempty"`
Metadata jsontypes.Metadata `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"`
Alert bool `json:"alert,omitempty"`
AlertRules rules.AlertRules `json:"alert_rules,omitempty"`
Weight float32 `json:"weight,omitempty"`
Learned bool `json:"learned,omitempty"`
Ignored bool `json:"ignored,omitempty"`
}
type TalkgroupVersion struct {
ID int `json:"id,omitempty"`
Time pgtype.Timestamptz `json:"time,omitempty"`
CreatedBy *int32 `json:"created_by,omitempty"`
Deleted *bool `json:"deleted,omitempty"`
SystemID *int32 `json:"system_id,omitempty"`
TGID *int32 `json:"tgid,omitempty"`
Name *string `json:"name,omitempty"`
AlphaTag *string `json:"alpha_tag,omitempty"`
TGGroup *string `json:"tg_group,omitempty"`
Frequency *int32 `json:"frequency,omitempty"`
Metadata []byte `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"`
Alert *bool `json:"alert,omitempty"`
AlertConfig []byte `json:"alert_config,omitempty"`
Weight *float32 `json:"weight,omitempty"`
Learned *bool `json:"learned,omitempty"`
Ignored *bool `json:"ignored,omitempty"`
ID int `json:"id,omitempty"`
Time pgtype.Timestamptz `json:"time,omitempty"`
CreatedBy *int32 `json:"created_by,omitempty"`
Deleted *bool `json:"deleted,omitempty"`
SystemID *int32 `json:"system_id,omitempty"`
TGID *int32 `json:"tgid,omitempty"`
Name *string `json:"name,omitempty"`
AlphaTag *string `json:"alpha_tag,omitempty"`
TGGroup *string `json:"tg_group,omitempty"`
Frequency *int32 `json:"frequency,omitempty"`
Metadata []byte `json:"metadata,omitempty"`
Tags []string `json:"tags,omitempty"`
Alert *bool `json:"alert,omitempty"`
AlertRules []byte `json:"alert_rules,omitempty"`
Weight *float32 `json:"weight,omitempty"`
Learned *bool `json:"learned,omitempty"`
Ignored *bool `json:"ignored,omitempty"`
}
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)
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
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);`
@ -82,7 +82,7 @@ func (q *Queries) GetTalkgroupsWithLearnedBySysTGID(ctx context.Context, ids TGT
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.AlertRules,
&i.Talkgroup.Weight,
&i.System.ID,
&i.System.Name,
@ -99,7 +99,7 @@ func (q *Queries) GetTalkgroupsWithLearnedBySysTGID(ctx context.Context, ids TGT
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 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;`
@ -124,7 +124,7 @@ func (q *Queries) GetTalkgroupsBySysTGID(ctx context.Context, ids TGTuples) ([]G
&i.Talkgroup.Metadata,
&i.Talkgroup.Tags,
&i.Talkgroup.Alert,
&i.Talkgroup.AlertConfig,
&i.Talkgroup.AlertRules,
&i.Talkgroup.Weight,
&i.Talkgroup.Learned,
&i.Talkgroup.Ignored,

View file

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

View file

@ -202,7 +202,7 @@ func (ia *incidentsAPI) getCallsM3U(w http.ResponseWriter, r *http.Request) {
return
}
var b bytes.Buffer
b := new(bytes.Buffer)
callUrl := common.PtrTo(*ia.baseURL)
@ -220,7 +220,7 @@ func (ia *incidentsAPI) getCallsM3U(w http.ResponseWriter, r *http.Request) {
callUrl.Path = "/api/call/" + c.ID.String()
fmt.Fprintf(w, "#EXTINF:%d,%s%s (%s)\n%s\n\n",
fmt.Fprintf(b, "#EXTINF:%d,%s%s (%s)\n%s\n\n",
c.Duration.Seconds(),
tg.StringTag(true),
from,

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 *= tg.AlertConfig.Apply(tm)
m *= tg.AlertRules.Apply(tm)
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,
tags TEXT[] NOT NULL DEFAULT '{}',
alert BOOLEAN NOT NULL DEFAULT 'true',
alert_config JSONB,
alert_rules JSONB,
weight REAL NOT NULL DEFAULT 1.0,
learned BOOLEAN NOT NULL DEFAULT FALSE,
ignored BOOLEAN NOT NULL DEFAULT FALSE,
@ -62,7 +62,7 @@ CREATE TABLE IF NOT EXISTS talkgroup_versions(
metadata JSONB,
tags TEXT[],
alert BOOLEAN,
alert_config JSONB,
alert_rules JSONB,
weight REAL,
learned BOOLEAN,
ignored BOOLEAN

View file

@ -141,7 +141,8 @@ FROM incidents_calls ic, LATERAL (
sc.transcript
FROM swept_calls sc WHERE sc.id = ic.swept_call_id
) c
WHERE ic.incident_id = @id;
WHERE ic.incident_id = @id
ORDER BY ic.call_date ASC;
-- name: GetIncident :one
SELECT

View file

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

View file

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