Fdans has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/398306 )
Change subject: Replaces hardcoded URL with dynamic date values
......................................................................
Replaces hardcoded URL with dynamic date values
For now it disables the time range selector on top metrics, pending
the addition to the detail page of a month/year picker.
Bug: T182859
Change-Id: I5ec7db40147c705ecc028ffaac644fa525457170
---
M src/apis/aqs.js
M src/components/dashboard/MetricWidget.vue
M src/components/detail/Detail.vue
M src/components/detail/GraphPanel.vue
M src/config/index.js
M src/config/metrics/content.js
M src/config/metrics/contributing.js
M src/config/metrics/metricSchema.js
M src/config/metrics/reading.js
M src/utils.js
10 files changed, 56 insertions(+), 8 deletions(-)
Approvals:
jenkins-bot: Verified
Fdans: Looks good to me, approved
diff --git a/src/apis/aqs.js b/src/apis/aqs.js
index a7261ff..50ec152 100644
--- a/src/apis/aqs.js
+++ b/src/apis/aqs.js
@@ -50,6 +50,7 @@
.map(p => Object.assign(p, commonParameters))
.map(p => {
let url = apiConfig.endpoint;
+
url.match(/{{.*?}}/g)
.forEach((k) => {
const key = _.trim(k, '{}');
@@ -69,7 +70,6 @@
});
});
});
- const metricData = config.metricData(commonParameters.metric);
return Promise.all(promises).then(data => {
let validData = _.filter(data, d => !d.hasOwnProperty('error'));
let formattedData = _.flatten(validData.map(d => d.items));
@@ -79,7 +79,7 @@
if (formattedData[0].results) {
formattedData = this.transformResults(formattedData);
}
- if (metricData.type === 'list') {
+ if (commonParameters.structure === 'top') {
formattedData = this.formatTops(formattedData);
}
return new DimensionalData(formattedData);
@@ -126,5 +126,12 @@
}, []);
}
}
+/*
+
+AQS only has data up to the previous month to the current, so when requesting
+the last data available we should check that we're not trying to get
+the current month (or later).
+
+*/
export default AQS;
diff --git a/src/components/dashboard/MetricWidget.vue
b/src/components/dashboard/MetricWidget.vue
index 4437531..da0cf09 100644
--- a/src/components/dashboard/MetricWidget.vue
+++ b/src/components/dashboard/MetricWidget.vue
@@ -76,6 +76,7 @@
import AQS from '../../apis/aqs';
import config from '../../config';
+import utils from '../../utils';
import GraphModel from '../../models/GraphModel';
import RouterLink from '../RouterLink';
@@ -229,10 +230,15 @@
{
start: params.range[0],
end: params.range[1],
- granularity: params.granularity
+ granularity: params.granularity,
+ structure: params.metricConfig.structure,
}
);
+ if (params.metricConfig.structure === 'top') {
+ Object.assign(commonParameters,
utils.getLastFullMonth(commonParameters.end));
+ }
+
let dataPromise = this.aqsApi.getData(uniqueParameters,
commonParameters);
this.overlayMessage = StatusOverlay.LOADING;
diff --git a/src/components/detail/Detail.vue b/src/components/detail/Detail.vue
index c52f858..7959519 100644
--- a/src/components/detail/Detail.vue
+++ b/src/components/detail/Detail.vue
@@ -29,6 +29,7 @@
import TimeRangeSelector from '../TimeRangeSelector';
import config from '../../config';
+import utils from '../../utils';
import GraphModel from '../../models/GraphModel';
import AQS from '../../apis/aqs';
@@ -148,10 +149,15 @@
{
start: params.range[0],
end: params.range[1],
- granularity: params.granularity
+ granularity: params.granularity,
+ structure: params.metricConfig.structure,
}
);
+ if (params.metricConfig.structure === 'top') {
+ Object.assign(commonParameters,
utils.getLastFullMonth(commonParameters.end));
+ }
+
if (params.breakdown && !params.breakdown.total) {
let breakdownKeys = params.breakdown.values.filter(bv =>
bv.on).map(bv => bv.key);
diff --git a/src/components/detail/GraphPanel.vue
b/src/components/detail/GraphPanel.vue
index a90a810..520077e 100644
--- a/src/components/detail/GraphPanel.vue
+++ b/src/components/detail/GraphPanel.vue
@@ -54,7 +54,7 @@
<p>{{graphModel.config.description}}. <a class='metric link'
:href="graphModel.config.info_url" target="_blank">More info about this
metric.</a></p>
</div>
</div>
- <div class="ui center aligned subdued basic segment">
+ <div v-if="!['list', 'map'].includes(graphModel.config.type)"
class="ui center aligned subdued basic segment">
<time-range-selector
v-on:changeTimeRange='changeTimeRange'></time-range-selector>
</div>
<status-overlay v-if="overlayMessage"
:overlayMessage="overlayMessage"/>
diff --git a/src/config/index.js b/src/config/index.js
index df55ea3..13eab16 100644
--- a/src/config/index.js
+++ b/src/config/index.js
@@ -148,7 +148,7 @@
},
'top-viewed-articles': {
- endpoint: AQS_HOST +
'/pageviews/top/{{project}}/{{access}}/2015/10/all-days'
+ endpoint: AQS_HOST +
'/pageviews/top/{{project}}/{{access}}/{{year}}/{{month}}/all-days'
},
'new-pages': {
diff --git a/src/config/metrics/content.js b/src/config/metrics/content.js
index 686a187..b4ec096 100644
--- a/src/config/metrics/content.js
+++ b/src/config/metrics/content.js
@@ -15,6 +15,7 @@
}
},
type: 'bars',
+ structure: 'timeseries',
area: 'content',
value: 'abs_bytes_diff',
unit: 'bytes',
@@ -55,6 +56,7 @@
}
},
type: 'lines',
+ structure: 'timeseries',
area: 'content',
value: 'edited_pages',
global: false,
@@ -102,6 +104,7 @@
}
},
type: 'bars',
+ structure: 'timeseries',
area: 'content',
unit: 'bytes',
value: 'net_bytes_diff',
diff --git a/src/config/metrics/contributing.js
b/src/config/metrics/contributing.js
index 8476969..7308dea 100644
--- a/src/config/metrics/contributing.js
+++ b/src/config/metrics/contributing.js
@@ -17,6 +17,7 @@
}
},
type: 'lines',
+ structure: 'timeseries',
area: 'contributing',
value: 'editors',
global: false,
@@ -64,6 +65,7 @@
}
},
type: 'lines',
+ structure: 'timeseries',
area: 'contributing',
value: 'edits',
global: true,
@@ -103,6 +105,7 @@
}
},
type: 'bars',
+ structure: 'timeseries',
area: 'contributing',
value: 'new_pages',
global: true,
@@ -139,6 +142,7 @@
}
},
type: 'bars',
+ structure: 'timeseries',
area: 'contributing',
value: 'new_registered_users',
global: true,
diff --git a/src/config/metrics/metricSchema.js
b/src/config/metrics/metricSchema.js
index d849fc4..a2cfa8a 100644
--- a/src/config/metrics/metricSchema.js
+++ b/src/config/metrics/metricSchema.js
@@ -32,6 +32,11 @@
required: true,
possibleValues: ['bars', 'lines', 'list']
},
+ structure: {
+ type: 'string',
+ required: true,
+ possibleValues: ['top', 'timeseries']
+ },
area: {
type: 'string',
required: true,
diff --git a/src/config/metrics/reading.js b/src/config/metrics/reading.js
index 48de7f0..030fbb9 100644
--- a/src/config/metrics/reading.js
+++ b/src/config/metrics/reading.js
@@ -6,6 +6,7 @@
question: 'What are the most viewed articles?',
info_url: 'https://meta.wikimedia.org/wiki/Research:Page_view',
type: 'list',
+ structure: 'top',
defaults: {
unique: {
project: ['all-projects'],
@@ -39,6 +40,7 @@
}
},
type: 'lines',
+ structure: 'timeseries',
area: 'reading',
value: 'views',
global: true,
@@ -59,6 +61,7 @@
question: 'How many unique devices access content?',
info_url: 'https://meta.wikimedia.org/wiki/Research:Unique_Devices',
type: 'lines',
+ structure: 'timeseries',
defaults: {
unique: {
project: ['all-projects'],
diff --git a/src/utils.js b/src/utils.js
index 7a54cdc..fb8e1dc 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -14,13 +14,27 @@
}, [{}]);
};
-const formatSi = format.format(".2s");
-
function cloneDeep (c) {
return JSON.parse(JSON.stringify(c));
+}
+
+function getLastFullMonth (yyyymmddDate) {
+ if (yyyymmddDate.length < 6) { return { year: 2017, month: 11 }; }
+
+ let year = parseInt(yyyymmddDate.slice(0, 4), 10);
+ let month = parseInt(yyyymmddDate.slice(4, 6), 10);
+
+ const lastFullDate = new Date(year, month - 1, -1);
+ const lastMonth = '' + (lastFullDate.getMonth() + 1);
+
+ return {
+ year: '' + lastFullDate.getFullYear(),
+ month: (lastMonth.length === 1 ? '0' : '') + lastMonth,
+ };
}
export default {
labeledCrossProduct,
cloneDeep,
+ getLastFullMonth,
};
--
To view, visit https://gerrit.wikimedia.org/r/398306
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I5ec7db40147c705ecc028ffaac644fa525457170
Gerrit-PatchSet: 2
Gerrit-Project: analytics/wikistats2
Gerrit-Branch: master
Gerrit-Owner: Fdans <[email protected]>
Gerrit-Reviewer: Fdans <[email protected]>
Gerrit-Reviewer: Milimetric <[email protected]>
Gerrit-Reviewer: Nuria <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits