Use common naming convention both online and offline

This commit is contained in:
D. Berge
2023-09-29 16:11:44 +02:00
parent 4d3fddc051
commit 99ac082f00

View File

@@ -70,9 +70,9 @@ async function getNearestOfflinePreplot (candidates) {
if ("latitude" in candidates[0] && "longitude" in candidates[0]) {
text = `
SELECT
'${c._schema}' AS _schema,
'${c.schema}' AS schema,
ST_Distance(ST_Transform(ST_SetSRID(ST_MakePoint($1, $2), 4326), ST_SRID(geometry)), geometry) AS distance
FROM ${c._schema}.preplot_points
FROM ${c.schema}.preplot_points
ORDER BY distance ASC
LIMIT 1;
`;
@@ -80,9 +80,9 @@ async function getNearestOfflinePreplot (candidates) {
} else if ("easting" in candidates[0] && "northing" in candidates[0]) {
text = `
SELECT
'${c._schema}' AS _schema,
'${c.schema}' AS schema,
ST_Distance(ST_SetSRID(ST_MakePoint($1, $2), ST_SRID(geometry)), geometry) AS distance
FROM ${c._schema}.preplot_points
FROM ${c.schema}.preplot_points
ORDER BY distance ASC
LIMIT 1;
`;
@@ -98,13 +98,13 @@ async function getNearestOfflinePreplot (candidates) {
const results = [];
for (const qry of queries) {
const res = await client.query(qry.text, qry.values);
if (res.rows[0] && res.rows[0]._schema) {
if (res.rows[0] && res.rows[0].schema) {
results.push(res.rows[0]);
}
}
client.release();
const _schema = results.sort( (a, b) => a.distance - b.distance).shift()?._schema;
return candidates.find(c => c._schema == _schema);
const schema = results.sort( (a, b) => a.distance - b.distance).shift()?.schema;
return candidates.find(c => c.schema == schema);
}
async function saveOnline (dataset, opts = {}) {
@@ -292,7 +292,7 @@ async function save (navData, opts = {}) {
const candidates = configs.map(c => Object.assign({}, navData, {_schema: c.schema}));
const bestCandidate = await getNearestOfflinePreplot(candidates);
if (bestCandidate) {
navData.payload._schema = bestCandidate._schema;
navData.payload._schema = bestCandidate.schema;
last_tstamp = now;
}
}