Skip to content

Commit 44431e3

Browse files
Merge pull request #4003 from Countly/fix/dashboard-number-period
explicit period set for number widget
2 parents e891897 + 3550523 commit 44431e3

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

api/lib/countly.common.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ countlyCommon.extractChartData = function(db, clearFunction, chartData, dataProp
699699
* @param {object} data - countly metric model data
700700
* @param {object} props - object where key is output property name and value could be string as key from data object or function to create new value based on existing ones
701701
* @param {function} clearObject - function to prefill all expected properties as u, t, n, etc with 0, so you would not have null in the result which won't work when drawing graphs
702+
* @param {object} periodObject - period object override
702703
* @returns {object} object with sparkleline data for each property
703704
* @example
704705
* var sparkLines = countlyCommon.getSparklineData(countlySession.getDb(), {
@@ -723,8 +724,8 @@ countlyCommon.extractChartData = function(db, clearFunction, chartData, dataProp
723724
* "avg-events":"1.6222222222222222,1.5555555555555556,1.6,1.6363636363636365,1.6486486486486487,1,1,1,1,1,1.8333333333333333,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1.4137931034482758,1,1,1,1"
724725
* }
725726
*/
726-
countlyCommon.getSparklineData = function(data, props, clearObject) {
727-
var _periodObj = countlyCommon.periodObj;
727+
countlyCommon.getSparklineData = function(data, props, clearObject, periodObject) {
728+
var _periodObj = periodObject || countlyCommon.periodObj;
728729
var sparkLines = {};
729730
for (let p in props) {
730731
sparkLines[p] = [];
@@ -1530,6 +1531,7 @@ countlyCommon.timeString = function(timespent) {
15301531
* @param {array} unique - array of all properties that are unique from properties array. We need to apply estimation to them
15311532
* @param {object} totalUserOverrideObj - using unique property as key and total_users estimation property as value for all unique metrics that we want to have total user estimation overridden
15321533
* @param {object} prevTotalUserOverrideObj - using unique property as key and total_users estimation property as value for all unique metrics that we want to have total user estimation overridden for previous period
1534+
* @param {object} periodObject period object override for calculation
15331535
* @returns {object} dashboard data object
15341536
* @example
15351537
* countlyCommon.getDashboardData(countlySession.getDb(), ["t", "n", "u", "d", "e", "p", "m"], ["u", "p", "m"], {u:"users"});
@@ -1544,7 +1546,7 @@ countlyCommon.timeString = function(timespent) {
15441546
* "m":{"total":86,"prev-total":0,"change":"NA","trend":"u","isEstimate":true}
15451547
* }
15461548
*/
1547-
countlyCommon.getDashboardData = function(data, properties, unique, totalUserOverrideObj, prevTotalUserOverrideObj) {
1549+
countlyCommon.getDashboardData = function(data, properties, unique, totalUserOverrideObj, prevTotalUserOverrideObj, periodObject) {
15481550
/**
15491551
* Clear object, bu nulling out predefined properties, that does not exist
15501552
* @param {object} obj - object to clear
@@ -1568,7 +1570,7 @@ countlyCommon.getDashboardData = function(data, properties, unique, totalUserOve
15681570
return obj;
15691571
}
15701572

1571-
var _periodObj = countlyCommon.periodObj,
1573+
var _periodObj = periodObject || countlyCommon.periodObj,
15721574
dataArr = {},
15731575
tmp_x,
15741576
tmp_y,

api/lib/countly.model.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ countlyModel.create = function(fetchValue) {
507507
* @returns {array} object to use when displaying number {value: 123, change: 12, sparkline: [1,2,3,4,5,6,7]}
508508
*/
509509
countlyMetric.getNumber = function(metric, isSparklineNotRequired) {
510+
var periodObject = null;
511+
if (this.getPeriod()) { // only set custom period if it was explicitly set on the model object
512+
periodObject = countlyCommon.getPeriodObj({qstring: {}}, this.getPeriod());
513+
}
510514
metric = metric || _metrics[0];
511515
var metrics = [metric];
512516
//include other default metrics for data correction
@@ -517,7 +521,7 @@ countlyModel.create = function(fetchValue) {
517521
if (metric === "n") {
518522
metrics.push("u");
519523
}
520-
var data = countlyCommon.getDashboardData(this.getDb(), metrics, _uniques, { u: this.getTotalUsersObj().users }, { u: this.getTotalUsersObj(true).users });
524+
var data = countlyCommon.getDashboardData(this.getDb(), metrics, _uniques, { u: this.getTotalUsersObj().users }, { u: this.getTotalUsersObj(true).users }, periodObject);
521525
if (isSparklineNotRequired) {
522526
return data[metric];
523527
}
@@ -535,7 +539,7 @@ countlyModel.create = function(fetchValue) {
535539
}
536540

537541
return obj;
538-
});
542+
}, periodObject);
539543
for (let i in data) {
540544
if (sparkLines[i]) {
541545
data[i].sparkline = sparkLines[i].split(",").map(function(item) {

0 commit comments

Comments
 (0)