From 8d41b109e7a7a54546eb88a04bc4c19354f665e4 Mon Sep 17 00:00:00 2001 From: Mokaddem Date: Fri, 19 Aug 2016 14:33:01 +0200 Subject: [PATCH] Added query of the data for the new tracked word --- var/www/Flask_server.py | 36 +++++++++++++++++++++++-- var/www/templates/terms_management.html | 14 +++++----- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 7ce34bdb..cb216447 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -218,6 +218,22 @@ def get_top_relevant_data(server, module_name): # member_set.insert(0, ("passed_days", days)) # return member_set + +def Term_getValueOverRange(word, startDate, num_day): + passed_days = 0 + oneDay = 60*60*24 + to_return = [] + curr_to_return = 0 + for timestamp in range(startDate, startDate - max(num_day)*oneDay, -oneDay): + value = r_serv_term.hget(timestamp, word) + curr_to_return += int(value) if value is not None else 0 + for i in num_day: + if passed_days == i-1: + to_return.append(curr_to_return) + passed_days += 1 + return to_return + + # ========= CACHE CONTROL ======== @app.after_request def add_header(response): @@ -562,17 +578,33 @@ def terms_management(): TrackedTermsSet_Name = "TrackedSetTermSet" BlackListTermsSet_Name = "BlackListSetTermSet" + today = datetime.datetime.now() + today = today.replace(hour=0, minute=0, second=0, microsecond=0) + today_timestamp = calendar.timegm(today.timetuple()) + track_list = [] 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])) + black_list = [] - black_list_values = [] for blacked_term in r_serv_term.smembers(BlackListTermsSet_Name): black_list.append(blacked_term) - return render_template("terms_management.html", black_list=black_list, track_list=track_list) + 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(): + term = request.args.get('term') + today = datetime.datetime.now() + today = today.replace(hour=0, minute=0, second=0, microsecond=0) + today_timestamp = calendar.timegm(today.timetuple()) + + print Term_getValueOverRange(term, today_timestamp, [1, 7, 31]) + return jsonify(Term_getValueOverRange(term, today_timestamp, [1, 7, 31])) @app.route("/terms_management_action/", methods=['GET']) diff --git a/var/www/templates/terms_management.html b/var/www/templates/terms_management.html index 7738f37d..629b8236 100644 --- a/var/www/templates/terms_management.html +++ b/var/www/templates/terms_management.html @@ -97,9 +97,9 @@ {{ term }} {{ i }} - 15 - 55 - 459 + {{ track_list_values[i][0] }} + {{ track_list_values[i][1] }} + {{ track_list_values[i][2] }}

@@ -211,9 +211,11 @@ function perform_operation(){ if(json.section == "followTerm") { if(json.action == "add") { // query data - var action_button = "" - table_track.row.add( [ json.term, 'now', 0, 0, 0, action_button ] ).draw( false ); - perform_binding(); + $.get("{{ url_for('terms_management_query') }}", { term: json.term }, function(data2, status){ + var action_button = "" + table_track.row.add( [ json.term, 'now', 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) {