From f297458954200afba394be429acc6ec8339d0f19 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Mon, 17 May 2021 20:13:53 +0200 Subject: [PATCH] Report on virgin points and points to be acquired. Virgin points are those that have not been acquired (and processed) at least once. Points to be acquired are virgin points that do not have the `ntba` flag set. --- lib/www/server/lib/db/line/list.js | 51 +++++++++--------------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/lib/www/server/lib/db/line/list.js b/lib/www/server/lib/db/line/list.js index 0b59a26..16226c8 100644 --- a/lib/www/server/lib/db/line/list.js +++ b/lib/www/server/lib/db/line/list.js @@ -10,44 +10,23 @@ async function list (projectId, opts = {}) { const limit = Math.abs(Number(opts.itemsPerPage)) || null; const text = ` - WITH summary AS ( - SELECT DISTINCT - line, - CASE - WHEN pl.incr THEN - first_value(point) OVER w - ELSE - last_value(point) OVER w - END fsp, - CASE - WHEN pl.incr THEN - last_value(point) OVER w - ELSE - first_value(point) OVER w - END lsp, - count(point) OVER w num_points, - -- ST_MakeLine(first_value(geometry) OVER w, last_value(geometry) over w) geometry, - ST_Distance(first_value(pp.geometry) OVER w, last_value(pp.geometry) over w) length, - CASE - WHEN pl.incr THEN - ST_Azimuth(first_value(pp.geometry) OVER w, last_value(pp.geometry) over w)*180/pi() - ELSE - ST_Azimuth(last_value(pp.geometry) OVER w, first_value(pp.geometry) over w)*180/pi() - END azimuth - FROM preplot_points pp - INNER JOIN preplot_lines pl USING (line) - WHERE pp.class = 'V' - WINDOW w AS ( - PARTITION BY line - ORDER BY point ASC - ROWS BETWEEN - UNBOUNDED PRECEDING - AND UNBOUNDED FOLLOWING - ) + WITH counts AS ( + SELECT pls.*, COALESCE(ppc.virgin, 0) na, COALESCE(ppc.tba, 0) tba + FROM preplot_lines_summary pls + LEFT JOIN ( + SELECT line, COUNT(*) virgin, COUNT(NULLIF(ntba,true)) tba + FROM preplot_points_count pc + INNER JOIN preplot_points pp + USING (line, point) + WHERE pc.count = 0 + GROUP BY line + ) ppc + USING (line) ) - SELECT s.*, incr, remarks, pl.ntba, pl.meta - FROM summary s + SELECT s.*, pl.ntba, c.na, c.tba, pl.meta + FROM preplot_lines_summary s INNER JOIN preplot_lines pl ON pl.class = 'V' AND s.line = pl.line + LEFT JOIN counts c ON s.line = c.line ORDER BY ${sortKey} ${sortDir} OFFSET $1 LIMIT $2;