Improve history view using tenth centile times 125% for min max
This commit is contained in:
parent
28ac9c8ef7
commit
5d6bd9ea2b
1 changed files with 12 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
import datetime
|
||||
|
||||
from django.db.models import Avg, Q, StdDev, Sum
|
||||
from django.db.models import Q, Sum
|
||||
from django.db.models.functions import Abs, TruncMonth
|
||||
|
||||
|
||||
|
@ -36,12 +36,16 @@ def history(transaction_set):
|
|||
return {
|
||||
"data": _data,
|
||||
"max": {
|
||||
"pm": max(
|
||||
_history.aggregate(
|
||||
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=Avg(Abs("sum")) + StdDev(Abs("sum")))["max"],
|
||||
"pm": 125
|
||||
* max(
|
||||
_history.order_by("-sum_p")[len(_history) // 10]["sum_p"],
|
||||
_history.order_by("-sum_m")[len(_history) // 10]["sum_m"],
|
||||
)
|
||||
/ 100,
|
||||
"sum": 125
|
||||
* _history.annotate(abs_sum=Abs("sum")).order_by("-abs_sum")[
|
||||
len(_history) // 10
|
||||
]["abs_sum"]
|
||||
/ 100,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue