Improve history view with outliers
This commit is contained in:
parent
46ea394422
commit
a3e598acb6
4 changed files with 43 additions and 43 deletions
|
@ -2,6 +2,43 @@
|
|||
{% load history_extras %}
|
||||
{% load transaction_extras %}
|
||||
{% load i18n %}
|
||||
<div class="calendar">
|
||||
<table class="full-width">
|
||||
<thead>
|
||||
<tr>
|
||||
{% if not year %}
|
||||
<th scope="col">{% translate "Year" %}</th>
|
||||
{% endif %}
|
||||
{% calendar_head %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% regroup history.data by month.year as years_list %}
|
||||
{% for y, y_data in years_list reversed %}
|
||||
<tr>
|
||||
{% if not year %}
|
||||
<th class="date" scope="row">{% year_url y %}</th>
|
||||
{% endif %}
|
||||
{% for m in y_data %}
|
||||
{% if forloop.parentloop.last and forloop.first %}
|
||||
{% empty_calendar_cells_start m.month.month %}
|
||||
{% endif %}
|
||||
{% if m %}
|
||||
<td class="{% if m.sum > 0 %}p{% else %}m{% endif %}"
|
||||
style="--opacity: {% calendar_opacity m.sum history.max.sum %}"
|
||||
title="{{ m.sum|pmrvalue }}">{% up_down_icon m.sum %}</td>
|
||||
{% else %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
{% if forloop.parentloop.first and forloop.last %}
|
||||
{% empty_calendar_cells_end m.month.month %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="history plot">
|
||||
<table class="full-width">
|
||||
<colgroup>
|
||||
|
@ -47,40 +84,3 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="calendar">
|
||||
<table class="full-width">
|
||||
<thead>
|
||||
<tr>
|
||||
{% if not year %}
|
||||
<th scope="col">{% translate "Year" %}</th>
|
||||
{% endif %}
|
||||
{% calendar_head %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% regroup history.data by month.year as years_list %}
|
||||
{% for y, y_data in years_list reversed %}
|
||||
<tr>
|
||||
{% if not year %}
|
||||
<th class="date" scope="row">{% year_url y %}</th>
|
||||
{% endif %}
|
||||
{% for m in y_data %}
|
||||
{% if forloop.parentloop.last and forloop.first %}
|
||||
{% empty_calendar_cells_start m.month.month %}
|
||||
{% endif %}
|
||||
{% if m %}
|
||||
<td class="{% if m.sum > 0 %}p{% else %}m{% endif %}"
|
||||
style="--opacity: {% calendar_opacity m.sum history.max.sum %}"
|
||||
title="{{ m.sum|pmrvalue }}">{% up_down_icon m.sum %}</td>
|
||||
{% else %}
|
||||
<td></td>
|
||||
{% endif %}
|
||||
{% if forloop.parentloop.first and forloop.last %}
|
||||
{% empty_calendar_cells_end m.month.month %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
@ -9,7 +9,7 @@ register = template.Library()
|
|||
|
||||
@register.simple_tag
|
||||
def calendar_opacity(v, vmax):
|
||||
return f"{math.sin(math.fabs(v/vmax)*math.pi/2):.0%}"
|
||||
return f"{math.sin(min(1, math.fabs(v/vmax))*math.pi/2):.0%}"
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import datetime
|
||||
|
||||
from django.db.models import Max, Min, Q, Sum
|
||||
from django.db.models import Avg, Q, StdDev, Sum
|
||||
from django.db.models.functions import Abs, TruncMonth
|
||||
|
||||
|
||||
|
@ -38,10 +38,10 @@ def history(transaction_set):
|
|||
"max": {
|
||||
"pm": max(
|
||||
_history.aggregate(
|
||||
max=Max("sum_p", default=0),
|
||||
min=-Min("sum_m", default=0),
|
||||
max=Avg("sum_p", default=0) + StdDev("sum_p", default=0),
|
||||
min=Avg("sum_m", default=0) - StdDev("sum_m", default=0),
|
||||
).values(),
|
||||
),
|
||||
"sum": _history.aggregate(max=Max(Abs("sum")))["max"],
|
||||
"sum": _history.aggregate(max=Avg(Abs("sum")) + StdDev(Abs("sum")))["max"],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ table.full-width col.bar {
|
|||
.calendar {
|
||||
overflow-x: auto;
|
||||
|
||||
margin-top: var(--gap);
|
||||
margin-bottom: var(--gap);
|
||||
font-feature-settings: var(--num);
|
||||
|
||||
table {
|
||||
|
|
Loading…
Reference in a new issue