mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-23 14:37:17 +00:00
Added terms trending module and web interface:
- Curve module has been rewritten - Added new module curve_manage_top_set - Added all web-pages
This commit is contained in:
parent
841e87eb16
commit
d3c0fc5f94
8 changed files with 387 additions and 67 deletions
52
bin/Curve.py
52
bin/Curve.py
|
@ -41,11 +41,25 @@ import calendar
|
||||||
from Helper import Process
|
from Helper import Process
|
||||||
|
|
||||||
# Config Variables
|
# Config Variables
|
||||||
|
BlackListTermsSet_Name = "BlackListSetTermSet"
|
||||||
|
TrackedTermsSet_Name = "TrackedSetTermSet"
|
||||||
top_term_freq_max_set_cardinality = 20 # Max cardinality of the terms frequences set
|
top_term_freq_max_set_cardinality = 20 # Max cardinality of the terms frequences set
|
||||||
|
oneDay = 60*60*24
|
||||||
|
top_termFreq_setName_day = ["TopTermFreq_set_day_", 1]
|
||||||
|
top_termFreq_setName_week = ["TopTermFreq_set_week", 7]
|
||||||
|
top_termFreq_setName_month = ["TopTermFreq_set_month", 31]
|
||||||
|
top_termFreq_set_array = [top_termFreq_setName_day,top_termFreq_setName_week, top_termFreq_setName_month]
|
||||||
|
|
||||||
|
|
||||||
|
def check_if_tracked_term(term, path):
|
||||||
|
if term in TrackedTermsSet_Name:
|
||||||
|
#add_paste to tracked_word_set
|
||||||
|
set_name = "tracked_" + term
|
||||||
|
server.sadd(set_name, path)
|
||||||
|
p.populate_set_out("New Term added", 'CurveManageTopSets')
|
||||||
|
|
||||||
|
|
||||||
def getValueOverRange(word, startDate, num_day):
|
def getValueOverRange(word, startDate, num_day):
|
||||||
oneDay = 60*60*24
|
|
||||||
to_return = 0
|
to_return = 0
|
||||||
for timestamp in range(startDate, startDate - num_day*oneDay, -oneDay):
|
for timestamp in range(startDate, startDate - num_day*oneDay, -oneDay):
|
||||||
value = server_term.hget(timestamp, word)
|
value = server_term.hget(timestamp, word)
|
||||||
|
@ -86,10 +100,9 @@ if __name__ == "__main__":
|
||||||
generate_new_graph = False
|
generate_new_graph = False
|
||||||
|
|
||||||
# Term Frequency
|
# Term Frequency
|
||||||
top_termFreq_setName_day = ["TopTermFreq_set_day", 1]
|
top_termFreq_setName_day = ["TopTermFreq_set_day_", 1]
|
||||||
top_termFreq_setName_week = ["TopTermFreq_set_week", 7]
|
top_termFreq_setName_week = ["TopTermFreq_set_week", 7]
|
||||||
top_termFreq_setName_month = ["TopTermFreq_set_month", 31]
|
top_termFreq_setName_month = ["TopTermFreq_set_month", 31]
|
||||||
top_termFreq_set_array = [top_termFreq_setName_day,top_termFreq_setName_week, top_termFreq_setName_month]
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
@ -100,42 +113,33 @@ if __name__ == "__main__":
|
||||||
temp = filename.split('/')
|
temp = filename.split('/')
|
||||||
date = temp[-4] + temp[-3] + temp[-2]
|
date = temp[-4] + temp[-3] + temp[-2]
|
||||||
timestamp = calendar.timegm((int(temp[-4]), int(temp[-3]), int(temp[-2]), 0, 0, 0))
|
timestamp = calendar.timegm((int(temp[-4]), int(temp[-3]), int(temp[-2]), 0, 0, 0))
|
||||||
|
top_termFreq_setName_day[0] += timestamp
|
||||||
# If set size is greater then the one authorized
|
|
||||||
# suppress smaller elements
|
|
||||||
for curr_set, curr_num_day in top_termFreq_set_array:
|
|
||||||
diffCard = server_term.scard(curr_set) - top_term_freq_max_set_cardinality
|
|
||||||
if diffCard > 0:
|
|
||||||
top_termFreq = server_term.smembers(curr_set)
|
|
||||||
sorted_top_termFreq_set = []
|
|
||||||
for word in top_termFreq:
|
|
||||||
word_value = getValueOverRange(word, timestamp, curr_num_day)
|
|
||||||
sorted_top_termFreq_set.append((word, word_value))
|
|
||||||
|
|
||||||
sorted_top_termFreq_set.sort(key=lambda tup: tup[1])
|
|
||||||
for i in range(0, diffCard):
|
|
||||||
print 'set oversized, dropping', sorted_top_termFreq_set[i][0]
|
|
||||||
server_term.srem(curr_set, sorted_top_termFreq_set[i][0])
|
|
||||||
|
|
||||||
|
|
||||||
#timer = time.clock()
|
|
||||||
low_word = word.lower()
|
low_word = word.lower()
|
||||||
#print 'wordlower', time.clock() - timer
|
#Old curve
|
||||||
r_serv1.hincrby(low_word, date, int(score))
|
r_serv1.hincrby(low_word, date, int(score))
|
||||||
|
|
||||||
|
|
||||||
# Update redis
|
# Update redis
|
||||||
curr_word_value = int(server_term.hincrby(timestamp, low_word, int(score)))
|
curr_word_value = int(server_term.hincrby(timestamp, low_word, int(score)))
|
||||||
|
if low_word not in server.smembers(BlackListTermsSet_Name):
|
||||||
|
server.zincrby(top_termFreq_setName_day[0], int(score), low_word)
|
||||||
|
|
||||||
# Manage Top set
|
#Add more info for tracked terms
|
||||||
for curr_set, curr_num_day in top_termFreq_set_array:
|
check_if_tracked_term(low_word, filename)
|
||||||
|
|
||||||
|
# Manage Top set is done in module Curve_manage_top_sets
|
||||||
|
|
||||||
|
'''
|
||||||
if server_term.scard(curr_set) < top_term_freq_max_set_cardinality:
|
if server_term.scard(curr_set) < top_term_freq_max_set_cardinality:
|
||||||
server_term.sadd(curr_set, low_word)
|
server_term.sadd(curr_set, low_word)
|
||||||
elif server_term.sismember(curr_set, low_word):
|
elif server_term.sismember(curr_set, low_word):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
|
||||||
#timer = time.clock()
|
#timer = time.clock()
|
||||||
curr_word_value = getValueOverRange(low_word, timestamp, curr_num_day)
|
curr_word_value = getValueOverRange(low_word, timestamp, curr_num_day)
|
||||||
#print 'curr_range', time.clock() - timer
|
#print 'curr_range', time.clock() - timer
|
||||||
|
@ -153,7 +157,7 @@ if __name__ == "__main__":
|
||||||
print str(curr_num_day)+':', low_word, curr_word_value, '\t', sorted_top_termFreq_set[0][0], sorted_top_termFreq_set[0][1], '\t', curr_word_value > sorted_top_termFreq_set[0][1]
|
print str(curr_num_day)+':', low_word, curr_word_value, '\t', sorted_top_termFreq_set[0][0], sorted_top_termFreq_set[0][1], '\t', curr_word_value > sorted_top_termFreq_set[0][1]
|
||||||
server_term.srem(curr_set, sorted_top_termFreq_set[0][0])
|
server_term.srem(curr_set, sorted_top_termFreq_set[0][0])
|
||||||
server_term.sadd(curr_set, low_word)
|
server_term.sadd(curr_set, low_word)
|
||||||
|
'''
|
||||||
else:
|
else:
|
||||||
if generate_new_graph:
|
if generate_new_graph:
|
||||||
generate_new_graph = False
|
generate_new_graph = False
|
||||||
|
|
128
bin/Curve_manage_top_sets.py
Executable file
128
bin/Curve_manage_top_sets.py
Executable file
|
@ -0,0 +1,128 @@
|
||||||
|
#!/usr/bin/env python2
|
||||||
|
# -*-coding:UTF-8 -*
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
zrank for each day
|
||||||
|
week -> top zrank for each day
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
*Need running Redis instances. (Redis)
|
||||||
|
*Categories files of words in /files/ need to be created
|
||||||
|
*Need the ZMQ_PubSub_Tokenize_Q Module running to be able to work properly.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import redis
|
||||||
|
import time
|
||||||
|
import copy
|
||||||
|
from pubsublogger import publisher
|
||||||
|
from packages import lib_words
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import calendar
|
||||||
|
|
||||||
|
from Helper import Process
|
||||||
|
|
||||||
|
# Config Variables
|
||||||
|
BlackListTermsSet_Name = "BlackListSetTermSet"
|
||||||
|
TrackedTermsSet_Name = "TrackedSetTermSet"
|
||||||
|
top_term_freq_max_set_cardinality = 20 # Max cardinality of the terms frequences set
|
||||||
|
oneDay = 60*60*24
|
||||||
|
num_day_month = 31
|
||||||
|
num_day_week = 7
|
||||||
|
|
||||||
|
top_termFreq_setName_day = ["TopTermFreq_set_day_", 1]
|
||||||
|
top_termFreq_setName_week = ["TopTermFreq_set_week", 7]
|
||||||
|
top_termFreq_setName_month = ["TopTermFreq_set_month", 31]
|
||||||
|
top_termFreq_set_array = [top_termFreq_setName_day,top_termFreq_setName_week, top_termFreq_setName_month]
|
||||||
|
|
||||||
|
|
||||||
|
def manage_top_set():
|
||||||
|
startDate = datetime.datetime.now()
|
||||||
|
startDate = startDate.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
startDate = calendar.timegm(startDate.timetuple())
|
||||||
|
|
||||||
|
dico = {}
|
||||||
|
|
||||||
|
# Retreive top data (2*max_card) from days sets
|
||||||
|
for timestamp in range(startDate, startDate - num_day_month*oneDay, -oneDay):
|
||||||
|
top_termFreq_setName_day[0] += str(timestamp)
|
||||||
|
array_top_day = server_term.zrangebyscore(top_termFreq_setName_day[0], '-inf', '+inf', withscores=True, start=0, num=top_term_freq_max_set_cardinality*2)
|
||||||
|
|
||||||
|
for word, value in array_top_day:
|
||||||
|
if word in dico.keys():
|
||||||
|
dico[word] += value
|
||||||
|
else:
|
||||||
|
dico[word] = value
|
||||||
|
|
||||||
|
if timestamp == startDate - num_day_week*oneDay:
|
||||||
|
dico_week = copy.deepcopy(dico)
|
||||||
|
|
||||||
|
# convert dico into sorted array
|
||||||
|
array_month = []
|
||||||
|
for w, v in dico.iteritems():
|
||||||
|
array_month.append((w, v))
|
||||||
|
array_month.sort(key=lambda tup: -tup[1])
|
||||||
|
|
||||||
|
array_week = []
|
||||||
|
for w, v in dico_week.iteritems():
|
||||||
|
array_week.append((w, v))
|
||||||
|
array_week.sort(key=lambda tup: -tup[1])
|
||||||
|
|
||||||
|
|
||||||
|
# suppress every terms in top sets
|
||||||
|
for curr_set, curr_num_day in top_termFreq_set_array[1:3]:
|
||||||
|
for w in server_term.zrange(curr_set, 0, -1):
|
||||||
|
server_term.zrem(curr_set, w)
|
||||||
|
|
||||||
|
# Add top term from sorted array in their respective sorted sets
|
||||||
|
for elem in array_week:
|
||||||
|
server_term.zadd(top_termFreq_setName_week[0], float(elem[1]), elem[0])
|
||||||
|
|
||||||
|
for elem in array_month:
|
||||||
|
server_term.zadd(top_termFreq_setName_month[0], float(elem[1]), elem[0])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# If you wish to use an other port of channel, do not forget to run a subscriber accordingly (see launch_logs.sh)
|
||||||
|
# Port of the redis instance used by pubsublogger
|
||||||
|
publisher.port = 6380
|
||||||
|
# Script is the default channel used for the modules.
|
||||||
|
publisher.channel = 'Script'
|
||||||
|
|
||||||
|
config_section = 'CurveManageTopSets'
|
||||||
|
p = Process(config_section)
|
||||||
|
|
||||||
|
server_term = redis.StrictRedis(
|
||||||
|
host=p.config.get("Redis_Level_DB_TermFreq", "host"),
|
||||||
|
port=p.config.get("Redis_Level_DB_TermFreq", "port"),
|
||||||
|
db=p.config.get("Redis_Level_DB_TermFreq", "db"))
|
||||||
|
|
||||||
|
# FUNCTIONS #
|
||||||
|
publisher.info("Script Curve_manage_top_set started")
|
||||||
|
|
||||||
|
# Sent to the logging a description of the module
|
||||||
|
publisher.info("Manage the top sets with the data created by the module curve.")
|
||||||
|
|
||||||
|
manage_top_set()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# Get one message from the input queue
|
||||||
|
message = p.get_from_set()
|
||||||
|
if message is None:
|
||||||
|
publisher.debug("{} queue is empty, waiting".format(config_section))
|
||||||
|
print 'sleeping'
|
||||||
|
time.sleep(60) # sleep a long time then manage the set
|
||||||
|
manage_top_set()
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Do something with the message from the queue
|
||||||
|
#manage_top_set()
|
||||||
|
|
|
@ -136,7 +136,9 @@ function launching_scripts {
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
screen -S "Script" -X screen -t "Credential" bash -c './Credential.py; read x'
|
screen -S "Script" -X screen -t "Credential" bash -c './Credential.py; read x'
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
#screen -S "Script" -X screen -t "Curve" bash -c './Curve.py; read x'
|
screen -S "Script" -X screen -t "Curve" bash -c './Curve.py; read x'
|
||||||
|
sleep 0.1
|
||||||
|
screen -S "Script" -X screen -t "Curve_topsets_manager" bash -c './Curve_manage_top_sets.py; read x'
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
screen -S "Script" -X screen -t "Indexer" bash -c './Indexer.py; read x'
|
screen -S "Script" -X screen -t "Indexer" bash -c './Indexer.py; read x'
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
|
@ -158,12 +160,6 @@ function launching_scripts {
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
screen -S "Script" -X screen -t "SentimentAnalyser" bash -c './SentimentAnalyser.py; read x'
|
screen -S "Script" -X screen -t "SentimentAnalyser" bash -c './SentimentAnalyser.py; read x'
|
||||||
|
|
||||||
sleep 0.1
|
|
||||||
screen -S "Script" -X screen -t "Curve" bash -c './Curve.py; read x'
|
|
||||||
sleep 0.1
|
|
||||||
screen -S "Script" -X screen -t "Curve" bash -c './Curve.py; read x'
|
|
||||||
sleep 0.1
|
|
||||||
screen -S "Script" -X screen -t "Curve" bash -c './Curve.py; read x'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#If no params, display the help
|
#If no params, display the help
|
||||||
|
|
|
@ -24,6 +24,10 @@ publish = Redis_Words
|
||||||
|
|
||||||
[Curve]
|
[Curve]
|
||||||
subscribe = Redis_Words
|
subscribe = Redis_Words
|
||||||
|
publish = Redis_CurveManageTopSets
|
||||||
|
|
||||||
|
[CurveManageTopSets]
|
||||||
|
subscribe = Redis_CurveManageTopSets
|
||||||
|
|
||||||
[Categ]
|
[Categ]
|
||||||
subscribe = Redis_Global
|
subscribe = Redis_Global
|
||||||
|
|
|
@ -227,8 +227,8 @@ def Term_getValueOverRange(word, startDate, num_day):
|
||||||
curr_to_return = 0
|
curr_to_return = 0
|
||||||
for timestamp in range(startDate, startDate - max(num_day)*oneDay, -oneDay):
|
for timestamp in range(startDate, startDate - max(num_day)*oneDay, -oneDay):
|
||||||
value = r_serv_term.hget(timestamp, word)
|
value = r_serv_term.hget(timestamp, word)
|
||||||
print timestamp, word
|
#print timestamp, word
|
||||||
print value
|
#print value
|
||||||
curr_to_return += int(value) if value is not None else 0
|
curr_to_return += int(value) if value is not None else 0
|
||||||
for i in num_day:
|
for i in num_day:
|
||||||
if passed_days == i-1:
|
if passed_days == i-1:
|
||||||
|
@ -595,11 +595,15 @@ def terms_management():
|
||||||
|
|
||||||
track_list = []
|
track_list = []
|
||||||
track_list_values = []
|
track_list_values = []
|
||||||
|
track_list_num_of_paste = []
|
||||||
for tracked_term in r_serv_term.smembers(TrackedTermsSet_Name):
|
for tracked_term in r_serv_term.smembers(TrackedTermsSet_Name):
|
||||||
track_list.append(tracked_term)
|
track_list.append(tracked_term)
|
||||||
value_range = 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 = r_serv_term.hget(TrackedTermsDate_Name, tracked_term)
|
||||||
|
|
||||||
|
set_paste_name = "tracked_" + tracked_term
|
||||||
|
track_list_num_of_paste.append(r_serv_term.scard(set_paste_name))
|
||||||
term_date = datetime.datetime.utcfromtimestamp(int(term_date)) if term_date is not None else "No date recorded"
|
term_date = datetime.datetime.utcfromtimestamp(int(term_date)) if term_date is not None else "No date recorded"
|
||||||
value_range.append(term_date)
|
value_range.append(term_date)
|
||||||
track_list_values.append(value_range)
|
track_list_values.append(value_range)
|
||||||
|
@ -609,10 +613,38 @@ def terms_management():
|
||||||
for blacked_term in r_serv_term.smembers(BlackListTermsSet_Name):
|
for blacked_term in r_serv_term.smembers(BlackListTermsSet_Name):
|
||||||
term_date = r_serv_term.hget(BlackListTermsDate_Name, 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"
|
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])
|
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)
|
return render_template("terms_management.html", black_list=black_list, track_list=track_list, track_list_values=track_list_values, track_list_num_of_paste=track_list_num_of_paste)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/terms_management_query_paste/")
|
||||||
|
def terms_management_query_paste():
|
||||||
|
term = request.args.get('term')
|
||||||
|
TrackedTermsSet_Name = "TrackedSetTermSet"
|
||||||
|
paste_info = []
|
||||||
|
|
||||||
|
set_paste_name = "tracked_" + term
|
||||||
|
track_list_path = r_serv_term.smembers(set_paste_name)
|
||||||
|
print set_paste_name
|
||||||
|
print track_list_path
|
||||||
|
|
||||||
|
for path in track_list_path:
|
||||||
|
paste = Paste.Paste(path)
|
||||||
|
p_date = str(paste._get_p_date())
|
||||||
|
p_date = p_date[6:]+'/'+p_date[4:6]+'/'+p_date[0:4]
|
||||||
|
p_source = paste.p_source
|
||||||
|
p_encoding = paste._get_p_encoding()
|
||||||
|
p_language = paste._get_p_language()
|
||||||
|
p_size = paste.p_size
|
||||||
|
p_mime = paste.p_mime
|
||||||
|
p_lineinfo = paste.get_lines_info()
|
||||||
|
p_content = paste.get_p_content().decode('utf-8', 'ignore')
|
||||||
|
if p_content != 0:
|
||||||
|
p_content = p_content[0:400]
|
||||||
|
paste_info.append({"path": path, "date": p_date, "source": p_source, "encoding": p_encoding, "language": p_language, "size": p_size, "mime": p_mime, "lineinfo": p_lineinfo, "content": p_content})
|
||||||
|
|
||||||
|
return jsonify(paste_info)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/terms_management_query/")
|
@app.route("/terms_management_query/")
|
||||||
|
@ -680,7 +712,11 @@ def terms_management_action():
|
||||||
|
|
||||||
@app.route("/terms_plot_tool/")
|
@app.route("/terms_plot_tool/")
|
||||||
def terms_plot_tool():
|
def terms_plot_tool():
|
||||||
return render_template("terms_plot_tool.html")
|
term = request.args.get('term')
|
||||||
|
if term is not None:
|
||||||
|
return render_template("terms_plot_tool.html", term=term)
|
||||||
|
else:
|
||||||
|
return render_template("terms_plot_tool.html", term="")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/terms_plot_tool_data/")
|
@app.route("/terms_plot_tool_data/")
|
||||||
|
@ -699,6 +735,7 @@ def terms_plot_tool_data():
|
||||||
else:
|
else:
|
||||||
value_range = []
|
value_range = []
|
||||||
for timestamp in range(range_start, range_end+oneDay, oneDay):
|
for timestamp in range(range_start, range_end+oneDay, oneDay):
|
||||||
|
print timestamp, term
|
||||||
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])
|
||||||
|
@ -712,6 +749,7 @@ def terms_plot_top():
|
||||||
|
|
||||||
@app.route("/terms_plot_top_data/")
|
@app.route("/terms_plot_top_data/")
|
||||||
def terms_plot_top_data():
|
def terms_plot_top_data():
|
||||||
|
oneDay = 60*60*24
|
||||||
today = datetime.datetime.now()
|
today = datetime.datetime.now()
|
||||||
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())
|
||||||
|
@ -721,7 +759,22 @@ def terms_plot_top_data():
|
||||||
if the_set is None:
|
if the_set is None:
|
||||||
return "None"
|
return "None"
|
||||||
else:
|
else:
|
||||||
oneDay = 60*60*24
|
to_return = []
|
||||||
|
if the_set == "TopTermFreq_set_day":
|
||||||
|
the_set += "_" + str(today_timestamp)
|
||||||
|
|
||||||
|
for term, tot_value in r_serv_term.zrangebyscore(the_set, '-inf', '+inf', withscores=True, start=0, num=20):
|
||||||
|
value_range = []
|
||||||
|
for timestamp in range(today_timestamp, today_timestamp - num_day*oneDay, -oneDay):
|
||||||
|
value = r_serv_term.hget(timestamp, term)
|
||||||
|
curr_value_range = int(value) if value is not None else 0
|
||||||
|
value_range.append([timestamp, curr_value_range])
|
||||||
|
|
||||||
|
to_return.append([term, value_range, tot_value])
|
||||||
|
|
||||||
|
return jsonify(to_return)
|
||||||
|
|
||||||
|
'''
|
||||||
to_return = []
|
to_return = []
|
||||||
for term in r_serv_term.smembers(the_set):
|
for term in r_serv_term.smembers(the_set):
|
||||||
value_range = []
|
value_range = []
|
||||||
|
@ -735,6 +788,7 @@ def terms_plot_top_data():
|
||||||
to_return.append([term, value_range, tot_sum])
|
to_return.append([term, value_range, tot_sum])
|
||||||
|
|
||||||
return jsonify(to_return)
|
return jsonify(to_return)
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
@app.route("/test/") #completely shows the paste in a new tab
|
@app.route("/test/") #completely shows the paste in a new tab
|
||||||
|
|
|
@ -33,6 +33,24 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<!-- Modal -->
|
||||||
|
<div id="mymodal" class="modal fade" role="dialog">
|
||||||
|
<div class="modal-dialog modal-lg">
|
||||||
|
|
||||||
|
<!-- Modal content-->
|
||||||
|
<div id="mymodalcontent" class="modal-content">
|
||||||
|
<div id="mymodalbody" class="modal-body" max-width="8500px">
|
||||||
|
<p>Loading paste information...</p>
|
||||||
|
<img id="loading-gif-modal" src="{{url_for('static', filename='image/loading.gif') }}" height="26" width="26" style="margin: 4px;">
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<a id="button_show_plot" target="_blank" href=""><button type="button" class="btn btn-info">Plot term</button></a>
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="wrapper">
|
<div id="wrapper">
|
||||||
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
|
<nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
|
||||||
{% include 'header.html' %}
|
{% include 'header.html' %}
|
||||||
|
@ -76,7 +94,7 @@
|
||||||
|
|
||||||
<div class="form-group input-group" style="margin-bottom: 30px;">
|
<div class="form-group input-group" style="margin-bottom: 30px;">
|
||||||
<span class="input-group-addon"><span class="fa fa-eye"></span></span>
|
<span class="input-group-addon"><span class="fa fa-eye"></span></span>
|
||||||
<input id="followTermInput" class="form-control" placeholder="Term to track" type="text" style="max-width: 400px;" onkeypress="return enterKeyScript(event)">
|
<input id="followTermInput" class="form-control" placeholder="Term to track" type="text" style="max-width: 400px;">
|
||||||
<button id="followTermBtn" class="btn btn-success btn-interaction" style="margin-left: 10px;" data-section="followTerm" data-action="add"> Add term</button>
|
<button id="followTermBtn" class="btn btn-success btn-interaction" style="margin-left: 10px;" data-section="followTerm" data-action="add"> Add term</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -88,6 +106,7 @@
|
||||||
<th>Day occurence</th>
|
<th>Day occurence</th>
|
||||||
<th>Week occurence</th>
|
<th>Week occurence</th>
|
||||||
<th>Month occurence</th>
|
<th>Month occurence</th>
|
||||||
|
<th># Concerned pastes</th>
|
||||||
<th>Action</th>
|
<th>Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -100,9 +119,10 @@
|
||||||
<td>{{ track_list_values[i][0] }}</td>
|
<td>{{ track_list_values[i][0] }}</td>
|
||||||
<td>{{ track_list_values[i][1] }}</td>
|
<td>{{ track_list_values[i][1] }}</td>
|
||||||
<td>{{ track_list_values[i][2] }}</td>
|
<td>{{ track_list_values[i][2] }}</td>
|
||||||
|
<td>{{ track_list_num_of_paste[i] }}</td>
|
||||||
<td><p style="margin: 0px;">
|
<td><p style="margin: 0px;">
|
||||||
<button class="btn-link" data-toggle="tooltip" data-placement="right" title="Show concerned paste(s)"><span class="glyphicon glyphicon-info-sign"></span></button>
|
<span data-toggle="modal" data-target="#mymodal" data-term="{{ term }}" ><button class="btn-link" data-toggle="tooltip" data-placement="right" title="Show concerned paste(s)"><span class="glyphicon glyphicon-info-sign"></span></button></span>
|
||||||
<button class="btn-link btn-interaction" data-toggle="tooltip" data-placement="right" title="Remove this term" data-content="{{ term }}" data-section="followTerm" data-action="delete"><span class="glyphicon glyphicon-trash"></span></button>
|
<button class="btn-link btn-interaction" data-toggle="tooltip" data-placement="left" title="Remove this term" data-content="{{ term }}" data-section="followTerm" data-action="delete"><span class="glyphicon glyphicon-trash"></span></button>
|
||||||
</p></td>
|
</p></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% set i = i + 1 %}
|
{% set i = i + 1 %}
|
||||||
|
@ -197,6 +217,66 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
perform_binding();
|
perform_binding();
|
||||||
|
|
||||||
|
// On click, get html content from url and update the corresponding modal
|
||||||
|
$("[data-toggle='modal']").on("click.openmodal", function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
var the_modal=$(this);
|
||||||
|
var url = "{{ url_for('terms_management_query_paste') }}?term=" + $(this).attr('data-term');
|
||||||
|
$.getJSON(url, function (data) {
|
||||||
|
//console.log(data);
|
||||||
|
if (data.length != 0) {
|
||||||
|
for (i=0; i<data.length; i++) {
|
||||||
|
curr_data = data[i];
|
||||||
|
var html_to_add = "";
|
||||||
|
html_to_add += "<table class=\"table table-condensed\">";
|
||||||
|
html_to_add += "<thead>";
|
||||||
|
html_to_add += "<tr>";
|
||||||
|
html_to_add += "<th>Source</th>";
|
||||||
|
html_to_add += "<th>Date</th>";
|
||||||
|
html_to_add += "<th>Encoding</th>";
|
||||||
|
html_to_add += "<th>Language</th>";
|
||||||
|
html_to_add += "<th>Size (Kb)</th>";
|
||||||
|
html_to_add += "<th>Mime</th>";
|
||||||
|
html_to_add += "<th>Number of lines</th>";
|
||||||
|
html_to_add += "<th>Max line length</th>";
|
||||||
|
html_to_add += "<th>Preview</th>";
|
||||||
|
html_to_add += "</tr>";
|
||||||
|
html_to_add += "</thead>";
|
||||||
|
html_to_add += "<tbody>";
|
||||||
|
html_to_add += "<tr>";
|
||||||
|
html_to_add += "<td>"+curr_data.source+"</td>";
|
||||||
|
html_to_add += "<td>"+curr_data.date+"</td>";
|
||||||
|
html_to_add += "<td>"+curr_data.encoding+"</td>";
|
||||||
|
html_to_add += "<td>"+curr_data.language+"</td>";
|
||||||
|
html_to_add += "<td>"+curr_data.size+"</td>";
|
||||||
|
html_to_add += "<td>"+curr_data.mime+"</td>";
|
||||||
|
html_to_add += "<td>"+curr_data.lineinfo[0]+"</td>";
|
||||||
|
html_to_add += "<td>"+curr_data.lineinfo[1]+"</td>";
|
||||||
|
html_to_add += "<td><div class=\"row\"><button class=\"btn btn-xs btn-default\" data-toggle=\"popover\" data-placement=\"left\" data-content=\""+curr_data.content+"\">Preview content</button><a target=\"_blank\" href=\"{{ url_for('showsavedpaste') }}?paste="+curr_data.path+"&num=0\"> <button type=\"button\" class=\"btn btn-xs btn-info\">Show Paste</button></a></div></td>";
|
||||||
|
|
||||||
|
html_to_add += "</tr>";
|
||||||
|
html_to_add += "</tbody>";
|
||||||
|
html_to_add += "</table>";
|
||||||
|
$("#mymodalbody").html(html_to_add);
|
||||||
|
$("[data-toggle=popover]").popover();
|
||||||
|
$("#button_show_plot").attr("href", "{{ url_for('terms_plot_tool')}}"+"?term="+the_modal.attr('data-term') );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$("#mymodalbody").html("No paste containing this term has been received yet.");
|
||||||
|
$("#button_show_plot").attr("href", "{{ url_for('terms_plot_tool')}}"+"?term="+the_modal.attr('data-term') );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#mymodal").on('hidden.bs.modal', function () {
|
||||||
|
$("#mymodalbody").html("<p>Loading paste information...</p>");
|
||||||
|
var loading_gif = "<img id='loading-gif-modal' class='img-center' src=\"{{url_for('static', filename='image/loading.gif') }}\" height='26' width='26' style='margin: 4px;'>";
|
||||||
|
$("#mymodalbody").append(loading_gif); // Show the loading GIF
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -229,8 +309,8 @@ function perform_operation(){
|
||||||
if(json.action == "add") {
|
if(json.action == "add") {
|
||||||
// query data
|
// query data
|
||||||
$.get("{{ url_for('terms_management_query') }}", { term: json.term, section: json.section }, function(data2, status){
|
$.get("{{ url_for('terms_management_query') }}", { term: json.term, section: json.section }, function(data2, status){
|
||||||
var action_button = "<button class=\"btn-link btn-interaction\" data-toggle=\"tooltip\" data-placement=\"right\" title=\"Remove this term\" data-content=\"" + json.term + "\" data-section=\"followTerm\" data-action=\"delete\"><span class=\"glyphicon glyphicon-trash\"></span></button>"
|
var action_button = "<button class=\"btn-link btn-interaction\" data-toggle=\"tooltip\" data-placement=\"left\" title=\"Remove this term\" data-content=\"" + json.term + "\" data-section=\"followTerm\" data-action=\"delete\"><span class=\"glyphicon glyphicon-trash\"></span></button>"
|
||||||
table_track.row.add( [ json.term, data2[3], data2[0], data2[1], data2[2], action_button ] ).draw( false );
|
table_track.row.add( [ json.term, data2[3], data2[0], data2[1], data2[2], 0, action_button ] ).draw( false );
|
||||||
perform_binding();
|
perform_binding();
|
||||||
});
|
});
|
||||||
} else if (json.action == "delete") {
|
} else if (json.action == "delete") {
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
|
|
||||||
<div class="form-group input-group" style="margin-top: 30px;">
|
<div class="form-group input-group" style="margin-top: 30px;">
|
||||||
<span class="input-group-addon"><span class="glyphicon glyphicon-stats"></span></span>
|
<span class="input-group-addon"><span class="glyphicon glyphicon-stats"></span></span>
|
||||||
<input id="TermInput" class="form-control" placeholder="Term to plot" type="text" style="max-width: 400px;">
|
<input id="TermInput" class="form-control" placeholder="Term to plot" type="text" style="max-width: 400px;" data-init-plot="{{ term }}">
|
||||||
<button id="plot-btn" class="btn btn-info btn-interaction" style="margin-left: 10px;" data-section="followTerm" data-action="add"> Plot a term</button>
|
<button id="plot-btn" class="btn btn-info btn-interaction" style="margin-left: 10px;" data-section="followTerm" data-action="add"> Plot a term</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -144,6 +144,9 @@
|
||||||
|
|
||||||
$('#plot-btn').click(plotData);
|
$('#plot-btn').click(plotData);
|
||||||
|
|
||||||
|
$("#TermInput").val($("#TermInput").attr("data-init-plot"));
|
||||||
|
$("#plot-btn").click();
|
||||||
|
|
||||||
$("#TermInput").keyup(function(event){
|
$("#TermInput").keyup(function(event){
|
||||||
if(event.keyCode == 13){
|
if(event.keyCode == 13){
|
||||||
$("#plot-btn").click();
|
$("#plot-btn").click();
|
||||||
|
|
|
@ -266,6 +266,7 @@
|
||||||
<!-- /#page-wrapper -->
|
<!-- /#page-wrapper -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div style="position: absolute; border: 1px solid rgb(255, 221, 221); padding: 2px; background-color: #333; color:white; opacity: 0.8; top: 423px; left: 616px; display: none;" id="tooltip"></div>
|
||||||
|
|
||||||
<!-- import graph function -->
|
<!-- import graph function -->
|
||||||
<script>
|
<script>
|
||||||
|
@ -300,6 +301,14 @@ var graph_options = {
|
||||||
yaxis: {
|
yaxis: {
|
||||||
autoscaleMargin: 0.1,
|
autoscaleMargin: 0.1,
|
||||||
},
|
},
|
||||||
|
tooltip: true,
|
||||||
|
tooltipOpts: {
|
||||||
|
content: "%s (%x.1 is %y.4)",
|
||||||
|
shifts: {
|
||||||
|
x: -60,
|
||||||
|
y: 25
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -313,8 +322,8 @@ var plot_month;
|
||||||
|
|
||||||
var promises = []; // Used to know when everything has been received
|
var promises = []; // Used to know when everything has been received
|
||||||
|
|
||||||
promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_today, num_day: 1 }, function(data, status){
|
promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_today, num_day: 5 }, function(data, status){
|
||||||
//console.log(data);
|
console.log(data);
|
||||||
data.sort(function(a, b){return b[2]-a[2];});
|
data.sort(function(a, b){return b[2]-a[2];});
|
||||||
// Sort data
|
// Sort data
|
||||||
var table_today = $("#table-today")
|
var table_today = $("#table-today")
|
||||||
|
@ -326,12 +335,27 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_today
|
||||||
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]]);
|
||||||
}
|
}
|
||||||
to_plot.push({ data: curr_data, label: data[i][0]});
|
to_plot.push({ data: curr_data, label: data[i][0]});
|
||||||
|
console.log(to_plot);
|
||||||
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])+"</td></tr>")
|
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])+"</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])+"</td></tr>")
|
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])+"</td></tr>")
|
||||||
}
|
}
|
||||||
plot_today = $.plot($("#graph-today"), to_plot, graph_options);
|
plot_today = $.plot($("#graph-today"), to_plot, graph_options);
|
||||||
|
$("#graph-today").bind("plothover", function (event, pos, item) {
|
||||||
|
if (item) {
|
||||||
|
var date = new Date(item.datapoint[0]);
|
||||||
|
var x = parseInt(date.getUTCMonth())+1 + "/" + date.getUTCDate();
|
||||||
|
var y = item.datapoint[1];
|
||||||
|
|
||||||
|
$("#tooltip").html(item.series.label + " for "+x + " = " + y)
|
||||||
|
.css({top: item.pageY+5, left: item.pageX+5})
|
||||||
|
.fadeIn(200);
|
||||||
|
} else {
|
||||||
|
$("#tooltip").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_week, num_day: 7 }, function(data, status){
|
promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_week, num_day: 7 }, function(data, status){
|
||||||
|
@ -352,6 +376,19 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_week,
|
||||||
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])+"</td></tr>")
|
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])+"</td></tr>")
|
||||||
}
|
}
|
||||||
plot_week = $.plot($("#graph-week"), to_plot, graph_options);
|
plot_week = $.plot($("#graph-week"), to_plot, graph_options);
|
||||||
|
$("#graph-week").bind("plothover", function (event, pos, item) {
|
||||||
|
if (item) {
|
||||||
|
var date = new Date(item.datapoint[0]);
|
||||||
|
var x = parseInt(date.getUTCMonth())+1 + "/" + date.getUTCDate();
|
||||||
|
var y = item.datapoint[1];
|
||||||
|
|
||||||
|
$("#tooltip").html(item.series.label + " for "+x + " = " + y)
|
||||||
|
.css({top: item.pageY+5, left: item.pageX+5})
|
||||||
|
.fadeIn(200);
|
||||||
|
} else {
|
||||||
|
$("#tooltip").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_month, num_day: 31 }, function(data, status){
|
promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_month, num_day: 31 }, function(data, status){
|
||||||
|
@ -372,6 +409,19 @@ promises.push($.getJSON("{{ url_for('terms_plot_top_data') }}", { set: set_month
|
||||||
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])+"</td></tr>")
|
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])+"</td></tr>")
|
||||||
}
|
}
|
||||||
plot_month = $.plot($("#graph-month"), to_plot, graph_options);
|
plot_month = $.plot($("#graph-month"), to_plot, graph_options);
|
||||||
|
$("#graph-month").bind("plothover", function (event, pos, item) {
|
||||||
|
if (item) {
|
||||||
|
var date = new Date(item.datapoint[0]);
|
||||||
|
var x = parseInt(date.getUTCMonth())+1 + "/" + date.getUTCDate();
|
||||||
|
var y = item.datapoint[1];
|
||||||
|
|
||||||
|
$("#tooltip").html(item.series.label + " for "+x + " = " + y)
|
||||||
|
.css({top: item.pageY+5, left: item.pageX+5})
|
||||||
|
.fadeIn(200);
|
||||||
|
} else {
|
||||||
|
$("#tooltip").hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
/* When everything has been received, start adding tooltip */
|
/* When everything has been received, start adding tooltip */
|
||||||
|
@ -417,6 +467,7 @@ function hide_or_show() {
|
||||||
|
|
||||||
if(graph == "today") {
|
if(graph == "today") {
|
||||||
var graphData = plot_today.getData();
|
var graphData = plot_today.getData();
|
||||||
|
console.log(graphData);
|
||||||
var index;
|
var index;
|
||||||
for(i=0; i<graphData.length; i++){
|
for(i=0; i<graphData.length; i++){
|
||||||
if(graphData[i].label == curr_term){
|
if(graphData[i].label == curr_term){
|
||||||
|
|
Loading…
Reference in a new issue