Skip to content

Commit

Permalink
Fix endtime only geodataset time queries
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed Jan 16, 2025
1 parent cbd30e3 commit 0aa1020
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
51 changes: 29 additions & 22 deletions API/Backend/Geodatasets/routes/geodatasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ function get(reqtype, req, res, next) {
)}, ${Utils.forceAlphaNumUnder(parseFloat(maxy))}, 4326), geom)`;
hasBounds = true;
}
let startProp = "start_time";
let start_time = "";
let endProp = "end_time";
let end_time = "";
if (req.query?.endtime != null) {
const format = req.query?.format || "YYYY-MM-DDTHH:MI:SSZ";
Expand All @@ -86,10 +88,6 @@ function get(reqtype, req, res, next) {
else t += `AND `;

if (
req.query?.startProp == null ||
req.query?.startProp.indexOf(`'`) != -1 ||
req.query?.endProp == null ||
req.query?.endProp.indexOf(`'`) != -1 ||
req.query?.starttime == null ||
req.query?.starttime.indexOf(`'`) != -1 ||
req.query?.endtime == null ||
Expand All @@ -98,37 +96,46 @@ function get(reqtype, req, res, next) {
) {
res.send({
status: "failure",
message: "Missing inner or malformed 'time' parameters.",
message: "Missing inner or malformed time parameters.",
});
return;
}

start_time = new Date(req.query.starttime).getTime();
start_time = new Date(
req.query.starttime || "1970-01-01T00:00:00Z"
).getTime();
end_time = new Date(req.query.endtime).getTime();

const startProp = Utils.forceAlphaNumUnder(req.query.startProp);
const endProp = Utils.forceAlphaNumUnder(req.query.endProp);
startProp = Utils.forceAlphaNumUnder(
req.query.startProp || startProp
);
endProp = Utils.forceAlphaNumUnder(req.query.endProp || endProp);
// prettier-ignore
t += [
`(`,
`${startProp} IS NOT NULL AND ${endProp} IS NOT NULL AND`,
` ${startProp} >= ${start_time}`,
` AND ${endProp} <= ${end_time}`,
`)`,
` OR `,
`(`,
`${startProp} IS NULL AND ${endProp} IS NOT NULL AND`,
` ${endProp} >= ${start_time}`,
` AND ${endProp} >= ${end_time}`,
`)`
].join('')
`(`,
`${startProp} IS NOT NULL AND ${endProp} IS NOT NULL AND`,
` ${startProp} >= ${start_time}`,
` AND ${endProp} <= ${end_time}`,
`)`,
` OR `,
`(`,
`${startProp} IS NULL AND ${endProp} IS NOT NULL AND`,
` ${endProp} >= ${start_time}`,
` AND ${endProp} <= ${end_time}`,
`)`
].join('')
q += t;
}
q += `;`;

console.log(q);
sequelize
.query(q, {
replacements: {},
replacements: {
startProp: startProp,
start_time: start_time,
endProp: endProp,
end_time: end_time,
},
})
.then(([results]) => {
let geojson = { type: "FeatureCollection", features: [] };
Expand Down
17 changes: 13 additions & 4 deletions src/essence/Basics/Layers_/LayerCapturer.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ export const captureVector = (layerObj, options, cb, dynamicCb) => {
layerData?.variables
?.dynamicExtentMoveThreshold ==
null ||
layerData?.variables
?.dynamicExtentMoveThreshold ===
'' ||
layerData._ignoreDynamicExtentMoveThreshold ===
true ||
F_.lngLatDistBetween(
Expand Down Expand Up @@ -358,12 +361,18 @@ export const captureVector = (layerObj, options, cb, dynamicCb) => {
} else {
switch (urlSplit[0]) {
case 'geodatasets':
const body = {
layer: urlSplitRaw[1],
type: 'geojson',
}
if (layerData.time?.enabled === true) {
body.starttime = layerData.time.start
body.endtime = layerData.time.end
}

calls.api(
'geodatasets_get',
{
layer: urlSplitRaw[1],
type: 'geojson',
},
body,
(data) => {
cb(data)
},
Expand Down

0 comments on commit 0aa1020

Please sign in to comment.