fix: [UI term] remove deprecated trending charts, fix #446 #447

This commit is contained in:
Terrtia 2020-01-09 11:12:58 +01:00
parent 354a4fef7d
commit 91ce045d91
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
3 changed files with 98 additions and 100 deletions

View file

@ -150,105 +150,106 @@ def save_tag_to_auto_push(list_tag):
# ============ ROUTES ============ # ============ ROUTES ============
# TODO: remove + clean
@terms.route("/terms_plot_tool/") # @terms.route("/terms_plot_tool/")
@login_required # @login_required
@login_read_only # @login_read_only
def terms_plot_tool(): # def terms_plot_tool():
term = request.args.get('term') # term = request.args.get('term')
if term is not None: # if term is not None:
return render_template("terms_plot_tool.html", term=term) # return render_template("terms_plot_tool.html", term=term)
else: # else:
return render_template("terms_plot_tool.html", term="") # return render_template("terms_plot_tool.html", term="")
#
#
# @terms.route("/terms_plot_tool_data/")
# @login_required
# @login_read_only
# def terms_plot_tool_data():
# oneDay = 60*60*24
# range_start = datetime.datetime.utcfromtimestamp(int(float(request.args.get('range_start')))) if request.args.get('range_start') is not None else 0;
# range_start = range_start.replace(hour=0, minute=0, second=0, microsecond=0)
# range_start = calendar.timegm(range_start.timetuple())
# range_end = datetime.datetime.utcfromtimestamp(int(float(request.args.get('range_end')))) if request.args.get('range_end') is not None else 0;
# range_end = range_end.replace(hour=0, minute=0, second=0, microsecond=0)
# range_end = calendar.timegm(range_end.timetuple())
# term = request.args.get('term')
#
# per_paste = request.args.get('per_paste')
# if per_paste == "1" or per_paste is None:
# per_paste = "per_paste_"
# else:
# per_paste = ""
#
# if term is None:
# return "None"
#
# else:
# value_range = []
# for timestamp in range(range_start, range_end+oneDay, oneDay):
# value = r_serv_term.hget(per_paste+str(timestamp), term)
# curr_value_range = int(value) if value is not None else 0
# value_range.append([timestamp, curr_value_range])
# value_range.insert(0,term)
# return jsonify(value_range)
#
# @terms.route("/terms_plot_top/"
@terms.route("/terms_plot_tool_data/") # @login_required
@login_required # @login_read_only
@login_read_only # def terms_plot_top():
def terms_plot_tool_data(): # per_paste = request.args.get('per_paste')
oneDay = 60*60*24 # per_paste = per_paste if per_paste is not None else 1
range_start = datetime.datetime.utcfromtimestamp(int(float(request.args.get('range_start')))) if request.args.get('range_start') is not None else 0; # return render_template("terms_plot_top.html", per_paste=per_paste)
range_start = range_start.replace(hour=0, minute=0, second=0, microsecond=0) #
range_start = calendar.timegm(range_start.timetuple()) #
range_end = datetime.datetime.utcfromtimestamp(int(float(request.args.get('range_end')))) if request.args.get('range_end') is not None else 0; # @terms.route("/terms_plot_top_data/")
range_end = range_end.replace(hour=0, minute=0, second=0, microsecond=0) # @login_required
range_end = calendar.timegm(range_end.timetuple()) # @login_read_only
term = request.args.get('term') # def terms_plot_top_data():
# oneDay = 60*60*24
per_paste = request.args.get('per_paste') # today = datetime.datetime.now()
if per_paste == "1" or per_paste is None: # today = today.replace(hour=0, minute=0, second=0, microsecond=0)
per_paste = "per_paste_" # today_timestamp = calendar.timegm(today.timetuple())
else: #
per_paste = "" # per_paste = request.args.get('per_paste')
# if per_paste == "1" or per_paste is None:
if term is None: # per_paste = "per_paste_"
return "None" # else:
# per_paste = ""
else: #
value_range = [] # set_day = per_paste + "TopTermFreq_set_day_" + str(today_timestamp)
for timestamp in range(range_start, range_end+oneDay, oneDay): # set_week = per_paste + "TopTermFreq_set_week";
value = r_serv_term.hget(per_paste+str(timestamp), term) # set_month = per_paste + "TopTermFreq_set_month";
curr_value_range = int(value) if value is not None else 0 #
value_range.append([timestamp, curr_value_range]) # the_set = per_paste + request.args.get('set')
value_range.insert(0,term) # num_day = int(request.args.get('num_day'))
return jsonify(value_range) #
# if the_set is None:
# return "None"
@terms.route("/terms_plot_top/") # else:
@login_required # to_return = []
@login_read_only # if "TopTermFreq_set_day" in the_set:
def terms_plot_top(): # the_set += "_" + str(today_timestamp)
per_paste = request.args.get('per_paste') #
per_paste = per_paste if per_paste is not None else 1 # for term, tot_value in r_serv_term.zrevrangebyscore(the_set, '+inf', '-inf', withscores=True, start=0, num=20):
return render_template("terms_plot_top.html", per_paste=per_paste) # position = {}
# position['day'] = r_serv_term.zrevrank(set_day, term)
# position['day'] = position['day']+1 if position['day'] is not None else "<20"
@terms.route("/terms_plot_top_data/") # position['week'] = r_serv_term.zrevrank(set_week, term)
@login_required # position['week'] = position['week']+1 if position['week'] is not None else "<20"
@login_read_only # position['month'] = r_serv_term.zrevrank(set_month, term)
def terms_plot_top_data(): # position['month'] = position['month']+1 if position['month'] is not None else "<20"
oneDay = 60*60*24 # value_range = []
today = datetime.datetime.now() # for timestamp in range(today_timestamp, today_timestamp - num_day*oneDay, -oneDay):
today = today.replace(hour=0, minute=0, second=0, microsecond=0) # value = r_serv_term.hget(per_paste+str(timestamp), term)
today_timestamp = calendar.timegm(today.timetuple()) # curr_value_range = int(value) if value is not None else 0
# value_range.append([timestamp, curr_value_range])
per_paste = request.args.get('per_paste') #
if per_paste == "1" or per_paste is None: # to_return.append([term, value_range, tot_value, position])
per_paste = "per_paste_" #
else: # return jsonify(to_return)
per_paste = ""
set_day = per_paste + "TopTermFreq_set_day_" + str(today_timestamp)
set_week = per_paste + "TopTermFreq_set_week";
set_month = per_paste + "TopTermFreq_set_month";
the_set = per_paste + request.args.get('set')
num_day = int(request.args.get('num_day'))
if the_set is None:
return "None"
else:
to_return = []
if "TopTermFreq_set_day" in the_set:
the_set += "_" + str(today_timestamp)
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 = []
for timestamp in range(today_timestamp, today_timestamp - num_day*oneDay, -oneDay):
value = r_serv_term.hget(per_paste+str(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, position])
return jsonify(to_return)
@terms.route("/credentials_tracker/") @terms.route("/credentials_tracker/")

View file

@ -2,7 +2,5 @@
<span class="caret"></span></a> <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="{{ url_for('terms.credentials_tracker') }}"><i class="glyphicon glyphicon-screenshot"> </i> Credentials seeker</a></li> <li><a href="{{ url_for('terms.credentials_tracker') }}"><i class="glyphicon glyphicon-screenshot"> </i> Credentials seeker</a></li>
<li><a href="{{ url_for('terms.terms_plot_top') }}"><i class="glyphicon glyphicon-fire"> </i> Terms plot top</a></li>
<li><a href="{{ url_for('terms.terms_plot_tool') }}"><i class="fa fa-wrench"> </i> Terms plot tool</a></li>
</ul> </ul>
</li> </li>

View file

@ -1 +0,0 @@
<li id='page-trendingchart'><a href="{{ url_for('trendings.trending') }}"><i class="glyphicon glyphicon-stats"></i> Trending charts</a></li>