mirror of
https://github.com/DarkflameUniverse/NexusDashboard.git
synced 2024-11-21 21:17:23 +00:00
Resolves #33
This commit is contained in:
parent
3668ca8792
commit
ded0e55501
@ -49,14 +49,15 @@ 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'])
|
||||
@reports_blueprint.route('/items/graph/<start>/<end>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@gm_level(3)
|
||||
def items_graph():
|
||||
thirty_days_ago = datetime.date.today() - datetime.timedelta(days=30)
|
||||
def items_graph(start, end):
|
||||
start_date = datetime.date.today() - datetime.timedelta(weeks=int(start))
|
||||
end_date = datetime.date.today() - datetime.timedelta(weeks=int(end))
|
||||
entries = Reports.query.filter(
|
||||
Reports.report_type == "items"
|
||||
).filter(Reports.date >= thirty_days_ago).all()
|
||||
).filter(Reports.date.between(start_date, end_date)).all()
|
||||
# transform data for chartjs
|
||||
labels = []
|
||||
items = dict()
|
||||
@ -74,21 +75,28 @@ def items_graph():
|
||||
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
|
||||
})
|
||||
color = "#" + value.encode("utf-8").hex()[1:7]
|
||||
if max(data) > 10:
|
||||
datasets.append({
|
||||
"label": value,
|
||||
"data": data,
|
||||
"backgroundColor": color,
|
||||
"borderColor": color
|
||||
})
|
||||
|
||||
return render_template(
|
||||
'reports/graph.html.j2',
|
||||
labels=labels,
|
||||
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'])
|
||||
@login_required
|
||||
@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)
|
||||
|
||||
|
||||
@reports_blueprint.route('/currency/graph', methods=['GET', 'POST'])
|
||||
@reports_blueprint.route('/currency/graph/<start>/<end>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@gm_level(3)
|
||||
def currency_graph():
|
||||
thirty_days_ago = datetime.date.today() - datetime.timedelta(days=30)
|
||||
def currency_graph(start, end):
|
||||
start_date = datetime.date.today() - datetime.timedelta(weeks=int(start))
|
||||
end_date = datetime.date.today() - datetime.timedelta(weeks=int(end))
|
||||
entries = Reports.query.filter(
|
||||
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()
|
||||
labels = []
|
||||
datasets = []
|
||||
@ -118,18 +127,24 @@ def currency_graph():
|
||||
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
|
||||
})
|
||||
color = "#" + character.name.encode("utf-8").hex()[1:7]
|
||||
if max(data) > 10000:
|
||||
datasets.append({
|
||||
"label": character.name,
|
||||
"data": data,
|
||||
"backgroundColor": color,
|
||||
"borderColor": color
|
||||
})
|
||||
return render_template(
|
||||
'reports/graph.html.j2',
|
||||
labels=labels,
|
||||
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)
|
||||
|
||||
|
||||
@reports_blueprint.route('/uscore/graph', methods=['GET', 'POST'])
|
||||
@reports_blueprint.route('/uscore/graph/<start>/<end>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@gm_level(3)
|
||||
def uscore_graph():
|
||||
thirty_days_ago = datetime.date.today() - datetime.timedelta(days=30)
|
||||
def uscore_graph(start, end):
|
||||
start_date = datetime.date.today() - datetime.timedelta(weeks=int(start))
|
||||
end_date = datetime.date.today() - datetime.timedelta(weeks=int(end))
|
||||
entries = Reports.query.filter(
|
||||
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()
|
||||
labels = []
|
||||
datasets = []
|
||||
@ -162,18 +178,24 @@ def uscore_graph():
|
||||
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
|
||||
})
|
||||
color = "#" + character.name.encode("utf-8").hex()[1:7]
|
||||
if max(data) > 1000:
|
||||
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"
|
||||
name="U-Score",
|
||||
start=start,
|
||||
end=end,
|
||||
data_type="uscore",
|
||||
start_date=start_date,
|
||||
end_date=end_date
|
||||
)
|
||||
|
||||
|
||||
|
@ -1,14 +1,65 @@
|
||||
{% extends 'base.html.j2' %}
|
||||
|
||||
{% block title %}
|
||||
{{ name }} History for the Last 30 Days
|
||||
{{ name }} History for {{start_date}} to {{end_date}}
|
||||
{% endblock title %}
|
||||
|
||||
{% block content_before %}
|
||||
{{ name }} History for the Last 30 Days
|
||||
{{ name }} History for {{start_date}} to {{end_date}}
|
||||
{% endblock content_before %}
|
||||
|
||||
{% 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>
|
||||
{% endblock %}
|
||||
|
||||
@ -27,18 +78,18 @@
|
||||
plugins: { legend: { display: false }, },
|
||||
scales: {
|
||||
x: {
|
||||
display: true,
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Date'
|
||||
},
|
||||
display: true
|
||||
}
|
||||
},
|
||||
y: {
|
||||
display: true,
|
||||
title: {
|
||||
title: {
|
||||
display: true,
|
||||
text: '{{ name }}'
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
<div class="col">
|
||||
Items:
|
||||
<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
|
||||
</a><br/>
|
||||
{% for report in reports_items|reverse %}
|
||||
@ -26,7 +26,7 @@
|
||||
<div class="col">
|
||||
Currency:
|
||||
<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
|
||||
</a><br/>
|
||||
{% for report in reports_currency|reverse %}
|
||||
@ -39,7 +39,7 @@
|
||||
<div class="col">
|
||||
U-Score:
|
||||
<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
|
||||
</a><br/>
|
||||
{% for report in reports_uscore|reverse %}
|
||||
|
Loading…
Reference in New Issue
Block a user