From 15c7bca6e018dfc62619b215f0b718732b3724d3 Mon Sep 17 00:00:00 2001 From: Tomas Date: Mon, 22 Jan 2018 16:38:00 -0500 Subject: [PATCH] fixed time series endpoints --- CHANGELOG.md | 1 + src/api/routes/floods/timeseries/model.js | 4 ++-- src/api/routes/reports/timeseries/model.js | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6625c19..ce8f65f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,3 +43,4 @@ API Server for CogniCity * Updated documentation of Swagger files * Updated Babel package * Remove username field from GET /cards/:id +* Fix bug with time series endpoints diff --git a/src/api/routes/floods/timeseries/model.js b/src/api/routes/floods/timeseries/model.js index 7a981c6..a6e9e25 100644 --- a/src/api/routes/floods/timeseries/model.js +++ b/src/api/routes/floods/timeseries/model.js @@ -19,8 +19,8 @@ export default (config, db, logger) => ({ // Setup query let query = `SELECT ts, count(local_area) FROM (SELECT (cognicity.rem_get_flood(ts)).local_area, ts - FROM generate_series($1::timestamp with time zone, - $2::timestamp with time zone,'1 hour') + FROM generate_series(date_trunc('hour', $1::timestamp with time zone), + date_trunc('hour', $2::timestamp with time zone),'1 hour') as series(ts)) output GROUP BY ts ORDER BY ts`; diff --git a/src/api/routes/reports/timeseries/model.js b/src/api/routes/reports/timeseries/model.js index 72fffdd..fc3f941 100644 --- a/src/api/routes/reports/timeseries/model.js +++ b/src/api/routes/reports/timeseries/model.js @@ -18,8 +18,8 @@ export default (config, db, logger) => ({ count: (start, end, city) => new Promise((resolve, reject) => { // Setup query let query = `SELECT ts, count(r.pkey) - FROM generate_series($1::timestamp with time zone, - $2::timestamp with time zone, '1 hour') ts + FROM generate_series(date_trunc('hour', $1::timestamp with time zone), + date_trunc('hour', $2::timestamp with time zone), '1 hour') ts LEFT JOIN cognicity.all_reports r ON date_trunc('hour', r.created_at) = ts AND ($3 IS NULL OR tags->>'instance_region_code'=$3)