--- a/controllers/mysql.js
+++ b/controllers/mysql.js
@@ -204,7 +204,7 @@
Retrieve Statistics
*/
-
+/*
module.exports.retrieveStatisticsList = function(ruleid, callback){
var totalNotifications = 0;
var totalNotificationsApplyByRules = 0;
@@ -221,9 +221,8 @@
}
});
}
-
-
-/*
+*/
+
module.exports.retrieveStatisticsList = function(ruleid, callback){
var totalNotifications = 0;
var totalNotificationsApplyByRules = 0;
@@ -238,22 +237,32 @@
}
else{
totalNotifications = rows.length;
- for (var i = 0; i < totalNotifications; i++){
- if(rows[i].result == "true"){
- totalNotificationsApplyByRules++;
- totalValue = parseFloat(totalValue + parseFloat(rows[i].subjectValue));
+
+ if(totalNotifications == 0){
+ totalNotifications = 0;
+ totalValue = 0;
+ totalNotificationsApplyByRules = 0;
+ averageValue = 0.0;
+ percentage = 0.0;
+ }else{
+ for (var i = 0; i < totalNotifications; i++){
+ if(rows[i].result == "true"){
+ totalNotificationsApplyByRules++;
+ totalValue = parseFloat(totalValue + parseFloat(rows[i].subjectValue));
+ }
+ else{
+ totalValue = parseFloat(totalValue + parseFloat(rows[i].subjectValue));
+ }
}
- else{
- totalValue = parseFloat(totalValue + parseFloat(rows[i].subjectValue));
- }
- }
- averageValue = (totalValue / totalNotifications).toFixed(2);
- percentage = ((parseInt(totalNotificationsApplyByRules) * 100 ) / parseInt(totalNotifications)).toFixed(2);
+ averageValue = (totalValue / totalNotifications).toFixed(2);
+ percentage = ((parseInt(totalNotificationsApplyByRules) * 100 ) / parseInt(totalNotifications)).toFixed(2);
+ }
+
callback(true, rows, {totalNotifications: totalNotifications, totalNotificationsApplyByRules: totalNotificationsApplyByRules, averageValue: averageValue, percentage: percentage});
}
});
}
-*/
+
/*
Get Rules by Token
*/