Added position of each top term in the other sets + highligth ones not present.

This commit is contained in:
Mokaddem 2016-08-23 14:52:02 +02:00
parent a64d447b7b
commit e56187eb7e
2 changed files with 36 additions and 13 deletions

View file

@ -714,6 +714,10 @@ def terms_plot_top_data():
today = today.replace(hour=0, minute=0, second=0, microsecond=0) today = today.replace(hour=0, minute=0, second=0, microsecond=0)
today_timestamp = calendar.timegm(today.timetuple()) today_timestamp = calendar.timegm(today.timetuple())
set_day = "TopTermFreq_set_day_" + str(today_timestamp)
set_week = "TopTermFreq_set_week";
set_month = "TopTermFreq_set_month";
the_set = request.args.get('set') the_set = request.args.get('set')
num_day = int(request.args.get('num_day')) num_day = int(request.args.get('num_day'))
if the_set is None: if the_set is None:
@ -724,13 +728,20 @@ def terms_plot_top_data():
the_set += "_" + str(today_timestamp) the_set += "_" + str(today_timestamp)
for term, tot_value in r_serv_term.zrevrangebyscore(the_set, '+inf', '-inf', withscores=True, start=0, num=20): for term, tot_value in r_serv_term.zrevrangebyscore(the_set, '+inf', '-inf', withscores=True, start=0, num=20):
position = {}
position['day'] = r_serv_term.zrevrank(set_day, term)
position['day'] = position['day']+1 if position['day'] is not None else "<20"
position['week'] = r_serv_term.zrevrank(set_week, term)
position['week'] = position['week']+1 if position['week'] is not None else "<20"
position['month'] = r_serv_term.zrevrank(set_month, term)
position['month'] = position['month']+1 if position['month'] is not None else "<20"
value_range = [] value_range = []
for timestamp in range(today_timestamp, today_timestamp - num_day*oneDay, -oneDay): for timestamp in range(today_timestamp, today_timestamp - num_day*oneDay, -oneDay):
value = r_serv_term.hget(timestamp, term) value = r_serv_term.hget(timestamp, term)
curr_value_range = int(value) if value is not None else 0 curr_value_range = int(value) if value is not None else 0
value_range.append([timestamp, curr_value_range]) value_range.append([timestamp, curr_value_range])
to_return.append([term, value_range, tot_value]) to_return.append([term, value_range, tot_value, position])
return jsonify(to_return) return jsonify(to_return)

View file

@ -26,6 +26,9 @@
padding-left:0; padding-left:0;
list-style:none list-style:none
} }
.table > tbody > tr > td {
padding: 5px;
}
</style> </style>
</head> </head>
<body> <body>
@ -82,7 +85,8 @@
<th>Term</th> <th>Term</th>
<th>Value</th> <th>Value</th>
<th>Action</th> <th>Action</th>
<th>Displayed</th> <th>Show</th>
<th data-toggle="tooltip" data-placement="left" title="Position of the term in the week and month set">Position</th>
</tr> </tr>
</thead> </thead>
<tbody id="table-today"> <tbody id="table-today">
@ -96,7 +100,8 @@
<th>Term</th> <th>Term</th>
<th>Value</th> <th>Value</th>
<th>Action</th> <th>Action</th>
<th>Displayed</th> <th>Show</th>
<th data-toggle="tooltip" data-placement="left" title="Position of the term in the week and month set">Position</th>
</tr> </tr>
</thead> </thead>
<tbody id="table-today2"> <tbody id="table-today2">
@ -148,7 +153,8 @@
<th>Term</th> <th>Term</th>
<th>Value</th> <th>Value</th>
<th>Action</th> <th>Action</th>
<th>Displayed</th> <th>Show</th>
<th data-toggle="tooltip" data-placement="left" title="Position of the term in the day and month set">Position</th>
</tr> </tr>
</thead> </thead>
<tbody id="table-week"> <tbody id="table-week">
@ -162,7 +168,8 @@
<th>Term</th> <th>Term</th>
<th>Value</th> <th>Value</th>
<th>Action</th> <th>Action</th>
<th>Displayed</th> <th>Show</th>
<th data-toggle="tooltip" data-placement="left" title="Position of the term in the day and month set">Position</th>
</tr> </tr>
</thead> </thead>
<tbody id="table-week2"> <tbody id="table-week2">
@ -214,7 +221,8 @@
<th>Term</th> <th>Term</th>
<th>Value</th> <th>Value</th>
<th>Action</th> <th>Action</th>
<th>Displayed</th> <th>Show</th>
<th data-toggle="tooltip" data-placement="left" title="Position of the term in the day and week set">Position</th>
</tr> </tr>
</thead> </thead>
<tbody id="table-month"> <tbody id="table-month">
@ -228,7 +236,8 @@
<th>Term</th> <th>Term</th>
<th>Value</th> <th>Value</th>
<th>Action</th> <th>Action</th>
<th>Displayed</th> <th>Show</th>
<th data-toggle="tooltip" data-placement="left" title="Position of the term in the day and week set">Position</th>
</tr> </tr>
</thead> </thead>
<tbody id="table-month2"> <tbody id="table-month2">
@ -336,6 +345,7 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_today
var to_plot = []; var to_plot = [];
var unchecked_label = []; var unchecked_label = [];
for(i=0; i<data.length; i++) { for(i=0; i<data.length; i++) {
var highlight = data[i][3].week == "<20"? " style=\"background-color: lightgreen;\" " : "";
var curr_data = []; var curr_data = [];
for(j=0; j<data[i][1].length; j++) { for(j=0; j<data[i][1].length; j++) {
curr_data.push([data[i][1][j][0]*1000, data[i][1][j][1]]); curr_data.push([data[i][1][j][0]*1000, data[i][1][j][1]]);
@ -345,9 +355,9 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_today
} }
to_plot.push({ data: curr_data, label: data[i][0]}); to_plot.push({ data: curr_data, label: data[i][0]});
if ( i < (data.length/2)) if ( i < (data.length/2))
table_today.append("<tr><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("today", data[i][0], i<default_num_curves)+"</td></tr>") table_today.append("<tr"+highlight+"><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("today", data[i][0], i<default_num_curves)+"</td><td>"+data[i][3].week+", "+data[i][3].month+"</td></tr>");
else else
table_today2.append("<tr><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("today", data[i][0], i<default_num_curves)+"</td></tr>") table_today2.append("<tr"+highlight+"><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("today", data[i][0], i<default_num_curves)+"</td><td>"+data[i][3].week+", "+data[i][3].month+"</td></tr>");
} }
plot_today = $.plot($("#graph-today"), to_plot, graph_options); plot_today = $.plot($("#graph-today"), to_plot, graph_options);
hide_unchecked_curves(plot_today, unchecked_label); hide_unchecked_curves(plot_today, unchecked_label);
@ -375,6 +385,7 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_week,
var to_plot = []; var to_plot = [];
var unchecked_label = []; var unchecked_label = [];
for(i=0; i<data.length; i++) { for(i=0; i<data.length; i++) {
var highlight = parseInt(data[i][3].day) > 20? " style=\"background-color: orange;\" " : "";
var curr_data = []; var curr_data = [];
for(j=0; j<data[i][1].length; j++) { for(j=0; j<data[i][1].length; j++) {
curr_data.push([data[i][1][j][0]*1000, data[i][1][j][1]]); curr_data.push([data[i][1][j][0]*1000, data[i][1][j][1]]);
@ -384,9 +395,9 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_week,
} }
to_plot.push({ data: curr_data, label: data[i][0]}); to_plot.push({ data: curr_data, label: data[i][0]});
if ( i < (data.length/2)) if ( i < (data.length/2))
table.append("<tr><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("week", data[i][0], i<default_num_curves)+"</td></tr>") table.append("<tr"+highlight+"><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("week", data[i][0], i<default_num_curves)+"</td><td><strong>"+data[i][3].day+"</strong>, "+data[i][3].month+"</td></tr>");
else else
table2.append("<tr><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("week", data[i][0], i<default_num_curves)+"</td></tr>") table2.append("<tr"+highlight+"><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("week", data[i][0], i<default_num_curves)+"</td><td><strong>"+data[i][3].day+"</strong>, "+data[i][3].month+"</td></tr>");
} }
plot_week = $.plot($("#graph-week"), to_plot, graph_options); plot_week = $.plot($("#graph-week"), to_plot, graph_options);
hide_unchecked_curves(plot_week, unchecked_label); hide_unchecked_curves(plot_week, unchecked_label);
@ -413,6 +424,7 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_month
var to_plot = []; var to_plot = [];
var unchecked_label = []; var unchecked_label = [];
for(i=0; i<data.length; i++) { for(i=0; i<data.length; i++) {
var highlight = parseInt(data[i][3].day) > 20? " style=\"background-color: orange;\" " : "";
var curr_data = []; var curr_data = [];
for(j=0; j<data[i][1].length; j++) { for(j=0; j<data[i][1].length; j++) {
curr_data.push([data[i][1][j][0]*1000, data[i][1][j][1]]); curr_data.push([data[i][1][j][0]*1000, data[i][1][j][1]]);
@ -422,9 +434,9 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_month
} }
to_plot.push({ data: curr_data, label: data[i][0]}); to_plot.push({ data: curr_data, label: data[i][0]});
if ( i < (data.length/2)) if ( i < (data.length/2))
table.append("<tr><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("month", data[i][0], i<default_num_curves)+"</td></tr>") table.append("<tr"+highlight+"><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("month", data[i][0], i<default_num_curves)+"</td><td><strong>"+data[i][3].day+"</strong>, "+data[i][3].week+"</td></tr>");
else else
table2.append("<tr><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("month", data[i][0], i<default_num_curves)+"</td></tr>") table2.append("<tr"+highlight+"><td>"+data[i][0]+"</td><td>"+data[i][2]+"</td><td>"+addbuttons(data[i][0])+"</td><td>"+addcheckbox("month", data[i][0], i<default_num_curves)+"</td><td><strong>"+data[i][3].day+"</strong>, "+data[i][3].week+"</td></tr>");
} }
plot_month = $.plot($("#graph-month"), to_plot, graph_options); plot_month = $.plot($("#graph-month"), to_plot, graph_options);
hide_unchecked_curves(plot_month, unchecked_label); hide_unchecked_curves(plot_month, unchecked_label);