This commit is contained in:
Aaron Kimbre 2022-05-14 08:53:23 -05:00
parent 3668ca8792
commit ded0e55501
3 changed files with 118 additions and 45 deletions

View File

@ -49,14 +49,15 @@ def items_by_date(date):
return render_template('reports/items/by_date.html.j2', data=data, date=date) return render_template('reports/items/by_date.html.j2', data=data, date=date)
@reports_blueprint.route('/items/graph', methods=['GET', 'POST']) @reports_blueprint.route('/items/graph/<start>/<end>', methods=['GET', 'POST'])
@login_required @login_required
@gm_level(3) @gm_level(3)
def items_graph(): def items_graph(start, end):
thirty_days_ago = datetime.date.today() - datetime.timedelta(days=30) start_date = datetime.date.today() - datetime.timedelta(weeks=int(start))
end_date = datetime.date.today() - datetime.timedelta(weeks=int(end))
entries = Reports.query.filter( entries = Reports.query.filter(
Reports.report_type == "items" Reports.report_type == "items"
).filter(Reports.date >= thirty_days_ago).all() ).filter(Reports.date.between(start_date, end_date)).all()
# transform data for chartjs # transform data for chartjs
labels = [] labels = []
items = dict() items = dict()
@ -74,7 +75,8 @@ def items_graph():
data.append(entry.data[key]) data.append(entry.data[key])
else: else:
data.append(0) data.append(0)
color = "#" + ''.join([random.choice('ABCDEF0123456789') for i in range(6)]) color = "#" + value.encode("utf-8").hex()[1:7]
if max(data) > 10:
datasets.append({ datasets.append({
"label": value, "label": value,
"data": data, "data": data,
@ -86,9 +88,15 @@ def items_graph():
'reports/graph.html.j2', 'reports/graph.html.j2',
labels=labels, labels=labels,
datasets=datasets, datasets=datasets,
name="Item" name="Item",
start=start,
end=end,
data_type="items",
start_date=start_date,
end_date=end_date
) )
@reports_blueprint.route('/currency/by_date/<date>', methods=['GET', 'POST']) @reports_blueprint.route('/currency/by_date/<date>', methods=['GET', 'POST'])
@login_required @login_required
@gm_level(3) @gm_level(3)
@ -97,14 +105,15 @@ def currency_by_date(date):
return render_template('reports/currency/by_date.html.j2', data=data, date=date) return render_template('reports/currency/by_date.html.j2', data=data, date=date)
@reports_blueprint.route('/currency/graph', methods=['GET', 'POST']) @reports_blueprint.route('/currency/graph/<start>/<end>', methods=['GET', 'POST'])
@login_required @login_required
@gm_level(3) @gm_level(3)
def currency_graph(): def currency_graph(start, end):
thirty_days_ago = datetime.date.today() - datetime.timedelta(days=30) start_date = datetime.date.today() - datetime.timedelta(weeks=int(start))
end_date = datetime.date.today() - datetime.timedelta(weeks=int(end))
entries = Reports.query.filter( entries = Reports.query.filter(
Reports.report_type == "currency" Reports.report_type == "currency"
).filter(Reports.date >= thirty_days_ago).all() ).filter(Reports.date.between(start_date, end_date)).all()
characters = CharacterInfo.query.options(load_only(CharacterInfo.name)).all() characters = CharacterInfo.query.options(load_only(CharacterInfo.name)).all()
labels = [] labels = []
datasets = [] datasets = []
@ -118,7 +127,8 @@ def currency_graph():
data.append(entry.data[character.name]) data.append(entry.data[character.name])
else: else:
data.append(0) data.append(0)
color = "#" + ''.join([random.choice('ABCDEF0123456789') for i in range(6)]) color = "#" + character.name.encode("utf-8").hex()[1:7]
if max(data) > 10000:
datasets.append({ datasets.append({
"label": character.name, "label": character.name,
"data": data, "data": data,
@ -129,7 +139,12 @@ def currency_graph():
'reports/graph.html.j2', 'reports/graph.html.j2',
labels=labels, labels=labels,
datasets=datasets, datasets=datasets,
name="Currency" name="Currency",
start=start,
end=end,
data_type="currency",
start_date=start_date,
end_date=end_date
) )
@ -141,14 +156,15 @@ def uscore_by_date(date):
return render_template('reports/uscore/by_date.html.j2', data=data, date=date) return render_template('reports/uscore/by_date.html.j2', data=data, date=date)
@reports_blueprint.route('/uscore/graph', methods=['GET', 'POST']) @reports_blueprint.route('/uscore/graph/<start>/<end>', methods=['GET', 'POST'])
@login_required @login_required
@gm_level(3) @gm_level(3)
def uscore_graph(): def uscore_graph(start, end):
thirty_days_ago = datetime.date.today() - datetime.timedelta(days=30) start_date = datetime.date.today() - datetime.timedelta(weeks=int(start))
end_date = datetime.date.today() - datetime.timedelta(weeks=int(end))
entries = Reports.query.filter( entries = Reports.query.filter(
Reports.report_type == "uscore" Reports.report_type == "uscore"
).filter(Reports.date >= thirty_days_ago).all() ).filter(Reports.date.between(start_date, end_date)).all()
characters = CharacterInfo.query.options(load_only(CharacterInfo.name)).all() characters = CharacterInfo.query.options(load_only(CharacterInfo.name)).all()
labels = [] labels = []
datasets = [] datasets = []
@ -162,7 +178,8 @@ def uscore_graph():
data.append(entry.data[character.name]) data.append(entry.data[character.name])
else: else:
data.append(0) data.append(0)
color = "#" + ''.join([random.choice('ABCDEF0123456789') for i in range(6)]) color = "#" + character.name.encode("utf-8").hex()[1:7]
if max(data) > 1000:
datasets.append({ datasets.append({
"label": character.name, "label": character.name,
"data": data, "data": data,
@ -173,7 +190,12 @@ def uscore_graph():
'reports/graph.html.j2', 'reports/graph.html.j2',
labels=labels, labels=labels,
datasets=datasets, datasets=datasets,
name="U-Score" name="U-Score",
start=start,
end=end,
data_type="uscore",
start_date=start_date,
end_date=end_date
) )

View File

@ -1,14 +1,65 @@
{% extends 'base.html.j2' %} {% extends 'base.html.j2' %}
{% block title %} {% block title %}
{{ name }} History for the Last 30 Days {{ name }} History for {{start_date}} to {{end_date}}
{% endblock title %} {% endblock title %}
{% block content_before %} {% block content_before %}
{{ name }} History for the Last 30 Days {{ name }} History for {{start_date}} to {{end_date}}
{% endblock content_before %} {% endblock content_before %}
{% block content %} {% block content %}
<div class ="row">
{% if data_type == "items" %}
<div class="col">
<a role="button" class="btn btn-primary btn btn-block"
href='{{url_for('reports.items_graph', start=(start|int+1), end=(end|int+1))}}'>
Previous
</a>
</div>
{% if end|int > 0 %}
<div class="col">
<a role="button" class="btn btn-primary btn btn-block"
href='{{url_for('reports.items_graph', start=(start|int-1), end=(end|int-1))}}'>
Next
</a>
</div>
{% endif %}
{% elif data_type == "currency" %}
<div class="col">
<a role="button" class="btn btn-primary btn btn-block"
href='{{url_for('reports.currency_graph', start=(start|int+1), end=(end|int+1))}}'>
Previous
</a>
</div>
{% if end|int > 0 %}
<div class="col">
<a role="button" class="btn btn-primary btn btn-block"
href='{{url_for('reports.currency_graph', start=(start|int-1), end=(end|int-1))}}'>
Next
</a>
</div>
{% endif %}
{% elif data_type == "uscore" %}
<div class="col">
<a role="button" class="btn btn-primary btn btn-block"
href='{{url_for('reports.uscore_graph', start=(start|int+1), end=(end|int+1))}}'>
Previous
</a>
</div>
{% if end|int > 0 %}
<div class="col">
<a role="button" class="btn btn-primary btn btn-block"
href='{{url_for('reports.uscore_graph', start=(start|int-1), end=(end|int-1))}}'>
Next
</a>
</div>
{% endif %}
{% else %}
<h1> INVALID DATA TYPE </h1>
{% endif %}
</div>
<hr/>
<canvas id="item_chart"></canvas> <canvas id="item_chart"></canvas>
{% endblock %} {% endblock %}
@ -27,18 +78,18 @@
plugins: { legend: { display: false }, }, plugins: { legend: { display: false }, },
scales: { scales: {
x: { x: {
display: true,
title: { title: {
display: true, display: true,
text: 'Date' text: 'Date'
}, }
display: true
}, },
y: { y: {
display: true, display: true,
title: { title: {
display: true, display: true,
text: '{{ name }}' text: '{{ name }}'
}, }
} }
} }
} }

View File

@ -13,7 +13,7 @@
<div class="col"> <div class="col">
Items: Items:
<a role="button" class="btn btn-primary btn btn-block" <a role="button" class="btn btn-primary btn btn-block"
href='{{url_for('reports.items_graph')}}'> href='{{url_for('reports.items_graph', start=1, end=0)}}'>
Graph Graph
</a><br/> </a><br/>
{% for report in reports_items|reverse %} {% for report in reports_items|reverse %}
@ -26,7 +26,7 @@
<div class="col"> <div class="col">
Currency: Currency:
<a role="button" class="btn btn-primary btn btn-block" <a role="button" class="btn btn-primary btn btn-block"
href='{{url_for('reports.currency_graph')}}'> href='{{url_for('reports.currency_graph', start=1, end=0)}}'>
Graph Graph
</a><br/> </a><br/>
{% for report in reports_currency|reverse %} {% for report in reports_currency|reverse %}
@ -39,7 +39,7 @@
<div class="col"> <div class="col">
U-Score: U-Score:
<a role="button" class="btn btn-primary btn btn-block" <a role="button" class="btn btn-primary btn btn-block"
href='{{url_for('reports.uscore_graph')}}'> href='{{url_for('reports.uscore_graph', start=1, end=0)}}'>
Graph Graph
</a><br/> </a><br/>
{% for report in reports_uscore|reverse %} {% for report in reports_uscore|reverse %}