update exchange detection logic
Marco Andronaco andronacomarco@gmail.com
Sun, 06 Oct 2024 14:33:42 +0200
3 files changed,
3 insertions(+),
14 deletions(-)
M
src/app/init.go
→
src/app/init.go
@@ -43,11 +43,6 @@ }
if bookmakersAmount == 0 { InsertSampleData() } - - err = DB.Model(&Bookmaker{}).Where("default_commission > 0").Pluck("id", &ExchangeIDs).Error - if err != nil { - log.Println("could not get exchange ids: " + err.Error()) - } } func InsertSampleData() {
M
src/app/records.go
→
src/app/records.go
@@ -43,7 +43,7 @@ if e.Won == nil || e.Odds == nil {
log.Fatalf("please, update e.Won and e.Odds first") } - if IsExchange(e.BookmakerID) { + if e.Bookmaker.IsExchange() { r := (int(e.Amount) * (int(*e.Odds) - 100)) / 100 if *e.Won { value = int(e.Amount) - int(e.Amount)*int(e.Commission)/10000
M
src/app/utils.go
→
src/app/utils.go
@@ -1,7 +1,5 @@
package app -var ExchangeIDs []uint - func IndexOf[T comparable](slice []T, element T) int { for i, el := range slice { if el == element {@@ -11,10 +9,6 @@ }
return -1 } -func Contains[T comparable](slice []T, element T) bool { - return IndexOf(slice, element) != -1 -} - -func IsExchange(bookmakerID uint) bool { - return Contains(ExchangeIDs, bookmakerID) +func (b Bookmaker) IsExchange() bool { + return b.DefaultCommission != 0 }