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