From c07c12088dbf097dade6e7478f6bd19c6f6d902a Mon Sep 17 00:00:00 2001 From: Mokaddem Date: Tue, 26 Jul 2016 12:07:52 +0200 Subject: [PATCH] In moduleStat, display old data if there is no data today and notify the user. --- var/www/Flask_server.py | 28 ++++++++++++------- var/www/templates/Moduletrending.html | 14 +++++++++- .../trending_graphs/Moduletrending.html | 10 +++---- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 00ceaf14..22388cfb 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -116,7 +116,23 @@ def get_date_range(num_day): date_list.append(date.substract_day(i)) return date_list - +def get_top_relevant_data(server, module_name): + redis_progression_name_set = 'top_'+ module_name +'_set' + days = 0 + for date in get_date_range(15): + member_set = [] + for keyw in server.smembers(redis_progression_name_set): + redis_progression_name = module_name+'-'+keyw + keyw_value = server.hget(date ,redis_progression_name) + keyw_value = keyw_value if keyw_value is not None else 0 + member_set.append((keyw, int(keyw_value))) + member_set.sort(key=lambda tup: tup[1], reverse=True) + if member_set[0][1] == 0: #No data for this date + days += 1 + continue + else: + member_set.insert(0, ("passed_days", days)) + return member_set @@ -182,15 +198,7 @@ def modulesCharts(): return jsonify(bar_values) else: - redis_progression_name_set = 'top_'+ module_name +'_set' - - member_set = [] - for keyw in r_serv_charts.smembers(redis_progression_name_set): - redis_progression_name = module_name+'-'+keyw - keyw_value = r_serv_charts.hget(get_date_range(0)[0] ,redis_progression_name) - keyw_value = keyw_value if keyw_value is not None else 0 - member_set.append((keyw, int(keyw_value))) - member_set.sort(key=lambda tup: tup[1], reverse=True) + member_set = get_top_relevant_data(r_serv_charts, module_name) if len(member_set) == 0: member_set.append(("No relevant data", int(100))) return jsonify(member_set) diff --git a/var/www/templates/Moduletrending.html b/var/www/templates/Moduletrending.html index bd4218e3..ee49c428 100644 --- a/var/www/templates/Moduletrending.html +++ b/var/www/templates/Moduletrending.html @@ -87,7 +87,19 @@ function(data) { var temp_data_pie = []; for(i=0; i 0 && data[0][1] < 7){ + $("#day-"+module_name).text(data[0][1] + " Day(s) ago "); + $("#panel-"+module_name).removeClass("panel-default") + $("#panel-"+module_name).addClass("panel-warning") + } else if (data[0][1] > 6) { + $("#day-"+module_name).text(data[0][1] + " Day(s) ago "); + $("#panel-"+module_name).removeClass("panel-default") + $("#panel-"+module_name).addClass("panel-danger") + } + } else { + temp_data_pie.push({label: data[i][0], data: data[i][1]}); + } } $.plot($("#flot-pie-chart-"+module_name), temp_data_pie, options); diff --git a/var/www/templates/trending_graphs/Moduletrending.html b/var/www/templates/trending_graphs/Moduletrending.html index 0a40df20..4c3477cc 100644 --- a/var/www/templates/trending_graphs/Moduletrending.html +++ b/var/www/templates/trending_graphs/Moduletrending.html @@ -2,9 +2,9 @@
-
+
- Credential - Today most posted domain + Credential - Today most posted domain
@@ -26,9 +26,9 @@
-
+
- Mail - Today most posted domain (max 1 per paste) + Mail - Today most posted domain (max 1 per paste)
@@ -52,7 +52,7 @@
- Provider - Today average paste size + Provider - Today average paste size