2018-05-04 11:53:29 +00:00
|
|
|
#!/usr/bin/env python3
|
2016-12-09 07:46:37 +00:00
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
'''
|
|
|
|
Flask functions and routes for the trending charts page
|
|
|
|
'''
|
2022-11-28 14:01:40 +00:00
|
|
|
import os
|
|
|
|
import sys
|
2016-12-09 07:46:37 +00:00
|
|
|
import datetime
|
|
|
|
import flask
|
2017-04-19 09:02:03 +00:00
|
|
|
from flask import Flask, render_template, jsonify, request, Blueprint
|
2019-06-19 15:02:09 +00:00
|
|
|
|
2019-11-20 15:15:08 +00:00
|
|
|
from Role_Manager import login_admin, login_analyst, login_read_only
|
2019-05-02 15:31:14 +00:00
|
|
|
from flask_login import login_required
|
2016-12-09 07:46:37 +00:00
|
|
|
|
2022-11-28 14:01:40 +00:00
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from packages.Date import Date
|
|
|
|
|
2016-12-09 07:46:37 +00:00
|
|
|
# ============ VARIABLES ============
|
|
|
|
import Flask_config
|
|
|
|
|
|
|
|
app = Flask_config.app
|
2019-10-28 12:48:43 +00:00
|
|
|
config_loader = Flask_config.config_loader
|
2018-09-20 08:38:19 +00:00
|
|
|
baseUrl = Flask_config.baseUrl
|
2016-12-09 07:46:37 +00:00
|
|
|
r_serv_charts = Flask_config.r_serv_charts
|
2017-04-19 09:02:03 +00:00
|
|
|
|
|
|
|
trendings = Blueprint('trendings', __name__, template_folder='templates')
|
|
|
|
|
2016-12-09 07:46:37 +00:00
|
|
|
# ============ FUNCTIONS ============
|
|
|
|
|
|
|
|
def get_date_range(num_day):
|
|
|
|
curr_date = datetime.date.today()
|
|
|
|
date = Date(str(curr_date.year)+str(curr_date.month).zfill(2)+str(curr_date.day).zfill(2))
|
|
|
|
date_list = []
|
|
|
|
|
|
|
|
for i in range(0, num_day+1):
|
|
|
|
date_list.append(date.substract_day(i))
|
2018-04-17 14:06:32 +00:00
|
|
|
|
2016-12-09 07:46:37 +00:00
|
|
|
return date_list
|
|
|
|
|
|
|
|
|
|
|
|
# ============ ROUTES ============
|
|
|
|
|
2017-04-19 09:02:03 +00:00
|
|
|
@trendings.route("/_progressionCharts", methods=['GET'])
|
2019-05-02 15:31:14 +00:00
|
|
|
@login_required
|
2019-11-20 15:15:08 +00:00
|
|
|
@login_read_only
|
2016-12-09 07:46:37 +00:00
|
|
|
def progressionCharts():
|
|
|
|
attribute_name = request.args.get('attributeName')
|
|
|
|
trending_name = request.args.get('trendingName')
|
|
|
|
bar_requested = True if request.args.get('bar') == "true" else False
|
|
|
|
|
|
|
|
if (bar_requested):
|
|
|
|
num_day = int(request.args.get('days'))
|
|
|
|
bar_values = []
|
|
|
|
|
|
|
|
date_range = get_date_range(num_day)
|
|
|
|
# Retreive all data from the last num_day
|
|
|
|
for date in date_range:
|
2018-05-04 11:53:29 +00:00
|
|
|
|
2016-12-09 07:46:37 +00:00
|
|
|
curr_value = r_serv_charts.hget(attribute_name, date)
|
|
|
|
bar_values.append([date[0:4]+'/'+date[4:6]+'/'+date[6:8], int(curr_value if curr_value is not None else 0)])
|
|
|
|
bar_values.insert(0, attribute_name)
|
|
|
|
return jsonify(bar_values)
|
|
|
|
|
|
|
|
else:
|
|
|
|
redis_progression_name = "z_top_progression_" + trending_name
|
|
|
|
keyw_value = r_serv_charts.zrevrangebyscore(redis_progression_name, '+inf', '-inf', withscores=True, start=0, num=10)
|
2018-04-17 14:06:32 +00:00
|
|
|
|
2018-05-04 11:53:29 +00:00
|
|
|
return jsonify(keyw_value)
|
2016-12-09 07:46:37 +00:00
|
|
|
|
2017-04-19 09:02:03 +00:00
|
|
|
@trendings.route("/wordstrending/")
|
2019-05-02 15:31:14 +00:00
|
|
|
@login_required
|
2019-11-20 15:15:08 +00:00
|
|
|
@login_read_only
|
2016-12-09 07:46:37 +00:00
|
|
|
def wordstrending():
|
2019-10-28 12:48:43 +00:00
|
|
|
default_display = config_loader.get_config_str("Flask", "default_display")
|
2016-12-09 07:46:37 +00:00
|
|
|
return render_template("Wordstrending.html", default_display = default_display)
|
|
|
|
|
|
|
|
|
2017-04-19 09:02:03 +00:00
|
|
|
@trendings.route("/protocolstrending/")
|
2019-05-02 15:31:14 +00:00
|
|
|
@login_required
|
2019-11-20 15:15:08 +00:00
|
|
|
@login_read_only
|
2016-12-09 07:46:37 +00:00
|
|
|
def protocolstrending():
|
2019-10-28 12:48:43 +00:00
|
|
|
default_display = config_loader.get_config_str("Flask", "default_display")
|
2016-12-09 07:46:37 +00:00
|
|
|
return render_template("Protocolstrending.html", default_display = default_display)
|
|
|
|
|
|
|
|
|
2017-04-19 09:02:03 +00:00
|
|
|
@trendings.route("/trending/")
|
2019-05-02 15:31:14 +00:00
|
|
|
@login_required
|
2019-11-20 15:15:08 +00:00
|
|
|
@login_read_only
|
2016-12-09 07:46:37 +00:00
|
|
|
def trending():
|
2019-10-28 12:48:43 +00:00
|
|
|
default_display = config_loader.get_config_str("Flask", "default_display")
|
2016-12-09 07:46:37 +00:00
|
|
|
return render_template("Trending.html", default_display = default_display)
|
|
|
|
|
|
|
|
|
2017-04-19 09:02:03 +00:00
|
|
|
# ========= REGISTRATION =========
|
2018-09-20 08:38:19 +00:00
|
|
|
app.register_blueprint(trendings, url_prefix=baseUrl)
|