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
|
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
|
from django.db.models.functions import Abs, TruncMonth
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,12 +36,16 @@ def history(transaction_set):
|
||||||
return {
|
return {
|
||||||
"data": _data,
|
"data": _data,
|
||||||
"max": {
|
"max": {
|
||||||
"pm": max(
|
"pm": 125
|
||||||
_history.aggregate(
|
* max(
|
||||||
max=Avg("sum_p", default=0) + StdDev("sum_p", default=0),
|
_history.order_by("-sum_p")[len(_history) // 10]["sum_p"],
|
||||||
min=Avg("sum_m", default=0) - StdDev("sum_m", default=0),
|
_history.order_by("-sum_m")[len(_history) // 10]["sum_m"],
|
||||||
).values(),
|
)
|
||||||
),
|
/ 100,
|
||||||
"sum": _history.aggregate(max=Avg(Abs("sum")) + StdDev(Abs("sum")))["max"],
|
"sum": 125
|
||||||
|
* _history.annotate(abs_sum=Abs("sum")).order_by("-abs_sum")[
|
||||||
|
len(_history) // 10
|
||||||
|
]["abs_sum"]
|
||||||
|
/ 100,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue