|
|
|
|
@ -33,10 +33,7 @@ import net.pokeranalytics.android.ui.graph.Graph |
|
|
|
|
import net.pokeranalytics.android.ui.view.* |
|
|
|
|
import net.pokeranalytics.android.ui.view.rows.SessionPropertiesRow |
|
|
|
|
import net.pokeranalytics.android.util.* |
|
|
|
|
import net.pokeranalytics.android.util.extensions.hourMinute |
|
|
|
|
import net.pokeranalytics.android.util.extensions.shortDateTime |
|
|
|
|
import net.pokeranalytics.android.util.extensions.toCurrency |
|
|
|
|
import net.pokeranalytics.android.util.extensions.toMinutes |
|
|
|
|
import net.pokeranalytics.android.util.extensions.* |
|
|
|
|
import java.lang.ref.WeakReference |
|
|
|
|
import java.text.DateFormat |
|
|
|
|
import java.text.NumberFormat |
|
|
|
|
@ -163,10 +160,19 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
var result: Result? = null |
|
|
|
|
|
|
|
|
|
@LinkingObjects("session") |
|
|
|
|
private val computableResults: RealmResults<ComputableResult>? = null |
|
|
|
|
private val managedComputableResults: RealmResults<ComputableResult>? = null |
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
|
val computableResult: ComputableResult? = this.computableResults?.firstOrNull() |
|
|
|
|
val managedComputableResult: ComputableResult? = this.managedComputableResults?.firstOrNull() |
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
|
var inverseComputableResult: WeakReference<ComputableResult>? = null |
|
|
|
|
|
|
|
|
|
// @Ignore |
|
|
|
|
fun computableResult() : ComputableResult? { |
|
|
|
|
return this.inverseComputableResult?.get() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Timed interface |
|
|
|
|
|
|
|
|
|
@ -488,22 +494,29 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
*/ |
|
|
|
|
fun computeStats() { |
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
val currentComputableResult = realm.computableResult(this) |
|
|
|
|
|
|
|
|
|
// ComputableResult are created only when a session is over |
|
|
|
|
if (this.startDate != null && this.endDate != null && this.computableResults?.size == 0) { |
|
|
|
|
val computableResult = realm.createObject(ComputableResult::class.java) |
|
|
|
|
if (this.startDate != null && this.endDate != null && currentComputableResult == null && this.inverseComputableResult?.get() == null) { |
|
|
|
|
val computableResult = ComputableResult() |
|
|
|
|
computableResult.session = this |
|
|
|
|
this.inverseComputableResult = WeakReference(computableResult) |
|
|
|
|
} // if a ComputableResult exists and the session is not completed, delete it |
|
|
|
|
else if ((this.startDate == null || this.endDate == null) && this.computableResult != null && this.computableResult.isValid) { |
|
|
|
|
this.computableResult.deleteFromRealm() |
|
|
|
|
else if ((this.startDate == null || this.endDate == null) && currentComputableResult != null && currentComputableResult.isValid) { |
|
|
|
|
currentComputableResult.deleteFromRealm() |
|
|
|
|
} |
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
this.computableResult()?.updateWith(this) |
|
|
|
|
|
|
|
|
|
// Update the ComputableResult |
|
|
|
|
this.computableResults?.forEachIndexed { index, computableResult -> |
|
|
|
|
computableResult.updateWith(this) |
|
|
|
|
if (index > 0) { |
|
|
|
|
throw PAIllegalStateException("Session cannot have more than one computable result") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// this.computableResult()?.forEachIndexed { index, computableResult -> |
|
|
|
|
// computableResult.updateWith(this) |
|
|
|
|
// if (index > 0) { |
|
|
|
|
// throw PAIllegalStateException("Session cannot have more than one computable result") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
this.sessionSet?.computeStats() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -759,7 +772,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
} |
|
|
|
|
// cleanup unnecessary related objects |
|
|
|
|
this.result?.deleteFromRealm() |
|
|
|
|
this.computableResults?.deleteAllFromRealm() |
|
|
|
|
this.computableResult()?.deleteFromRealm() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1017,7 +1030,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
var right: TextFormat? = null |
|
|
|
|
|
|
|
|
|
if (!hasMainCurrencyCode) { |
|
|
|
|
this.computableResult?.ratedNet?.let { ratedNet -> |
|
|
|
|
this.managedComputableResult?.ratedNet?.let { ratedNet -> |
|
|
|
|
right = Stat.NET_RESULT.textFormat(ratedNet) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -1105,33 +1118,6 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
this.result?.netResult = null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Stakes |
|
|
|
|
|
|
|
|
|
// fun generateStakes() { |
|
|
|
|
// |
|
|
|
|
// if (this.cgAnte == null && this.cgAnte == null) { |
|
|
|
|
// this.cgStakes = null |
|
|
|
|
// return |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// val components = arrayListOf<String>() |
|
|
|
|
// |
|
|
|
|
// this.cgBlinds?.let { components.add("${cbBlinds}${it}") } |
|
|
|
|
// this.cgAnte?.let { components.add("${cbAnte}${it.formatted}") } |
|
|
|
|
// |
|
|
|
|
// val code = this.bankroll?.currency?.code ?: UserDefaults.currency.currencyCode |
|
|
|
|
// components.add("${cbCode}${code}") |
|
|
|
|
// |
|
|
|
|
// this.cgStakes = components.joinToString(cbSeparator) |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// fun defineHighestBet() { |
|
|
|
|
// val bets = arrayListOf<Double>() |
|
|
|
|
// this.cgAnte?.let { bets.add(it) } |
|
|
|
|
// bets.addAll(this.blindValues) |
|
|
|
|
// this.cgBiggestBet = bets.maxOrNull() |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
private fun cleanupBlinds(blinds: String?): String? { |
|
|
|
|
|
|
|
|
|
if (blinds == null) { |
|
|
|
|
|