Milimetric has submitted this change and it was merged.
Change subject: Fix date range for per-article
......................................................................
Fix date range for per-article
When YYYYMMDD format was used, it was not matching entries in cassandra
with YYYYMMDD00 values in the timestamp field. We just add a 00 in the
cases where this situation can occur.
Bug: T131641
Change-Id: Ic4d4f1340fb9ef20a49f3e8d8c3981929e98e3ed
---
M lib/aqsUtil.js
M sys/pageviews.js
M test/features/pageviews/pageviews.js
3 files changed, 31 insertions(+), 1 deletion(-)
Approvals:
Joal: Looks good to me, but someone else must approve
Milimetric: Verified; Looks good to me, approved
diff --git a/lib/aqsUtil.js b/lib/aqsUtil.js
index ae87e41..2fdadf7 100644
--- a/lib/aqsUtil.js
+++ b/lib/aqsUtil.js
@@ -79,6 +79,19 @@
}
};
+/**
+ * Generic validator of YYYYMMDDHH timestamps, with optional HH
+ *
+ * Options
+ * fakeHour: add a '00' when validating a YYYYMMDD timestamp
+ * zeroHour: actually change start and end to YYYYMMDD00
+ *
+ * Returns
+ * Nothing, but may change rp.start and rp.end
+ *
+ * Throws
+ * invalid date format exceptions
+ */
aqsUtil.validateStartAndEnd = function(rp, opts) {
opts = opts || {};
@@ -101,6 +114,11 @@
}
throwIfNeeded(errors);
+
+ if (opts.zeroHour) {
+ rp.start = rp.start.substring(0, 8) + '00';
+ rp.end = rp.end.substring(0, 8) + '00';
+ }
};
aqsUtil.validateYearMonthDay = function(rp) {
diff --git a/sys/pageviews.js b/sys/pageviews.js
index a7a53bc..990e135 100644
--- a/sys/pageviews.js
+++ b/sys/pageviews.js
@@ -137,7 +137,7 @@
// dates are passed in as YYYYMMDD but we need the HH to match the loaded
data
// which was originally planned at hourly resolution, so we pass "fakeHour"
- aqsUtil.validateStartAndEnd(rp, { fakeHour: true });
+ aqsUtil.validateStartAndEnd(rp, { fakeHour: true, zeroHour: true });
var dataRequest = hyper.get({
uri: tableURI(rp.domain, tables.articleFlat),
diff --git a/test/features/pageviews/pageviews.js
b/test/features/pageviews/pageviews.js
index 0bad0f5..5d40822 100644
--- a/test/features/pageviews/pageviews.js
+++ b/test/features/pageviews/pageviews.js
@@ -78,6 +78,18 @@
});
});
+ it('should return data when start = timestamp = end and YYYYMMDD is used',
function () {
+ return preq.get({
+ uri: server.config.aqsURL +
+ articleEndpoint
+ .replace('20150701', '20150702')
+ .replace('20150703', '20150702')
+ }).then(function(res) {
+ assert.deepEqual(res.body.items.length, 1);
+ assert.deepEqual(res.body.items[0].views, 1007);
+ });
+ });
+
// Test Project Endpoint
--
To view, visit https://gerrit.wikimedia.org/r/281982
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic4d4f1340fb9ef20a49f3e8d8c3981929e98e3ed
Gerrit-PatchSet: 1
Gerrit-Project: analytics/aqs
Gerrit-Branch: master
Gerrit-Owner: Milimetric <[email protected]>
Gerrit-Reviewer: Joal <[email protected]>
Gerrit-Reviewer: Milimetric <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits