Improve history view with outliers

This commit is contained in:
Edgar P. Burkhart 2024-12-30 16:57:00 +01:00
parent 46ea394422
commit a3e598acb6
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
4 changed files with 43 additions and 43 deletions

View file

@ -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>

View file

@ -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

View file

@ -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"],
},
}

View file

@ -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 {