Adds ratedTips field to ComputableResult + changed isPositive for tournaments

blinds
Laurent 5 years ago
parent 3a6a93b0be
commit c19aca865c
  1. 2
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 22
      app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt
  3. 10
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  4. 21
      app/src/main/java/net/pokeranalytics/android/model/migrations/Patcher.kt
  5. 6
      app/src/main/java/net/pokeranalytics/android/model/migrations/PokerAnalyticsMigration.kt
  6. 4
      app/src/main/java/net/pokeranalytics/android/model/realm/ComputableResult.kt
  7. 10
      app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt
  8. 1
      app/src/main/java/net/pokeranalytics/android/util/Preferences.kt

@ -47,7 +47,7 @@ class PokerAnalyticsApplication : Application() {
Realm.init(this)
val realmConfiguration = RealmConfiguration.Builder()
.name(Realm.DEFAULT_REALM_NAME)
.schemaVersion(10)
.schemaVersion(11)
.migration(PokerAnalyticsMigration())
.initialData(Seed(this))
.build()

@ -264,6 +264,10 @@ class Calculator {
val totalBuyin = computables.sum(ComputableResult.Field.RATED_BUYIN.identifier).toDouble()
results.addStat(TOTAL_BUYIN, totalBuyin)
val totalTips = computables.sum(ComputableResult.Field.RATED_TIPS.identifier).toDouble()
results.addStat(TOTAL_TIPS, totalTips)
// Timber.d("########## totalBuyin = ${totalBuyin} ### sum = ${sum}")
val maxNetResult = computables.max(ComputableResult.Field.RATED_NET.identifier)?.toDouble()
@ -283,12 +287,12 @@ class Calculator {
results.addStat(ROI, roi)
}
val shouldComputeITMRatio = options.stats.contains(TOURNAMENT_ITM_RATIO) || computableGroup.displayedStats?.contains(TOURNAMENT_ITM_RATIO) == true
if (shouldComputeITMRatio) {
val itmCount = computables.count { it.session?.result?.cashout ?: 0.0 > 0.0 } // should we add a property inside ComputableResult for better performance?
val itmRatio = itmCount.toDouble() / computables.size.toDouble()
results.addStat(TOURNAMENT_ITM_RATIO, itmRatio)
}
// val shouldComputeITMRatio = options.stats.contains(TOURNAMENT_ITM_RATIO) || computableGroup.displayedStats?.contains(TOURNAMENT_ITM_RATIO) == true
// if (shouldComputeITMRatio) {
// val itmCount = computables.count { it.session?.result?.cashout ?: 0.0 > 0.0 } // should we add a property inside ComputableResult for better performance?
// val itmRatio = itmCount.toDouble() / computables.size.toDouble()
// results.addStat(TOURNAMENT_ITM_RATIO, itmRatio)
// }
if (options.computeLocationsPlayed) {
results.addStat(LOCATIONS_PLAYED, computables.distinctBy { it.session?.location?.id }.size.toDouble())
@ -298,12 +302,14 @@ class Calculator {
if (computables.size > 0) {
average = sum / computables.size.toDouble()
val winRatio = winningSessionCount.toDouble() / computables.size.toDouble()
val itmRatio = winningSessionCount.toDouble() / computables.size.toDouble()
val avgBuyin = totalBuyin / computables.size.toDouble()
results.addStats(
setOf(
ComputedStat(AVERAGE, average),
ComputedStat(WIN_RATIO, winRatio),
ComputedStat(TOURNAMENT_ITM_RATIO, itmRatio),
ComputedStat(AVERAGE_BUYIN, avgBuyin)
)
)
@ -338,11 +344,9 @@ class Calculator {
tBBSum += computable.bbNet
tBBSessionCount += computable.hasBigBlind
tWinningSessionCount += computable.isPositive
tITMCount += computable.isPositive
tBuyinSum += computable.ratedBuyin
tHands += computable.estimatedHands
if (shouldComputeITMRatio && computable.session?.result?.cashout ?: 0.0 > 0.0) {
tITMCount++
}
if (computable.isPositive == 1) { // positive result
if (currentStreak >= 0) { // currently positive streak

@ -53,7 +53,8 @@ enum class Stat(override var uniqueIdentifier: Int) : IntIdentifiable, RowRepres
TOTAL_BUYIN(27),
RISK_OF_RUIN(28),
STANDARD_DEVIATION_BB(29),
TOURNAMENT_ITM_RATIO(30)
TOURNAMENT_ITM_RATIO(30),
TOTAL_TIPS(31)
;
companion object : IntSearchable<Stat> {
@ -131,6 +132,7 @@ enum class Stat(override var uniqueIdentifier: Int) : IntIdentifiable, RowRepres
DAYS_PLAYED -> R.string.days_played
TOTAL_BUYIN -> R.string.total_buyin
TOURNAMENT_ITM_RATIO -> R.string.itm_ratio
TOTAL_TIPS -> R.string.total_tips
else -> throw PAIllegalStateException("Stat ${this.name} name required but undefined")
}
}
@ -171,9 +173,9 @@ enum class Stat(override var uniqueIdentifier: Int) : IntIdentifiable, RowRepres
val color = if (value * 100 <= this.threshold) R.color.green else R.color.red
return TextFormat("${(value * 100).formatted}%", color)
}
// white amountsr
// white amounts
AVERAGE_BUYIN, STANDARD_DEVIATION, STANDARD_DEVIATION_HOURLY,
STANDARD_DEVIATION_BB_PER_100_HANDS, STANDARD_DEVIATION_BB, TOTAL_BUYIN -> {
STANDARD_DEVIATION_BB_PER_100_HANDS, STANDARD_DEVIATION_BB, TOTAL_BUYIN, TOTAL_TIPS -> {
return TextFormat(value.toCurrency(currency))
}
LONGEST_STREAKS -> {
@ -243,7 +245,7 @@ enum class Stat(override var uniqueIdentifier: Int) : IntIdentifiable, RowRepres
return when (this) {
HOURLY_DURATION, AVERAGE_HOURLY_DURATION, STANDARD_DEVIATION_BB,
STANDARD_DEVIATION, STANDARD_DEVIATION_HOURLY, HANDS_PLAYED,
STANDARD_DEVIATION_BB_PER_100_HANDS -> false
STANDARD_DEVIATION_BB_PER_100_HANDS, TOTAL_TIPS -> false
else -> true
}
}

@ -14,10 +14,12 @@ class Patcher {
companion object {
fun patchAll(context: Context) {
patchMissingTransactionTypes(context)
patchSessionSet()
patchMissingTransactionTypes(context)
Preferences.executeOnce(Preferences.Keys.PATCH_COMPUTABLE_RESULTS, context) {
patchComputableResults()
}
Preferences.executeOnce(Preferences.Keys.PATCH_SESSION_SETS, context) {
patchSessionSet()
}
@ -139,6 +141,21 @@ class Patcher {
realm.close()
}
/*
15/04/21: Two needs:
- To get better performance for ITM Ratio, a positive session is a net >= 0 for cash game, or a cashedOut > 0 for tournaments
- The field "ratedTips" is added
*/
private fun patchComputableResults() {
val realm = Realm.getDefaultInstance()
realm.executeTransaction {
val crs = realm.where(ComputableResult::class.java).findAll()
crs.forEach { cr ->
cr.session?.let { cr.updateWith(it) }
}
}
realm.close()
}
}
}

@ -246,6 +246,12 @@ class PokerAnalyticsMigration : RealmMigration {
currentVersion++
}
// Migrate to version 11
if (currentVersion == 10) {
schema.get("ComputableResult")?.addField("ratedTips", Double::class.java)
currentVersion++
}
}
override fun equals(other: Any?): Boolean {

@ -22,6 +22,8 @@ open class ComputableResult : RealmObject(), Filterable {
var session: Session? = null
var ratedTips: Double = 0.0
fun updateWith(session: Session) {
val rate = session.bankroll?.currency?.rate ?: 1.0
@ -30,6 +32,7 @@ open class ComputableResult : RealmObject(), Filterable {
this.ratedNet = result.net * rate
this.isPositive = result.isPositive
this.ratedBuyin = (result.buyin ?: 0.0) * rate
this.ratedTips = (result.tips ?: 0.0) * rate
}
this.bbNet = session.bbNet
@ -47,6 +50,7 @@ open class ComputableResult : RealmObject(), Filterable {
IS_POSITIVE("isPositive"),
RATED_BUYIN("ratedBuyin"),
ESTIMATED_HANDS("estimatedHands"),
RATED_TIPS("ratedTips"),
// BB_PER100HANDS("bbPer100Hands")
}

@ -98,8 +98,14 @@ open class Result : RealmObject(), Filterable {
/**
* Returns 1 if the session is positive
*/
@Ignore
val isPositive: Int = if (this.net >= 0.0) 1 else 0
val isPositive: Int
get() {
return if (session?.isTournament() == true) {
if (this.cashout ?: -1.0 >= 0.0) 1 else 0 // if cashout is null we want to count a negative session
} else {
if (this.net >= 0.0) 1 else 0
}
}
// Computes the Net
private fun computeNet(withBuyin: Boolean? = null) {

@ -33,6 +33,7 @@ class Preferences {
PATCH_SESSION_SETS("patchSessionSet"),
PATCH_TRANSACTION_TYPES_NAMES("patchTransactionTypesNames"),
PATCH_BLINDS_FORMAT("patchBlindFormat"),
PATCH_COMPUTABLE_RESULTS("patchPositiveSessions"),
SHOW_STOP_NOTIFICATIONS("showStopNotifications"),
ADD_NEW_TRANSACTION_TYPES("addNewTransactionTypes"),
SHOW_VILLAIN_CARDS("showVillainCards"),

Loading…
Cancel
Save