From 91e9b2ed8ece828f9c349187c57d7c626530136f Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Tue, 7 Jan 2025 20:00:31 -0500 Subject: [PATCH 1/3] slow version --- pkg/database/calls.sql.go | 29 ++++++++++++++--------------- sql/postgres/queries/calls.sql | 9 +++++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/pkg/database/calls.sql.go b/pkg/database/calls.sql.go index a58588f..3ea749f 100644 --- a/pkg/database/calls.sql.go +++ b/pkg/database/calls.sql.go @@ -255,13 +255,13 @@ SELECT c.id, c.call_date, c.duration, -tgs.system_id, -tgs.tgid, -sys.name system_name, -tgs.name tg_name +c.system, +c.talkgroup, +COUNT(ic.incident_id) incidents FROM calls c JOIN talkgroups tgs ON c.talkgroup = tgs.tgid AND c.system = tgs.system_id JOIN systems sys ON sys.id = tgs.system_id +LEFT JOIN incidents_calls ic ON c.id = ic.calls_tbl_id AND c.call_date = ic.call_date WHERE CASE WHEN $1::TIMESTAMPTZ IS NOT NULL THEN c.call_date >= $1 ELSE TRUE END AND @@ -279,6 +279,7 @@ CASE WHEN $4::TEXT[] IS NOT NULL THEN (CASE WHEN $6::NUMERIC IS NOT NULL THEN ( c.duration > $6 ) ELSE TRUE END) +GROUP BY c.id, c.call_date ORDER BY CASE WHEN $7::TEXT = 'asc' THEN c.call_date END ASC, CASE WHEN $7 = 'desc' THEN c.call_date END DESC @@ -299,13 +300,12 @@ type ListCallsPParams struct { } type ListCallsPRow struct { - ID uuid.UUID `json:"id"` - CallDate pgtype.Timestamptz `json:"call_date"` - Duration *int32 `json:"duration"` - SystemID int32 `json:"system_id"` - TGID int32 `json:"tgid"` - SystemName string `json:"system_name"` - TGName *string `json:"tg_name"` + ID uuid.UUID `json:"id"` + CallDate pgtype.Timestamptz `json:"call_date"` + Duration *int32 `json:"duration"` + System int `json:"system"` + Talkgroup int `json:"talkgroup"` + Incidents int64 `json:"incidents"` } func (q *Queries) ListCallsP(ctx context.Context, arg ListCallsPParams) ([]ListCallsPRow, error) { @@ -331,10 +331,9 @@ func (q *Queries) ListCallsP(ctx context.Context, arg ListCallsPParams) ([]ListC &i.ID, &i.CallDate, &i.Duration, - &i.SystemID, - &i.TGID, - &i.SystemName, - &i.TGName, + &i.System, + &i.Talkgroup, + &i.Incidents, ); err != nil { return nil, err } diff --git a/sql/postgres/queries/calls.sql b/sql/postgres/queries/calls.sql index 353d61c..edc7b76 100644 --- a/sql/postgres/queries/calls.sql +++ b/sql/postgres/queries/calls.sql @@ -101,13 +101,13 @@ SELECT c.id, c.call_date, c.duration, -tgs.system_id, -tgs.tgid, -sys.name system_name, -tgs.name tg_name +c.system, +c.talkgroup, +COUNT(ic.incident_id) incidents FROM calls c JOIN talkgroups tgs ON c.talkgroup = tgs.tgid AND c.system = tgs.system_id JOIN systems sys ON sys.id = tgs.system_id +LEFT JOIN incidents_calls ic ON c.id = ic.calls_tbl_id AND c.call_date = ic.call_date WHERE CASE WHEN sqlc.narg('start')::TIMESTAMPTZ IS NOT NULL THEN c.call_date >= @start ELSE TRUE END AND @@ -125,6 +125,7 @@ CASE WHEN sqlc.narg('tags_not')::TEXT[] IS NOT NULL THEN (CASE WHEN sqlc.narg('longer_than')::NUMERIC IS NOT NULL THEN ( c.duration > @longer_than ) ELSE TRUE END) +GROUP BY c.id, c.call_date ORDER BY CASE WHEN @direction::TEXT = 'asc' THEN c.call_date END ASC, CASE WHEN @direction = 'desc' THEN c.call_date END DESC From db5e6e7ad845ecee84db49c935c25b5ed1008001 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Tue, 7 Jan 2025 20:47:59 -0500 Subject: [PATCH 2/3] Incident highlight backend --- pkg/database/calls.sql.go | 12 ++++++------ sql/postgres/queries/calls.sql | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/database/calls.sql.go b/pkg/database/calls.sql.go index 3ea749f..22da55b 100644 --- a/pkg/database/calls.sql.go +++ b/pkg/database/calls.sql.go @@ -255,8 +255,8 @@ SELECT c.id, c.call_date, c.duration, -c.system, -c.talkgroup, +c.system system_id, +c.talkgroup tgid, COUNT(ic.incident_id) incidents FROM calls c JOIN talkgroups tgs ON c.talkgroup = tgs.tgid AND c.system = tgs.system_id @@ -303,8 +303,8 @@ type ListCallsPRow struct { ID uuid.UUID `json:"id"` CallDate pgtype.Timestamptz `json:"call_date"` Duration *int32 `json:"duration"` - System int `json:"system"` - Talkgroup int `json:"talkgroup"` + SystemID int `json:"system_id"` + TGID int `json:"tgid"` Incidents int64 `json:"incidents"` } @@ -331,8 +331,8 @@ func (q *Queries) ListCallsP(ctx context.Context, arg ListCallsPParams) ([]ListC &i.ID, &i.CallDate, &i.Duration, - &i.System, - &i.Talkgroup, + &i.SystemID, + &i.TGID, &i.Incidents, ); err != nil { return nil, err diff --git a/sql/postgres/queries/calls.sql b/sql/postgres/queries/calls.sql index edc7b76..998566a 100644 --- a/sql/postgres/queries/calls.sql +++ b/sql/postgres/queries/calls.sql @@ -101,8 +101,8 @@ SELECT c.id, c.call_date, c.duration, -c.system, -c.talkgroup, +c.system system_id, +c.talkgroup tgid, COUNT(ic.incident_id) incidents FROM calls c JOIN talkgroups tgs ON c.talkgroup = tgs.tgid AND c.system = tgs.system_id From b68ba4872ef8bd764acf04f0046521947bd59ff0 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Tue, 7 Jan 2025 20:48:45 -0500 Subject: [PATCH 3/3] Highlight incident UI --- client/stillbox/src/app/calls.ts | 3 +-- client/stillbox/src/app/calls/calls.component.html | 2 +- client/stillbox/src/app/calls/calls.component.scss | 4 ++++ client/stillbox/src/app/calls/calls.component.ts | 5 ++++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/stillbox/src/app/calls.ts b/client/stillbox/src/app/calls.ts index 1da3392..ccd51ee 100644 --- a/client/stillbox/src/app/calls.ts +++ b/client/stillbox/src/app/calls.ts @@ -4,6 +4,5 @@ export interface CallRecord { duration: number; system_id: number; tgid: number; - system_name: string; - tg_name: string; + incidents: number; // in incident } diff --git a/client/stillbox/src/app/calls/calls.component.html b/client/stillbox/src/app/calls/calls.component.html index 100cc73..3cbc7a4 100644 --- a/client/stillbox/src/app/calls/calls.component.html +++ b/client/stillbox/src/app/calls/calls.component.html @@ -169,7 +169,7 @@ - +
diff --git a/client/stillbox/src/app/calls/calls.component.scss b/client/stillbox/src/app/calls/calls.component.scss index d46d981..01e9628 100644 --- a/client/stillbox/src/app/calls/calls.component.scss +++ b/client/stillbox/src/app/calls/calls.component.scss @@ -96,3 +96,7 @@ form { .tagSelect { flex: 1 1 250px; } + +.in-incident { + background-color: rgb(59, 0, 59); +} diff --git a/client/stillbox/src/app/calls/calls.component.ts b/client/stillbox/src/app/calls/calls.component.ts index f6432c1..5ff0ae1 100644 --- a/client/stillbox/src/app/calls/calls.component.ts +++ b/client/stillbox/src/app/calls/calls.component.ts @@ -391,7 +391,10 @@ export class CallsComponent { } this.incSvc .addRemoveCalls(res, { - add: this.selection.selected.map((s) => s.id), + add: this.selection.selected.map((s, i, a) => { + s.incidents++; + return s.id; + }), }) .subscribe({ next: () => {