Allow sequences to be filtered.

Sequences can be filtered by:
* sequence number;
* line number;
* start / end date (of raw acquisition);
* remarks (raw or final).
This commit is contained in:
D. Berge
2020-08-25 12:59:40 +02:00
parent f486b4835e
commit 00f1ea20da
7 changed files with 80 additions and 30 deletions

View File

@@ -1,30 +0,0 @@
const { setSurvey } = require('./connection');
async function list (projectId, opts = {}) {
const client = await setSurvey(projectId);
const sortFields = [
"sequence", "line", "length", "azimuth", "fsp", "lsp",
"ts0", "ts1", "duration", "num_points", "missing_shots", "remarks"
];
const sortKey = opts.sortBy && sortFields.includes(opts.sortBy) && opts.sortBy || "line";
const sortDir = opts.sortDesc == "true" ? "DESC" : "ASC";
const offset = Math.abs((opts.page-1)*opts.itemsPerPage) || 0;
const limit = Math.abs(Number(opts.itemsPerPage)) || null;
const text = `
SELECT *
FROM final_lines_summary
ORDER BY ${sortKey} ${sortDir}
OFFSET $1
LIMIT $2;
`;
const res = await client.query(text, [offset, limit]);
client.release();
return res.rows;
}
module.exports = {
list
};

View File

View File

View File

@@ -0,0 +1,8 @@
module.exports = {
list: require('./list'),
get: require('./get'),
post: require('./post'),
put: require('./put'),
delete: require('./delete')
}

View File

@@ -0,0 +1,72 @@
const { setSurvey } = require('../connection');
async function list (projectId, opts = {}) {
const client = await setSurvey(projectId);
const sortFields = [
"sequence", "line", "length", "azimuth", "fsp", "lsp",
"ts0", "ts1", "duration", "num_points", "missing_shots", "remarks"
];
const sortKey = opts.sortBy && sortFields.includes(opts.sortBy) && opts.sortBy || "line";
const sortDir = opts.sortDesc == "true" ? "DESC" : "ASC";
const offset = Math.abs((opts.page-1)*opts.itemsPerPage) || 0;
const limit = Math.abs(Number(opts.itemsPerPage)) || null;
const filter = opts.filter;
const noFilter = !("filter" in opts) || opts.filter === null || !String(opts.filter).trim().length;
const filterText = noFilter
? "$3 = $3"
: `
$3 = rls.sequence::text
OR rls.line::text ~ $3
OR position($3 in date(rls.ts0)::text) > 0
OR position($3 in date(rls.ts1)::text) > 0
OR rls.remarks ~* $3
OR fls.remarks ~* $3
OR (($3 ILIKE 'process%' OR $3 ILIKE 'final%') AND fls.sequence IS NOT NULL)
OR ($3 ILIKE 'raw' AND fls.sequence IS NULL)
`;
const text = `
SELECT
rls.sequence,
rls.line,
rls.fsp,
rls.lsp,
fls.fsp fsp_final,
fls.lsp lsp_final,
rls.ts0,
rls.ts1,
fls.ts0 ts0_final,
fls.ts1 ts1_final,
rls.duration,
fls.duration duration_final,
rls.num_preplots,
coalesce(fls.num_points, rls.num_points) num_points,
coalesce(fls.missing_shots, rls.missing_shots) missing_shots,
coalesce(fls.length, rls.length) length,
coalesce(fls.azimuth, rls.azimuth) azimuth,
rls.remarks,
fls.remarks remarks_final,
CASE
WHEN fls.sequence IS NULL
THEN 'raw'
ELSE 'final'
END status
FROM raw_lines_summary rls
LEFT JOIN final_lines_summary fls
USING (sequence)
WHERE
${filterText}
ORDER BY ${sortKey} ${sortDir}
OFFSET $1
LIMIT $2;
`;
const res = await client.query(text, [offset, limit, filter]);
client.release();
return res.rows;
}
module.exports = list;

View File

View File