Fixed small race condition bug in ModuleStat.py and Added highlight of bar belonging to the same serie in moduleStats.js

This commit is contained in:
Mokaddem 2016-07-29 10:36:44 +02:00
parent c2bf2ba630
commit e8fae17cfd
2 changed files with 62 additions and 45 deletions

View file

@ -61,6 +61,7 @@ def compute_most_posted(server, message, num_day):
if keyw_value is not None: if keyw_value is not None:
member_set.append((keyw, int(keyw_value))) member_set.append((keyw, int(keyw_value)))
member_set.sort(key=lambda tup: tup[1]) member_set.sort(key=lambda tup: tup[1])
if len(member_set) > 0:
if member_set[0][1] < keyword_total_sum: if member_set[0][1] < keyword_total_sum:
#remove min from set and add the new one #remove min from set and add the new one
print module + ': adding ' +keyword+ '(' +str(keyword_total_sum)+') in set and removing '+member_set[0][0]+'('+str(member_set[0][1])+')' print module + ': adding ' +keyword+ '(' +str(keyword_total_sum)+') in set and removing '+member_set[0][0]+'('+str(member_set[0][1])+')'

View file

@ -67,7 +67,7 @@ function plot_top_graph(module_name, init){
} }
for(i=0; i<temp_data_pie.length; i++){ // Detect element below a certain threshold for(i=0; i<temp_data_pie.length; i++){ // Detect element below a certain threshold
if (parseInt(temp_data_pie[i].data) / tot_sum < pie_threshold) if (parseInt(temp_data_pie[i].data) / tot_sum < pie_threshold)
data_other.push(temp_data_pie[i].label); data_other.splice(i, 0, temp_data_pie[i].label);
} }
$.plot($("#flot-pie-chart-"+module_name), temp_data_pie, options); $.plot($("#flot-pie-chart-"+module_name), temp_data_pie, options);
@ -127,20 +127,18 @@ function plot_top_graph(module_name, init){
for(i=1; i<data.length; i++){ for(i=1; i<data.length; i++){
var curr_date = data[i][0].split('/'); var curr_date = data[i][0].split('/');
var offset = (data_other.length/2 - data_other.indexOf(data[0]))*10000000 var offset = (data_other.length/2 - data_other.indexOf(data[0]))*10000000
temp_data_bar.push([new Date(curr_date[0], curr_date[1]-1, curr_date[2]).getTime() + offset, data[i][1]]); temp_data_bar.splice(i, 0, [new Date(curr_date[0], curr_date[1]-1, curr_date[2]).getTime() + offset, data[i][1]]);
} }
all_other_temp_data.push([ data[0], temp_data_bar ]); all_other_temp_data.splice(data_other.indexOf(data[0]), 0, [ data[0], temp_data_bar, data_other.indexOf(data[0])]);
} }
) )
promises.push(request); promises.splice(i, 0, request);
} }
$.when.apply($, promises).done( function (arg) { $.when.apply($, promises).done( function (arg) {
var dataBar = [] var dataBar = []
for(i=0; i<all_other_temp_data.length; i++) //format data for the plot for(i=0; i<all_other_temp_data.length; i++) //format data for the plot
dataBar.push({bars: { barWidth: 8280000 }, label: all_other_temp_data[i][0], data: all_other_temp_data[i][1]}) dataBar.splice(i, 0, {bars: { barWidth: 8280000, order: all_other_temp_data[i][2] }, label: all_other_temp_data[i][0], data: all_other_temp_data[i][1]});
var plot = $.plot($(chartID), dataBar, {
$.plot($(chartID), dataBar, {
series: { series: {
stack: false, stack: false,
lines: { show: false, fill: true, steps: false }, lines: { show: false, fill: true, steps: false },
@ -161,8 +159,25 @@ function plot_top_graph(module_name, init){
position: "nw" position: "nw"
}, },
tooltip: true, tooltip: true,
tooltipOpts: { content: "x: %x, y: %y" } tooltipOpts: { content: "x: %x, y: %y" },
colors: ["#72a555", "#ab62c0", "#c57c3c", "#638ccc", "#ca5670"]
}) })
if (plot_data_old.length<2){
plot_data_old.push(plot.getData());
plot_old.push(plot);
} else {
plot_data_old = [];
plot_old = [];
plot_data_old.push(plot.getData());
plot_old.push(plot);
}
if (can_bind){
binder(module_name);
if (module_name == "size")
binder("num");
else if (module_name == "num")
binder("size");
}
}); });
@ -173,7 +188,7 @@ function plot_top_graph(module_name, init){
var temp_data_bar = [] var temp_data_bar = []
for(i=1; i<data.length; i++){ for(i=1; i<data.length; i++){
var curr_date = data[i][0].split('/'); var curr_date = data[i][0].split('/');
temp_data_bar.push([new Date(curr_date[0], curr_date[1]-1, curr_date[2]), data[i][1]]); temp_data_bar.push([new Date(curr_date[0], curr_date[1]-1, curr_date[2]).getTime(), data[i][1]]);
} }
var barData = { var barData = {
label: involved_item, label: involved_item,
@ -203,8 +218,6 @@ function plot_top_graph(module_name, init){
} }
function binder(module_name){ function binder(module_name){
console.log(module_name);
console.log(plot_data_old);
$("#flot-bar-chart-"+module_name).bind("plothover", function (event, pos, item) { $("#flot-bar-chart-"+module_name).bind("plothover", function (event, pos, item) {
if (item) { if (item) {
var x = item.datapoint[0] var x = item.datapoint[0]
@ -215,20 +228,23 @@ console.log(plot_data_old);
$("#tooltip_graph-"+module_name).html(item.series.label + " of " + formated_date + " = <b>" + y+"</b>") $("#tooltip_graph-"+module_name).html(item.series.label + " of " + formated_date + " = <b>" + y+"</b>")
.css({padding: "2px", width: 'auto', 'background-color': 'white', 'border': "3px solid "+item.series.color}) .css({padding: "2px", width: 'auto', 'background-color': 'white', 'border': "3px solid "+item.series.color})
.fadeIn(200); .fadeIn(200);
var plot_obj = plot_data_old[0]; //contain series
var plot_other = plot_data_old[0]; for(serie=0; serie<plot_obj.length; serie++){
if (plot_other.length > 0){ var data_other = plot_obj[serie].data;
var data_other = plot_other[0].data;
for(i=0; i<data_other.length; i++){ for(i=0; i<data_other.length; i++){
if (data_other[i][0].getTime() == date.getTime()) if (data_other[i][0] == date.getTime()){
if(y == data_other[i][1]){ // Avoid swap due to race condition if(y == data_other[i][1]){ // Avoid swap due to race condition
var other_graph_plot = plot_old[1]; var other_graph_plot = plot_old[1];
var curr_data_other = plot_data_old[1][0].data[i][1]; var curr_data_other = plot_data_old[1][serie].data[i][1];
var datapoint = i; var datapoint = i;
var the_serie = serie;
} else { } else {
var other_graph_plot = plot_old[0]; var other_graph_plot = plot_old[0];
var curr_data_other = data_other[i][1]; var curr_data_other = data_other[i][1];
var datapoint = i; var datapoint = i;
var the_serie = serie;
}
}
} }
} }
if (module_name == "size"){ if (module_name == "size"){
@ -236,18 +252,18 @@ console.log(plot_data_old);
.css({padding: "2px", width: 'auto', 'background-color': 'white', 'border': "3px solid "+item.series.color}) .css({padding: "2px", width: 'auto', 'background-color': 'white', 'border': "3px solid "+item.series.color})
.fadeIn(200); .fadeIn(200);
for(i=0; i<data_other.length; i++) for(i=0; i<data_other.length; i++)
other_graph_plot.unhighlight(0, i); for(s=0; s<plot_obj.length; s++)
other_graph_plot.highlight(0, datapoint); other_graph_plot.unhighlight(s, i);
other_graph_plot.highlight(the_serie, datapoint);
} }
else if (module_name == "num"){ else if (module_name == "num"){
$("#tooltip_graph-"+"size").html(item.series.label + " of " + formated_date + " = <b>" + curr_data_other+"</b>") $("#tooltip_graph-"+"size").html(item.series.label + " of " + formated_date + " = <b>" + curr_data_other+"</b>")
.css({padding: "2px", width: 'auto', 'background-color': 'white', 'border': "3px solid "+item.series.color}) .css({padding: "2px", width: 'auto', 'background-color': 'white', 'border': "3px solid "+item.series.color})
.fadeIn(200); .fadeIn(200);
for(i=0; i<data_other.length; i++) for(i=0; i<data_other.length; i++)
other_graph_plot.unhighlight(0, i); for(s=0; s<plot_obj.length; s++)
other_graph_plot.highlight(0, datapoint); other_graph_plot.unhighlight(s, i);
} other_graph_plot.highlight(the_serie, datapoint);
} else {
} }
} else { } else {
for(i=0; i<plot_old.length; i++) for(i=0; i<plot_old.length; i++)