Fixes issue with net computation for online tournaments

od
Laurent 6 years ago
parent 58b0077cca
commit 561bfd8b1c
  1. 29
      app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt

@ -30,7 +30,7 @@ open class Result : RealmObject(), Filterable {
set(value) {
field = value
this.computeNumberOfRebuy()
this.computeNet()
this.computeNet(true)
}
/**
@ -39,7 +39,7 @@ open class Result : RealmObject(), Filterable {
var cashout: Double? = null
set(value) {
field = value
this.computeNet()
this.computeNet(true)
if (value != null) {
this.session?.end()
}
@ -60,9 +60,9 @@ open class Result : RealmObject(), Filterable {
}
field = value
this.computeNet()
this.computeNet(false)
if (value != null) {
this.session.end()
this.session?.end()
}
}
@ -103,12 +103,27 @@ open class Result : RealmObject(), Filterable {
val isPositive: Int = if (this.net >= 0.0) 1 else 0
// Computes the Net
private fun computeNet() {
private fun computeNet(withBuyin: Boolean? = null) {
val transactionsSum = transactions.sumByDouble { it.amount }
val isLive = this.session?.isLive ?: true
if (isLive) {
// choose the method to compute the net
var useBuyin = withBuyin ?: true
if (withBuyin == null) {
if (netResult != null) {
useBuyin = false
} else if (buyin != null || cashout != null) {
useBuyin = true
} else {
this.session?.let { session ->
if (session.isCashGame() && !session.isLive) {
useBuyin = false
}
}
}
}
if (useBuyin) {
val buyin = this.buyin ?: 0.0
val cashOut = this.cashout ?: 0.0
this.net = cashOut - buyin + transactionsSum

Loading…
Cancel
Save