Modify DB upgrade file 25 to use final_shots

This commit is contained in:
D. Berge
2022-05-15 13:19:01 +02:00
parent d5aac5e84d
commit bada6dc2e2

View File

@@ -51,7 +51,7 @@ BEGIN
WITH straddlers AS ( WITH straddlers AS (
-- Get sequence numbers straddling midnight UTC -- Get sequence numbers straddling midnight UTC
SELECT sequence SELECT sequence
FROM raw_shots FROM final_shots
GROUP BY sequence GROUP BY sequence
HAVING min(date(tstamp)) != max(date(tstamp)) HAVING min(date(tstamp)) != max(date(tstamp))
), ),
@@ -61,12 +61,12 @@ BEGIN
-- This will return the timestamps for: -- This will return the timestamps for:
-- FSP, LDSP, FDSP, LSP. -- FSP, LDSP, FDSP, LSP.
SELECT SELECT
rs.sequence, fs.sequence,
min(rs.tstamp) AS ts0, min(fs.tstamp) AS ts0,
max(rs.tstamp) AS ts1 max(fs.tstamp) AS ts1
FROM raw_shots rs INNER JOIN straddlers USING (sequence) FROM final_shots fs INNER JOIN straddlers USING (sequence)
GROUP BY rs.sequence, (date(rs.tstamp)) GROUP BY fs.sequence, (date(fs.tstamp))
ORDER BY rs.sequence, date(rs.tstamp) ORDER BY fs.sequence, date(fs.tstamp)
), ),
spts AS ( spts AS (
-- Filter out FSP, LSP from the above. -- Filter out FSP, LSP from the above.
@@ -81,21 +81,21 @@ BEGIN
ORDER BY sequence ORDER BY sequence
), evt AS ( ), evt AS (
SELECT SELECT
rs.tstamp, fs.tstamp,
rs.sequence, fs.sequence,
point, point,
'Last shotpoint of the day' remarks, 'Last shotpoint of the day' remarks,
'{LDSP}'::text[] labels '{LDSP}'::text[] labels
FROM raw_shots rs FROM final_shots fs
INNER JOIN spts ON rs.sequence = spts.sequence AND rs.tstamp = spts.ldsp INNER JOIN spts ON fs.sequence = spts.sequence AND fs.tstamp = spts.ldsp
UNION SELECT UNION SELECT
rs.tstamp, fs.tstamp,
rs.sequence, fs.sequence,
point, point,
'First shotpoint of the day' remarks, 'First shotpoint of the day' remarks,
'{FDSP}'::text[] labels '{FDSP}'::text[] labels
FROM raw_shots rs FROM final_shots fs
INNER JOIN spts ON rs.sequence = spts.sequence AND rs.tstamp = spts.fdsp INNER JOIN spts ON fs.sequence = spts.sequence AND fs.tstamp = spts.fdsp
ORDER BY tstamp ORDER BY tstamp
) )
SELECT * FROM evt; SELECT * FROM evt;
@@ -104,8 +104,10 @@ BEGIN
CREATE OR REPLACE PROCEDURE log_midnight_shots (dt0 date, dt1 date) CREATE OR REPLACE PROCEDURE log_midnight_shots (dt0 date, dt1 date)
LANGUAGE sql LANGUAGE sql
AS $$ AS $$
INSERT INTO event_log (sequence, point, remarks, labels) INSERT INTO event_log (sequence, point, remarks, labels, meta)
SELECT sequence, point, remarks, labels SELECT
sequence, point, remarks, labels,
'{"auto": true, "insertedBy": "log_midnight_shots"}'::jsonb
FROM midnight_shots ms FROM midnight_shots ms
WHERE WHERE
(dt0 IS NULL OR ms.tstamp >= dt0) AND (dt0 IS NULL OR ms.tstamp >= dt0) AND