From 0b6828fb16b5759de78f8a72c5cedbee7f30cb54 Mon Sep 17 00:00:00 2001 From: Mokaddem Date: Fri, 19 Aug 2016 16:53:46 +0200 Subject: [PATCH] Correctly handle and display add or remove a term in term-frequency + started sketch of terms-plot tool. --- bin/Curve.py | 8 ++++ var/www/Flask_server.py | 39 ++++++++++++++-- var/www/templates/terms_management.html | 41 +++++++++-------- var/www/templates/terms_plot_tool.html | 59 +++++++++++++------------ 4 files changed, 95 insertions(+), 52 deletions(-) diff --git a/bin/Curve.py b/bin/Curve.py index f804f2bd..e7435eb6 100755 --- a/bin/Curve.py +++ b/bin/Curve.py @@ -14,6 +14,14 @@ words and their occurency per day. ..note:: Module ZMQ_Something_Q and ZMQ_Something are closely bound, always put the same Subscriber name in both of them. + + + +zrank for each day +week -> top zrank for each day + + + Requirements ------------ diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index cb216447..9c98642e 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -5,6 +5,7 @@ import redis import ConfigParser import json import datetime +import time import calendar from flask import Flask, render_template, jsonify, request import flask @@ -577,6 +578,8 @@ def sentiment_analysis_plot_tool_getdata(): def terms_management(): TrackedTermsSet_Name = "TrackedSetTermSet" BlackListTermsSet_Name = "BlackListSetTermSet" + TrackedTermsDate_Name = "TrackedTermDate" + BlackListTermsDate_Name = "BlackListTermDate" today = datetime.datetime.now() today = today.replace(hour=0, minute=0, second=0, microsecond=0) @@ -586,32 +589,58 @@ def terms_management(): track_list_values = [] for tracked_term in r_serv_term.smembers(TrackedTermsSet_Name): track_list.append(tracked_term) - track_list_values.append(Term_getValueOverRange(tracked_term, today_timestamp, [1, 7, 31])) + value_range = Term_getValueOverRange(tracked_term, today_timestamp, [1, 7, 31]) + + term_date = r_serv_term.hget(TrackedTermsDate_Name, tracked_term) + term_date = datetime.datetime.utcfromtimestamp(int(term_date)) if term_date is not None else "No date recorded" + value_range.append(term_date) + track_list_values.append(value_range) black_list = [] for blacked_term in r_serv_term.smembers(BlackListTermsSet_Name): - black_list.append(blacked_term) + term_date = r_serv_term.hget(BlackListTermsDate_Name, blacked_term) + term_date = datetime.datetime.utcfromtimestamp(int(term_date)) if term_date is not None else "No date recorded" + print term_date + black_list.append([blacked_term, term_date]) return render_template("terms_management.html", black_list=black_list, track_list=track_list, track_list_values=track_list_values) @app.route("/terms_management_query/") def terms_management_query(): + TrackedTermsDate_Name = "TrackedTermDate" + BlackListTermsDate_Name = "BlackListTermDate" term = request.args.get('term') + section = request.args.get('section') + today = datetime.datetime.now() today = today.replace(hour=0, minute=0, second=0, microsecond=0) today_timestamp = calendar.timegm(today.timetuple()) + value_range = Term_getValueOverRange(term, today_timestamp, [1, 7, 31]) - print Term_getValueOverRange(term, today_timestamp, [1, 7, 31]) - return jsonify(Term_getValueOverRange(term, today_timestamp, [1, 7, 31])) + if section == "followTerm": + term_date = r_serv_term.hget(TrackedTermsDate_Name, term) + elif section == "blacklistTerm": + term_date = r_serv_term.hget(BlackListTermsDate_Name, term) + + term_date = datetime.datetime.utcfromtimestamp(int(term_date)) if term_date is not None else "No date recorded" + value_range.append(str(term_date)) + return jsonify(value_range) @app.route("/terms_management_action/", methods=['GET']) def terms_management_action(): TrackedTermsSet_Name = "TrackedSetTermSet" + TrackedTermsDate_Name = "TrackedTermDate" + BlackListTermsDate_Name = "BlackListTermDate" BlackListTermsSet_Name = "BlackListSetTermSet" + today = datetime.datetime.now() + today = today.replace(microsecond=0) + today_timestamp = calendar.timegm(today.timetuple()) + + section = request.args.get('section') action = request.args.get('action') term = request.args.get('term') @@ -621,11 +650,13 @@ def terms_management_action(): if section == "followTerm": if action == "add": r_serv_term.sadd(TrackedTermsSet_Name, term) + r_serv_term.hset(TrackedTermsDate_Name, term, today_timestamp) else: r_serv_term.srem(TrackedTermsSet_Name, term) elif section == "blacklistTerm": if action == "add": r_serv_term.sadd(BlackListTermsSet_Name, term) + r_serv_term.hset(BlackListTermsDate_Name, term, today_timestamp) else: r_serv_term.srem(BlackListTermsSet_Name, term) else: diff --git a/var/www/templates/terms_management.html b/var/www/templates/terms_management.html index 629b8236..f4ebb0cb 100644 --- a/var/www/templates/terms_management.html +++ b/var/www/templates/terms_management.html @@ -83,8 +83,8 @@ - - + + @@ -96,7 +96,7 @@ {% for term in track_list %} - + @@ -137,8 +137,8 @@
Term nameDateTermAdded date Day occurence Week occurence Month occurence
{{ term }}{{ i }}{{ track_list_values[i][3] }} {{ track_list_values[i][0] }} {{ track_list_values[i][1] }} {{ track_list_values[i][2] }}
- - + + @@ -146,10 +146,10 @@ {% set i = 0 %} {% for term in black_list %} - - + + {% set i = i + 1 %} @@ -211,29 +211,32 @@ function perform_operation(){ if(json.section == "followTerm") { if(json.action == "add") { // query data - $.get("{{ url_for('terms_management_query') }}", { term: json.term }, function(data2, status){ + $.get("{{ url_for('terms_management_query') }}", { term: json.term, section: json.section }, function(data2, status){ var action_button = "" - table_track.row.add( [ json.term, 'now', data2[0], data2[1], data2[2], action_button ] ).draw( false ); + table_track.row.add( [ json.term, data2[3], data2[0], data2[1], data2[2], action_button ] ).draw( false ); perform_binding(); }); } else if (json.action == "delete") { // Find indexes of row which have the term in the first column - var index = table_track.row().eq( 0 ).filter( function (rowIdx) { - return table_track.cell( rowIdx, 0 ).data() == json.term ? true : false; + var index = table_track.rows().eq( 0 ).filter( function (rowIdx) { + return table_track.cell( rowIdx, 0 ).data() === json.term; } ); - table_track.row().remove(index).draw( false ); + table_track.rows(index).remove().draw( false ); } } else if(json.section == "blacklistTerm"){ if(json.action == "add") { - var action_button = "" - table_black.row.add( [ json.term, 'now', action_button ] ).draw( false ); - perform_binding(); + $.get("{{ url_for('terms_management_query') }}", { term: json.term, section: json.section }, function(data2, status){ + console.log(data2); + var action_button = "" + table_black.row.add( [ json.term, data2[3], action_button ] ).draw( false ); + perform_binding(); + }); } else if (json.action == "delete") { // Find indexes of row which have the term in the first column - var index = table_black.row().eq( 0 ).filter( function (rowIdx) { - return table_black.cell( rowIdx, 0 ).data() == json.term ? true : false; + var index = table_black.rows().eq( 0 ).filter( function (rowIdx) { + return table_black.cell( rowIdx, 0 ).data() === json.term; } ); - table_black.row().remove(index).draw( false ); + table_black.rows(index).remove().draw( false ); } } diff --git a/var/www/templates/terms_plot_tool.html b/var/www/templates/terms_plot_tool.html index 73121d57..c3373658 100644 --- a/var/www/templates/terms_plot_tool.html +++ b/var/www/templates/terms_plot_tool.html @@ -54,7 +54,7 @@
-

Terms plot tool

+

Terms plot tool

@@ -71,34 +71,15 @@ Select options
-
- -
- -
-
-
    -
-
-
-
-
-
    -
-
-
-
- -
-
- Date: -
-
- -
- - +
+ Date: + +
+ + +
+
@@ -142,9 +123,29 @@ $(document).ready(function(){ activePage = $('h1.page-header').attr('data-page'); $("#"+activePage).addClass("active"); + + + /* Create the slider and button*/ + var today = Date.now(); + var old_day = today - (12*31*24*60*60)*1000; + $( ".sliderRange" ).slider({ + range: true, + min: old_day, + max: today, + values: [ today - (7*24*60*60)*1000, today ], + step: 24*60*60*1000, + slide: function( event, ui ) { + $( "#amount" ).val( new Date(ui.values[ 0 ]).toLocaleDateString() + " - " + new Date(ui.values[ 1 ]).toLocaleDateString() ); + } + }); + +$( "#amount" ).val( new Date($( ".sliderRange" ).slider( "values", 0 )).toLocaleDateString() + + " - " + new Date($( ".sliderRange" ).slider( "values", 1 )).toLocaleDateString() ); + +$('#plot_btn').click(plotData); + }); -
Term nameDateTermxAdded date Action
{{ term }}{{ i }}{{ black_list[i][0] }}{{ black_list[i][1] }}

- +