From 3c3ebcece3b679774c54a63d1196cdc80ddc08b1 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Thu, 25 Apr 2019 15:04:14 +0200 Subject: [PATCH] add migration for numberOfRebuys and compute function to calculate it --- .../migrations/PokerAnalyticsMigration.kt | 13 +++++++++++- .../android/model/realm/Result.kt | 21 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/model/migrations/PokerAnalyticsMigration.kt b/app/src/main/java/net/pokeranalytics/android/model/migrations/PokerAnalyticsMigration.kt index 81fb9afe..44755ecc 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/migrations/PokerAnalyticsMigration.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/migrations/PokerAnalyticsMigration.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 { diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt index df768729..21987895 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt @@ -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? = 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?