In moduleStat, display old data if there is no data today and notify the user.

pull/65/head
Mokaddem 2016-07-26 12:07:52 +02:00
parent baa042827d
commit c07c12088d
3 changed files with 36 additions and 16 deletions

View File

@ -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)

View File

@ -87,7 +87,19 @@
function(data) {
var temp_data_pie = [];
for(i=0; i<data.length; i++){
temp_data_pie.push({label: data[i][0], data: data[i][1]});
if (i==0 && data[0][0] == "passed_days"){ //If there is no data today, take it from the past
if (data[0][1] > 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);

View File

@ -2,9 +2,9 @@
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div id="panel-credential" class="panel panel-default">
<div class="panel-heading">
<i id="flash-tld" class="fa fa-unlock" flash-tld=""></i> <strong> Credential</strong> - Today most posted domain
<i id="flash-tld" class="fa fa-unlock" flash-tld=""></i> <strong> Credential</strong> - <b id="day-credential">Today</b> most posted domain
</div>
<div class="panel-body">
<div class="">
@ -26,9 +26,9 @@
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div id="panel-mail" class="panel panel-default">
<div class="panel-heading">
<i id="flash-tld" class="fa fa-envelope" flash-tld=""></i><strong> Mail</strong> - Today most posted domain (max 1 per paste)
<i id="flash-mail" class="fa fa-envelope" flash-tld=""></i><strong> Mail</strong> - <b id="day-mail">Today</b> most posted domain (max 1 per paste)
</div>
<div class="panel-body">
<div class="">
@ -52,7 +52,7 @@
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<i id="flash-size" class="glyphicon glyphicon-transfer" flash-tld=""></i><strong> Provider</strong> - Today average paste size
<i id="flash-size" class="glyphicon glyphicon-transfer" flash-tld=""></i><strong> Provider</strong> - <b>Today</b> average paste size
</div>
<div class="panel-body">
<div class="">