Skip to content

Commit 9f8e854

Browse files
committed
[crashes] fixing crashes stats
1 parent d0a936b commit 9f8e854

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

api/utils/common.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,7 @@ function stripPort(ip) {
16281628
* @param {object} object - object to fill
16291629
* @param {string} property - meric value or segment or property to fill/increment
16301630
* @param {number=} increment - by how much to increments, default is 1
1631+
* @param {boolean=} isUnique - if property is unique
16311632
* @returns {void} void
16321633
* @example
16331634
* var obj = {};
@@ -1636,7 +1637,7 @@ function stripPort(ip) {
16361637
* //outputs
16371638
* { 'd.u': 1, 'd.2.u': 1, 'd.w8.u': 1 }
16381639
*/
1639-
common.fillTimeObjectZero = function(params, object, property, increment) {
1640+
common.fillTimeObjectZero = function(params, object, property, increment, isUnique) {
16401641
var tmpIncrement = (increment) ? increment : 1,
16411642
timeObj = params.time;
16421643

@@ -1650,7 +1651,8 @@ common.fillTimeObjectZero = function(params, object, property, increment) {
16501651
object['d.' + timeObj.month + '.' + property[i]] = tmpIncrement;
16511652

16521653
// For properties that hold the unique visitor count we store weekly data as well.
1653-
if (property[i].substr(-2) === ("." + common.dbMap.unique) ||
1654+
if (isUnique ||
1655+
property[i].substr(-2) === ("." + common.dbMap.unique) ||
16541656
property[i] === common.dbMap.unique ||
16551657
property[i].substr(0, 2) === (common.dbMap.frequency + ".") ||
16561658
property[i].substr(0, 2) === (common.dbMap.loyalty + ".") ||
@@ -1664,7 +1666,7 @@ common.fillTimeObjectZero = function(params, object, property, increment) {
16641666
object['d.' + property] = tmpIncrement;
16651667
object['d.' + timeObj.month + '.' + property] = tmpIncrement;
16661668

1667-
if (property.substr(-2) === ("." + common.dbMap.unique) ||
1669+
if (isUnique || property.substr(-2) === ("." + common.dbMap.unique) ||
16681670
property === common.dbMap.unique ||
16691671
property.substr(0, 2) === (common.dbMap.frequency + ".") ||
16701672
property.substr(0, 2) === (common.dbMap.loyalty + ".") ||
@@ -1858,7 +1860,6 @@ common.recordMetric = function(params, props) {
18581860
function recordMetric(params, metric, props, tmpSet, updateUsersZero, updateUsersMonth) {
18591861
var zeroObjUpdate = [],
18601862
monthObjUpdate = [];
1861-
18621863
if (props.unique) {
18631864
if (props.lastTimestamp) {
18641865
var currDate = common.getDate(params.time.timestamp, params.appTimezone),
@@ -1890,7 +1891,7 @@ function recordMetric(params, metric, props, tmpSet, updateUsersZero, updateUser
18901891
}
18911892
}
18921893
else {
1893-
common.fillTimeObjectZero(params, updateUsersZero, metric, props.value);
1894+
common.fillTimeObjectZero(params, updateUsersZero, metric, props.value, true);
18941895
common.fillTimeObjectMonth(params, updateUsersMonth, metric, props.value);
18951896
}
18961897
}
@@ -1967,7 +1968,7 @@ function recordSegmentMetric(params, metric, name, val, props, tmpSet, updateUse
19671968
}
19681969
}
19691970
else {
1970-
common.fillTimeObjectZero(params, updateUsersZero, escapedMetricVal + '.' + metric, props.value);
1971+
common.fillTimeObjectZero(params, updateUsersZero, escapedMetricVal + '.' + metric, props.value, true);
19711972
common.fillTimeObjectMonth(params, updateUsersMonth, escapedMetricVal + '.' + metric, props.value, recordHourly);
19721973
}
19731974
}

plugins/crashes/api/api.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ plugins.setConfigs("crashes", {
218218
}
219219
version = (version + "").replace(/^\$/, "").replace(/\./g, ":");
220220
}
221-
222221
common.recordCustomMetric(params, "crashdata", params.app_id, metrics, 1, null, ["cr_u"], dbAppUser.ls);
223222
if (platform && version) {
224223
common.recordCustomMetric(params, "crashdata", platform + "**" + version + "**" + params.app_id, metrics, 1, null, ["cr_u"], (version === dbAppUser.av && platform === dbAppUser.p) ? dbAppUser.ls : 0);
@@ -893,7 +892,7 @@ plugins.setConfigs("crashes", {
893892
}
894893
}
895894
}
896-
var options = {unique: ["cru", "crau", "crauf", "craunf", "cruf", "crunf"]/*, levels:{daily:["cr","crnf","cru","crf", "crru"], monthly:["cr","crnf","cru","crf", "crru"]}*/};
895+
var options = {unique: ["cru", "crau", "crauf", "craunf", "cruf", "crunf", "cr_u"]/*, levels:{daily:["cr","crnf","cru","crf", "crru"], monthly:["cr","crnf","cru","crf", "crru"]}*/};
897896

898897
if (params.qstring.os || params.qstring.app_version) {
899898
var props = [];

plugins/crashes/frontend/public/javascripts/countly.models.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@
109109

110110
["total", "prev-total"].forEach(function(prop) {
111111
dashboard["cr-session"][prop] = (dashboard.cr_s[prop] === 0) ? 0 : (Math.round(Math.min(dashboard.cr[prop] / dashboard.cr_s[prop], 1) * 100) / 100);
112-
dashboard.crau[prop] = Math.max(0, dashboard.crauf[prop] + dashboard.craunf[prop] - dashboard.cr_u[prop]);
113-
dashboard.crses[prop] = Math.max(0, dashboard.crfses[prop] + dashboard.crnfses[prop] - dashboard.cr_s[prop]);
114-
dashboard.crtf[prop] = Math.round(Math.min(dashboard.crf[prop] / dashboard.cr_s[prop], 1) * 100) / 100;
115-
dashboard.crtnf[prop] = Math.round(Math.min(dashboard.crnf[prop] / dashboard.cr_s[prop], 1) * 100) / 100;
112+
dashboard.crau[prop] = Math.max(0, dashboard.crauf[prop] + dashboard.craunf[prop]);
113+
dashboard.crses[prop] = Math.max(0, dashboard.crfses[prop] + dashboard.crnfses[prop]);
114+
dashboard.crtf[prop] = (dashboard.cr_s[prop] === 0) ? 0 : (Math.round(Math.min(dashboard.crf[prop] / dashboard.cr_s[prop], 1) * 100) / 100);
115+
dashboard.crtnf[prop] = (dashboard.cr_s[prop] === 0) ? 0 : (Math.round(Math.min(dashboard.crnf[prop] / dashboard.cr_s[prop], 1) * 100) / 100);
116116

117117
});
118118

@@ -122,14 +122,14 @@
122122

123123
["crau", "craunf", "crauf"].forEach(function(name) {
124124
["total", "prev-total"].forEach(function(prop) {
125-
dashboard[name][prop] = Math.min(100, (dashboard.cr_u[prop] === 0) ? 100 : (dashboard[name][prop] / dashboard.cr_u[prop] * 100));
125+
dashboard[name][prop] = Math.min(100, (dashboard.cr_u[prop] === 0 || dashboard[name][prop] === 0) ? 100 : ((dashboard[name][prop] - dashboard.cr_u[prop]) / dashboard.cr_u[prop] * 100));
126126
});
127127
populateMetric(name, true);
128128
});
129129

130130
["crses", "crnfses", "crfses"].forEach(function(name) {
131131
["total", "prev-total"].forEach(function(prop) {
132-
dashboard[name][prop] = Math.min(100, (dashboard.cr_s[prop] === 0) ? 100 : (dashboard[name][prop] / dashboard.cr_s[prop] * 100));
132+
dashboard[name][prop] = Math.min(100, (dashboard.cr_s[prop] === 0 || dashboard[name][prop] === 0) ? 100 : ((dashboard[name][prop] - dashboard.cr_s[prop]) / dashboard.cr_s[prop] * 100));
133133
});
134134
populateMetric(name, true);
135135
});
@@ -193,10 +193,10 @@
193193
return (obj.cr_s === 0) ? 0 : Math.round(Math.min((obj.crf + obj.crnf) / obj.cr_s, 1) * 100) / 100;
194194
},
195195
"^crses$": function(obj) {
196-
return (obj.cr_s === 0) ? 100 : Math.round(Math.min(Math.max((obj.crfses + obj.crnfses - obj.cr_s) / obj.cr_s, 0), 1) * 10000) / 100;
196+
return (obj.cr_s === 0 || obj.crfses + obj.crnfses === 0) ? 100 : Math.round(Math.min(Math.max((obj.crfses + obj.crnfses - obj.cr_s) / obj.cr_s, 0), 1) * 10000) / 100;
197197
},
198198
"^crau$": function(obj) {
199-
return (obj.cr_u === 0) ? 100 : Math.round(Math.min(Math.max((obj.crauf + obj.craunf - obj.cr_u) / obj.cr_u, 0), 1) * 10000) / 100;
199+
return (obj.cr_u === 0 || obj.crauf + obj.craunf === 0) ? 100 : Math.round(Math.min(Math.max((obj.crauf + obj.craunf - obj.cr_u) / obj.cr_u, 0), 1) * 10000) / 100;
200200
},
201201
"^cr$": function(obj) {
202202
return obj.crf + obj.crnf;
@@ -208,10 +208,10 @@
208208
return (obj.cr_s === 0) ? 0 : Math.round(Math.min(obj[state.activeFilter.fatality === "fatal" ? "crf" : "crnf"] / obj.cr_s, 1) * 100) / 100;
209209
},
210210
"^crn?fses$": function(obj) {
211-
return (obj.cr_s === 0) ? 100 : Math.round(Math.min(obj[name] / obj.cr_s, 1) * 10000) / 100;
211+
return (obj.cr_s === 0 || obj[name] === 0) ? 100 : Math.round(Math.min(obj[name] / obj.cr_s, 1) * 10000) / 100;
212212
},
213213
"^craun?f$": function(obj) {
214-
return (obj.cr_s === 0) ? 100 : Math.round(Math.min(obj[name] / obj.cr_u, 1) * 10000) / 100;
214+
return (obj.cr_s === 0 || obj[name] === 0) ? 100 : Math.round(Math.min(obj[name] / obj.cr_u, 1) * 10000) / 100;
215215
}
216216
};
217217

@@ -264,11 +264,11 @@
264264
statistics.users = {
265265
affected: {
266266
total: state.rawData.users.affected,
267-
totalPercent: parseFloat(((state.rawData.users.affected / state.rawData.users.total) * 100).toFixed(2)),
267+
totalPercent: parseFloat((((state.rawData.users.total === 0) ? 0 : (state.rawData.users.affected / state.rawData.users.total)) * 100).toFixed(2)),
268268
fatal: state.rawData.users.fatal,
269-
fatalPercent: parseFloat(((state.rawData.users.fatal / state.rawData.users.total) * 100).toFixed(2)),
269+
fatalPercent: parseFloat((((state.rawData.users.total === 0) ? 0 : (state.rawData.users.fatal / state.rawData.users.total)) * 100).toFixed(2)),
270270
nonFatal: (state.rawData.users.affected - state.rawData.users.fatal),
271-
nonFatalPercent: parseFloat((((state.rawData.users.affected - state.rawData.users.fatal) / state.rawData.users.total) * 100).toFixed(2)),
271+
nonFatalPercent: parseFloat((((state.rawData.users.total === 0) ? 0 : ((state.rawData.users.affected - state.rawData.users.fatal) / state.rawData.users.total)) * 100).toFixed(2)),
272272
},
273273
notAffected: {
274274
total: state.rawData.users.affected,
@@ -281,15 +281,15 @@
281281
statistics.crashes = {
282282
total: state.rawData.crashes.total,
283283
fatal: state.rawData.crashes.fatal,
284-
fatalPercent: (state.rawData.crashes.fatal / state.rawData.crashes.total) * 100,
284+
fatalPercent: ((state.rawData.crashes.total === 0) ? 0 : (state.rawData.crashes.fatal / state.rawData.crashes.total)) * 100,
285285
nonFatal: state.rawData.crashes.nonfatal,
286-
nonFatalPercent: (state.rawData.crashes.nonfatal / state.rawData.crashes.total) * 100,
286+
nonFatalPercent: ((state.rawData.crashes.total === 0) ? 0 : (state.rawData.crashes.nonfatal / state.rawData.crashes.total)) * 100,
287287
new: state.rawData.crashes.news,
288-
newPercent: (state.rawData.crashes.news / state.rawData.crashes.total) * 100,
288+
newPercent: ((state.rawData.crashes.total === 0) ? 0 : (state.rawData.crashes.news / state.rawData.crashes.total)) * 100,
289289
resolved: state.rawData.crashes.resolved,
290-
resolvedPercent: parseFloat(((state.rawData.crashes.resolved / state.rawData.crashes.total) * 100).toFixed(2)),
290+
resolvedPercent: parseFloat((((state.rawData.crashes.total === 0) ? 0 : (state.rawData.crashes.resolved / state.rawData.crashes.total)) * 100).toFixed(2)),
291291
unresolved: (state.rawData.crashes.total - state.rawData.crashes.resolved),
292-
unresolvedPercent: parseFloat((((state.rawData.crashes.total - state.rawData.crashes.resolved) / state.rawData.crashes.total) * 100).toFixed(2)),
292+
unresolvedPercent: parseFloat(((((state.rawData.crashes.total === 0) ? 0 : (state.rawData.crashes.total - state.rawData.crashes.resolved) / state.rawData.crashes.total)) * 100).toFixed(2)),
293293
reoccured: state.rawData.crashes.renewed
294294
};
295295

@@ -299,7 +299,7 @@
299299
Object.keys(state.rawData.crashes.os).forEach(function(platform) {
300300
statistics.topPlatforms[platform] = {
301301
count: countlyCommon.getShortNumber(state.rawData.crashes.os[platform]),
302-
percent: (state.rawData.crashes.os[platform] / statistics.crashes.total) * 100
302+
percent: ((statistics.crashes.total === 0) ? 0 : (state.rawData.crashes.os[platform] / statistics.crashes.total)) * 100
303303
};
304304
});
305305

0 commit comments

Comments
 (0)