mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:07:08 +00:00
Use common naming convention both online and offline
This commit is contained in:
@@ -70,9 +70,9 @@ async function getNearestOfflinePreplot (candidates) {
|
|||||||
if ("latitude" in candidates[0] && "longitude" in candidates[0]) {
|
if ("latitude" in candidates[0] && "longitude" in candidates[0]) {
|
||||||
text = `
|
text = `
|
||||||
SELECT
|
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
|
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
|
ORDER BY distance ASC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`;
|
`;
|
||||||
@@ -80,9 +80,9 @@ async function getNearestOfflinePreplot (candidates) {
|
|||||||
} else if ("easting" in candidates[0] && "northing" in candidates[0]) {
|
} else if ("easting" in candidates[0] && "northing" in candidates[0]) {
|
||||||
text = `
|
text = `
|
||||||
SELECT
|
SELECT
|
||||||
'${c._schema}' AS _schema,
|
'${c.schema}' AS schema,
|
||||||
ST_Distance(ST_SetSRID(ST_MakePoint($1, $2), ST_SRID(geometry)), geometry) AS distance
|
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
|
ORDER BY distance ASC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
`;
|
`;
|
||||||
@@ -98,13 +98,13 @@ async function getNearestOfflinePreplot (candidates) {
|
|||||||
const results = [];
|
const results = [];
|
||||||
for (const qry of queries) {
|
for (const qry of queries) {
|
||||||
const res = await client.query(qry.text, qry.values);
|
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]);
|
results.push(res.rows[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.release();
|
client.release();
|
||||||
const _schema = results.sort( (a, b) => a.distance - b.distance).shift()?._schema;
|
const schema = results.sort( (a, b) => a.distance - b.distance).shift()?.schema;
|
||||||
return candidates.find(c => c._schema == _schema);
|
return candidates.find(c => c.schema == schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveOnline (dataset, opts = {}) {
|
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 candidates = configs.map(c => Object.assign({}, navData, {_schema: c.schema}));
|
||||||
const bestCandidate = await getNearestOfflinePreplot(candidates);
|
const bestCandidate = await getNearestOfflinePreplot(candidates);
|
||||||
if (bestCandidate) {
|
if (bestCandidate) {
|
||||||
navData.payload._schema = bestCandidate._schema;
|
navData.payload._schema = bestCandidate.schema;
|
||||||
last_tstamp = now;
|
last_tstamp = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user