mirror of
https://github.com/DarkflameUniverse/NexusDashboard.git
synced 2024-11-09 19:58:19 +00:00
parent
6606f1558e
commit
24e98190fe
@ -75,14 +75,14 @@ def create_app():
|
||||
if cdclient is not None:
|
||||
cdclient.close()
|
||||
|
||||
@app.errorhandler(Exception)
|
||||
def handle_exception(e):
|
||||
app.logger.error(e)
|
||||
# pass through HTTP errors
|
||||
if isinstance(e, HTTPException):
|
||||
return e
|
||||
# now you're handling non-HTTP exceptions only
|
||||
return render_template("status_codes/500.html.j2", exception=e), 500
|
||||
# @app.errorhandler(Exception)
|
||||
# def handle_exception(e):
|
||||
# app.logger.error(e)
|
||||
# # pass through HTTP errors
|
||||
# if isinstance(e, HTTPException):
|
||||
# return e
|
||||
# # now you're handling non-HTTP exceptions only
|
||||
# return render_template("status_codes/500.html.j2", exception=e), 500
|
||||
|
||||
# add the commands to flask cli
|
||||
app.cli.add_command(init_db)
|
||||
@ -193,7 +193,7 @@ def register_settings(app):
|
||||
'APP_DATABASE_URI',
|
||||
app.config['APP_DATABASE_URI']
|
||||
)
|
||||
if app.config['SECRET_KEY'] is "" or "<database>" in app.config['APP_DATABASE_URI']:
|
||||
if app.config['SECRET_KEY'] == "" or "<database>" in app.config['APP_DATABASE_URI']:
|
||||
raise("No database uri or secret Key")
|
||||
# try to get overides, otherwise just use what we have already
|
||||
app.config['USER_ENABLE_REGISTER'] = os.getenv(
|
||||
|
@ -199,6 +199,19 @@ def translate_from_locale(trans_string):
|
||||
return trans_string
|
||||
|
||||
|
||||
def get_lot_name(lot_id):
|
||||
name = translate_from_locale(f'Objects_{lot_id}_name')
|
||||
if name == f'Objects_{lot_id}_name':
|
||||
intermed = query_cdclient(
|
||||
'select * from Objects where id = ?',
|
||||
[lot_id],
|
||||
one=True
|
||||
)
|
||||
if intermed:
|
||||
name = intermed[7] if (intermed[7] != "None" and intermed[7] != "" and intermed[7] is None) else intermed[1]
|
||||
return name
|
||||
|
||||
|
||||
def register_luclient_jinja_helpers(app):
|
||||
|
||||
@app.template_filter('get_zone_name')
|
||||
@ -237,17 +250,8 @@ def register_luclient_jinja_helpers(app):
|
||||
return None
|
||||
|
||||
@app.template_filter('get_lot_name')
|
||||
def get_lot_name(lot_id):
|
||||
name = translate_from_locale(f'Objects_{lot_id}_name')
|
||||
if name == f'Objects_{lot_id}_name':
|
||||
intermed = query_cdclient(
|
||||
'select * from Objects where id = ?',
|
||||
[lot_id],
|
||||
one=True
|
||||
)
|
||||
if intermed:
|
||||
name = intermed[7] if (intermed[7] != "None" and intermed[7] != "" and intermed[7] is None) else intermed[1]
|
||||
return name
|
||||
def jinja_get_lot_name(lot_id):
|
||||
return get_lot_name(lot_id)
|
||||
|
||||
@app.template_filter('get_lot_rarity')
|
||||
def get_lot_rarity(lot_id):
|
||||
|
141
app/reports.py
141
app/reports.py
@ -1,9 +1,12 @@
|
||||
from flask import render_template, Blueprint, current_app
|
||||
from flask_user import login_required
|
||||
from app.models import CharacterInfo, Account, CharacterXML, Reports
|
||||
from app.luclient import get_lot_name
|
||||
from app import gm_level, scheduler
|
||||
from sqlalchemy.orm import load_only
|
||||
import datetime
|
||||
import xmltodict
|
||||
import random
|
||||
|
||||
reports_blueprint = Blueprint('reports', __name__)
|
||||
|
||||
@ -12,8 +15,30 @@ reports_blueprint = Blueprint('reports', __name__)
|
||||
@login_required
|
||||
@gm_level(3)
|
||||
def index():
|
||||
reports = Reports.query.distinct(Reports.date).group_by(Reports.date).all()
|
||||
return render_template('reports/index.html.j2', reports=reports)
|
||||
reports_items = Reports.query.distinct(
|
||||
Reports.date
|
||||
).filter(
|
||||
Reports.report_type == "items"
|
||||
).group_by(Reports.date).options(load_only(Reports.date)).all()
|
||||
|
||||
reports_currency = Reports.query.distinct(
|
||||
Reports.date
|
||||
).filter(
|
||||
Reports.report_type == "currency"
|
||||
).group_by(Reports.date).options(load_only(Reports.date)).all()
|
||||
|
||||
reports_uscore = Reports.query.distinct(
|
||||
Reports.date
|
||||
).filter(
|
||||
Reports.report_type == "uscore"
|
||||
).group_by(Reports.date).options(load_only(Reports.date)).all()
|
||||
|
||||
return render_template(
|
||||
'reports/index.html.j2',
|
||||
reports_items=reports_items,
|
||||
reports_currency=reports_currency,
|
||||
reports_uscore=reports_uscore,
|
||||
)
|
||||
|
||||
|
||||
@reports_blueprint.route('/items/by_date/<date>', methods=['GET', 'POST'])
|
||||
@ -24,6 +49,46 @@ def items_by_date(date):
|
||||
return render_template('reports/items/by_date.html.j2', data=data, date=date)
|
||||
|
||||
|
||||
@reports_blueprint.route('/items/graph', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@gm_level(3)
|
||||
def items_graph():
|
||||
thirty_days_ago = datetime.date.today() - datetime.timedelta(days=30)
|
||||
entries = Reports.query.filter(
|
||||
Reports.report_type == "items"
|
||||
).filter(Reports.date >= thirty_days_ago).all()
|
||||
# transform data for chartjs
|
||||
labels = []
|
||||
items = dict()
|
||||
datasets = []
|
||||
# get stuff ready
|
||||
for entry in entries:
|
||||
labels.append(entry.date.strftime("%m/%d/%Y"))
|
||||
for key in entry.data:
|
||||
items[key] = get_lot_name(key)
|
||||
# make it
|
||||
for key, value in items.items():
|
||||
data = []
|
||||
for entry in entries:
|
||||
if key in entry.data.keys():
|
||||
data.append(entry.data[key])
|
||||
else:
|
||||
data.append(0)
|
||||
color = "#" + ''.join([random.choice('ABCDEF0123456789') for i in range(6)])
|
||||
datasets.append({
|
||||
"label": value,
|
||||
"data": data,
|
||||
"backgroundColor": color,
|
||||
"borderColor": color
|
||||
})
|
||||
|
||||
return render_template(
|
||||
'reports/graph.html.j2',
|
||||
labels=labels,
|
||||
datasets=datasets,
|
||||
name="Item"
|
||||
)
|
||||
|
||||
@reports_blueprint.route('/currency/by_date/<date>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@gm_level(3)
|
||||
@ -32,6 +97,42 @@ def currency_by_date(date):
|
||||
return render_template('reports/currency/by_date.html.j2', data=data, date=date)
|
||||
|
||||
|
||||
@reports_blueprint.route('/currency/graph', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@gm_level(3)
|
||||
def currency_graph():
|
||||
thirty_days_ago = datetime.date.today() - datetime.timedelta(days=30)
|
||||
entries = Reports.query.filter(
|
||||
Reports.report_type == "currency"
|
||||
).filter(Reports.date >= thirty_days_ago).all()
|
||||
characters = CharacterInfo.query.options(load_only(CharacterInfo.name)).all()
|
||||
labels = []
|
||||
datasets = []
|
||||
# get stuff ready
|
||||
for entry in entries:
|
||||
labels.append(entry.date.strftime("%m/%d/%Y"))
|
||||
for character in characters:
|
||||
data = []
|
||||
for entry in entries:
|
||||
if character.name in entry.data.keys():
|
||||
data.append(entry.data[character.name])
|
||||
else:
|
||||
data.append(0)
|
||||
color = "#" + ''.join([random.choice('ABCDEF0123456789') for i in range(6)])
|
||||
datasets.append({
|
||||
"label": character.name,
|
||||
"data": data,
|
||||
"backgroundColor": color,
|
||||
"borderColor": color
|
||||
})
|
||||
return render_template(
|
||||
'reports/graph.html.j2',
|
||||
labels=labels,
|
||||
datasets=datasets,
|
||||
name="Currency"
|
||||
)
|
||||
|
||||
|
||||
@reports_blueprint.route('/uscore/by_date/<date>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@gm_level(3)
|
||||
@ -40,6 +141,42 @@ def uscore_by_date(date):
|
||||
return render_template('reports/uscore/by_date.html.j2', data=data, date=date)
|
||||
|
||||
|
||||
@reports_blueprint.route('/uscore/graph', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@gm_level(3)
|
||||
def uscore_graph():
|
||||
thirty_days_ago = datetime.date.today() - datetime.timedelta(days=30)
|
||||
entries = Reports.query.filter(
|
||||
Reports.report_type == "uscore"
|
||||
).filter(Reports.date >= thirty_days_ago).all()
|
||||
characters = CharacterInfo.query.options(load_only(CharacterInfo.name)).all()
|
||||
labels = []
|
||||
datasets = []
|
||||
# get stuff ready
|
||||
for entry in entries:
|
||||
labels.append(entry.date.strftime("%m/%d/%Y"))
|
||||
for character in characters:
|
||||
data = []
|
||||
for entry in entries:
|
||||
if character.name in entry.data.keys():
|
||||
data.append(entry.data[character.name])
|
||||
else:
|
||||
data.append(0)
|
||||
color = "#" + ''.join([random.choice('ABCDEF0123456789') for i in range(6)])
|
||||
datasets.append({
|
||||
"label": character.name,
|
||||
"data": data,
|
||||
"backgroundColor": color,
|
||||
"borderColor": color
|
||||
})
|
||||
return render_template(
|
||||
'reports/graph.html.j2',
|
||||
labels=labels,
|
||||
datasets=datasets,
|
||||
name="U-Score"
|
||||
)
|
||||
|
||||
|
||||
@scheduler.task("cron", id="gen_item_report", hour=23, timezone="UTC")
|
||||
def gen_item_report():
|
||||
with scheduler.app.app_context():
|
||||
|
37
app/templates/reports/graph.html.j2
Normal file
37
app/templates/reports/graph.html.j2
Normal file
@ -0,0 +1,37 @@
|
||||
{% extends 'base.html.j2' %}
|
||||
|
||||
{% block title %}
|
||||
{{name}} History for the Last 30 Days
|
||||
{% endblock title %}
|
||||
|
||||
{% block content_before %}
|
||||
{{name}} History for the Last 30 Days
|
||||
{% endblock content_before %}
|
||||
|
||||
{% block content %}
|
||||
<canvas id="item_chart"></canvas>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
{{ super () }}
|
||||
<script type="text/javascript" src="{{ url_for('static', filename='chartjs/chart.min.js') }}"></script>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
let config = {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: {{labels}},
|
||||
datasets: {{datasets}},
|
||||
},
|
||||
options: {
|
||||
plugins: { legend: { display: false }, }
|
||||
}
|
||||
};
|
||||
let items_chart = new Chart(
|
||||
document.getElementById('item_chart'),
|
||||
config
|
||||
);
|
||||
}
|
||||
);
|
||||
</script>
|
||||
{% endblock %}
|
@ -11,8 +11,12 @@
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
Items: <br/>
|
||||
{% for report in reports|reverse %}
|
||||
Items:
|
||||
<a role="button" class="btn btn-primary btn btn-block"
|
||||
href='{{url_for('reports.items_graph')}}'>
|
||||
Graph
|
||||
</a><br/>
|
||||
{% for report in reports_items|reverse %}
|
||||
<a role="button" class="btn btn-primary btn btn-block"
|
||||
href='{{url_for('reports.items_by_date', date=report.date)}}'>
|
||||
{{report.date}}
|
||||
@ -20,8 +24,12 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="col">
|
||||
Currency: <br/>
|
||||
{% for report in reports|reverse %}
|
||||
Currency:
|
||||
<a role="button" class="btn btn-primary btn btn-block"
|
||||
href='{{url_for('reports.currency_graph')}}'>
|
||||
Graph
|
||||
</a><br/>
|
||||
{% for report in reports_currency|reverse %}
|
||||
<a role="button" class="btn btn-primary btn btn-block"
|
||||
href='{{url_for('reports.currency_by_date', date=report.date)}}'>
|
||||
{{report.date}}
|
||||
@ -29,8 +37,12 @@
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="col">
|
||||
U-Score: <br/>
|
||||
{% for report in reports|reverse %}
|
||||
U-Score:
|
||||
<a role="button" class="btn btn-primary btn btn-block"
|
||||
href='{{url_for('reports.uscore_graph')}}'>
|
||||
Graph
|
||||
</a><br/>
|
||||
{% for report in reports_uscore|reverse %}
|
||||
<a role="button" class="btn btn-primary btn btn-block"
|
||||
href='{{url_for('reports.uscore_by_date', date=report.date)}}'>
|
||||
{{report.date}}
|
||||
|
Loading…
Reference in New Issue
Block a user