Compare commits

...

2 commits

5 changed files with 16 additions and 13 deletions

View file

@ -36,7 +36,8 @@ func (a *Alert) ToAddAlertParams() database.AddAlertParams {
return database.AddAlertParams{
ID: a.ID,
Time: pgtype.Timestamptz{Time: a.Timestamp, Valid: true},
PackedTg: a.Score.ID.Pack(),
SystemID: int(a.Score.ID.System),
Tgid: int(a.Score.ID.Talkgroup),
Weight: &a.Weight,
Score: &f32score,
OrigScore: origScore,

View file

@ -13,7 +13,7 @@ import (
)
const addAlert = `-- name: AddAlert :exec
INSERT INTO alerts (id, time, talkgroup, weight, score, orig_score, notified, metadata)
INSERT INTO alerts (id, time, tgid, system_id, weight, score, orig_score, notified, metadata)
VALUES
(
$1,
@ -23,14 +23,16 @@ VALUES
$5,
$6,
$7,
$8
$8,
$9
)
`
type AddAlertParams struct {
ID uuid.UUID `json:"id"`
Time pgtype.Timestamptz `json:"time"`
PackedTg int64 `json:"packed_tg"`
Tgid int `json:"tgid"`
SystemID int `json:"system_id"`
Weight *float32 `json:"weight"`
Score *float32 `json:"score"`
OrigScore *float32 `json:"orig_score"`
@ -42,7 +44,8 @@ func (q *Queries) AddAlert(ctx context.Context, arg AddAlertParams) error {
_, err := q.db.Exec(ctx, addAlert,
arg.ID,
arg.Time,
arg.PackedTg,
arg.Tgid,
arg.SystemID,
arg.Weight,
arg.Score,
arg.OrigScore,

View file

@ -15,9 +15,8 @@ import (
type Alert struct {
ID uuid.UUID `json:"id"`
Time pgtype.Timestamptz `json:"time"`
Talkgroup int64 `json:"talkgroup"`
SystemID int32 `json:"system_id"`
Tgid int32 `json:"tgid"`
Tgid int `json:"tgid"`
SystemID int `json:"system_id"`
Weight *float32 `json:"weight"`
Score *float32 `json:"score"`
OrigScore *float32 `json:"orig_score"`

View file

@ -74,9 +74,8 @@ CREATE TABLE IF NOT EXISTS talkgroups_learned(
CREATE TABLE IF NOT EXISTS alerts(
id UUID PRIMARY KEY,
time TIMESTAMPTZ NOT NULL,
talkgroup INT8 REFERENCES talkgroups(id) NOT NULL,
system_id INT4 REFERENCES systems(id) NOT NULL GENERATED ALWAYS AS (talkgroup >> 32) STORED,
tgid INT4 NOT NULL GENERATED ALWAYS AS (talkgroup & x'ffffffff'::BIGINT) STORED,
tgid INTEGER NOT NULL,
system_id INTEGER REFERENCES systems(id) NOT NULL,
weight REAL,
score REAL,
orig_score REAL,

View file

@ -41,12 +41,13 @@ source
UPDATE calls SET transcript = $2 WHERE id = $1;
-- name: AddAlert :exec
INSERT INTO alerts (id, time, talkgroup, weight, score, orig_score, notified, metadata)
INSERT INTO alerts (id, time, tgid, system_id, weight, score, orig_score, notified, metadata)
VALUES
(
sqlc.arg(id),
sqlc.arg(time),
sqlc.arg(packed_tg),
sqlc.arg(tgid),
sqlc.arg(system_id),
sqlc.arg(weight),
sqlc.arg(score),
sqlc.arg(orig_score),