no predict contributions if less than 2 balances
This commit is contained in:
@@ -55,6 +55,9 @@ func registerWithContributionPredictionForNameForCurrency(reg Register, window t
|
||||
sort.Slice(contributions, func(i, j int) bool {
|
||||
return contributions[i].t.Before(contributions[j].t)
|
||||
})
|
||||
if len(contributions) < 2 {
|
||||
return nil
|
||||
}
|
||||
|
||||
getMedianValueDelta := func(contributions []contribution) float64 {
|
||||
values := make([]float64, len(contributions))
|
||||
@@ -72,10 +75,17 @@ func registerWithContributionPredictionForNameForCurrency(reg Register, window t
|
||||
slices.Sort(lapses)
|
||||
return lapses[len(lapses)/2]
|
||||
}
|
||||
contributsSlice := func(percent float64) []contribution {
|
||||
wouldBe := int(percent * float64(len(contributions)))
|
||||
if wouldBe == 0 {
|
||||
wouldBe = 2
|
||||
}
|
||||
return contributions[len(contributions)-wouldBe:]
|
||||
}
|
||||
|
||||
eighth := contributions[int(7.0*len(contributions)/8.0):]
|
||||
quarter := contributions[int(3.0*len(contributions)/4.0):]
|
||||
half := contributions[int(1.0*len(contributions)/2.0):]
|
||||
eighth := contributsSlice(7.0 / 8.0)
|
||||
quarter := contributsSlice(3.0 / 4.0)
|
||||
half := contributsSlice(1.0 / 2.0)
|
||||
medianValueDelta := func() float64 {
|
||||
return (4.0*getMedianValueDelta(eighth) + 2.0*getMedianValueDelta(quarter) + 1.0*getMedianValueDelta(half)) / (4.0 + 2.0 + 1.0)
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user