add migration for numberOfRebuys and compute function to calculate it

feature/top10
Razmig Sarkissian 7 years ago
parent 623d6ae38f
commit 3c3ebcece3
  1. 13
      app/src/main/java/net/pokeranalytics/android/model/migrations/PokerAnalyticsMigration.kt
  2. 21
      app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt

@ -60,7 +60,9 @@ class PokerAnalyticsMigration : RealmMigration {
}
schema.get("Session")?.let {
it.addField("blinds", String::class.java)
it.addField("blinds", String::class.java).transform {
}
}
schema.get("FilterCondition")?.let {
@ -89,6 +91,15 @@ class PokerAnalyticsMigration : RealmMigration {
currentVersion++
}
// Migrate to version 3
if (currentVersion == 3) {
Timber.d("*** Running migration ${currentVersion + 1}")
schema.get("Result")?.let {
it.addField("numberOfRebuy", Double::class.java).setNullable("numberOfRebuy", true)
}
currentVersion++
}
}
override fun equals(other: Any?): Boolean {

@ -87,7 +87,7 @@ open class Result : RealmObject(), Filterable {
var tournamentFinalPosition: Int? = null
// Number of rebuys
//var numberOfRebuy: Double? = null
var numberOfRebuy: Double? = null
@LinkingObjects("result")
private val sessions: RealmResults<Session>? = null
@ -123,6 +123,25 @@ open class Result : RealmObject(), Filterable {
// Computes the number of rebuy
private fun computeNumberOfRebuy() {
this.session?.let {
if (it.isCashGame()) {
it.cgBigBlind?.let { bb ->
if (bb > 0.0) {
this.numberOfRebuy = (this.buyin ?: 0.0) / bb
} else {
this.numberOfRebuy = null
}
}
} else {
it.tournamentEntryFee?.let { entryFee ->
if (entryFee > 0.0) {
this.numberOfRebuy = (this.buyin ?: 0.0) / entryFee
} else {
this.numberOfRebuy = null
}
}
}
}
}
// @todo tips?

Loading…
Cancel
Save