From 738571bdd54503c01de21b6be6341ce9e347edcf Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 18 Apr 2019 15:19:26 +0200 Subject: [PATCH] Calculator now computes progress values over groups --- .../android/calculus/Calculator.kt | 4 +- .../pokeranalytics/android/calculus/Report.kt | 120 +++++++++++++----- .../pokeranalytics/android/calculus/Stat.kt | 5 + 3 files changed, 97 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt b/app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt index 25efb031..6e7ec548 100644 --- a/app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt +++ b/app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt @@ -82,7 +82,7 @@ class Calculator { return this.displayedStats.contains(DAYS_PLAYED) } - val evolutionForAggregatedValues: Boolean + val shouldManageMultiGroupProgressValues: Boolean get() { if (this.aggregationType != null) { return this.aggregationType == AggregationType.MONTH || this.aggregationType == AggregationType.YEAR @@ -190,7 +190,7 @@ class Calculator { */ fun compute(realm: Realm, computableGroup: ComputableGroup, options: Options): ComputedResults { - val results = ComputedResults(computableGroup) + val results = ComputedResults(computableGroup, options.shouldManageMultiGroupProgressValues) val computables = computableGroup.computables(realm) Timber.d(">>>> Start computing group ${computableGroup.name}, ${computables.size} computables") diff --git a/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt b/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt index ad27c08e..1ab9e794 100644 --- a/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt +++ b/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt @@ -16,33 +16,30 @@ import net.pokeranalytics.android.model.realm.SessionSet */ class Report(var options: Calculator.Options) { + /** + * The mutable list of ComputedResults, one for each group of data + */ private var _results: MutableList = mutableListOf() val results: List = this._results - -// private var groups: MutableList = mutableListOf() -// -// -// fun addGroup(group: ComputableGroup) { -// this.groups.add(group) -// } -// -// fun addGroups(groups: Collection) { -// this.groups.addAll(groups) -// } - + /** + * Adds a new result to the list of ComputedResults + */ fun addResults(result: ComputedResults) { this._results.add(result) } + /** + * Returns the list of entries corresponding to the provided [stat] + * One value will be returned by result + */ fun lineEntries(stat: Stat): List { val entries = mutableListOf() this._results.forEachIndexed { index, results -> - val cs = results.computedStat(stat) - cs?.let { computedStat -> - entries.add(Entry(index.toFloat(), computedStat.value.toFloat(), results)) + results.computedStat(stat)?.progressValue?.let { evoValue -> + entries.add(Entry(index.toFloat(), evoValue.toFloat(), results)) } } return entries @@ -165,7 +162,7 @@ class ComputableGroup(name: String, conditions: List = listOf(), } -class ComputedResults(group: ComputableGroup) : StatEntry { +class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValues: Boolean = false) : StatEntry { /** * The session group used to computed the stats @@ -178,6 +175,8 @@ class ComputedResults(group: ComputableGroup) : StatEntry { // The map containing all evolution numericValues for all stats private var _evolutionValues: MutableMap> = mutableMapOf() + private var shouldManageMultiGroupProgressValues = shouldManageMultiGroupProgressValues + fun allStats(): Collection { return this._computedStats.values } @@ -216,31 +215,99 @@ class ComputedResults(group: ComputableGroup) : StatEntry { } } + /** + * Adds a [computedStat] to the list of stats + * Also computes evolution values using the previously computed values + */ private fun addComputedStat(computedStat: ComputedStat) { - this.group.comparedComputedResults?.let { result -> + if (this.shouldManageMultiGroupProgressValues) { + + computedStat.progressValue = computedStat.value // useful for first occurence, otherwise overridden + + // Computes the evolution value for the stat + this.group.comparedComputedResults?.let { result -> - result.computedStat(computedStat.stat)?.let { previousComputedStat -> + result.computedStat(computedStat.stat)?.let { previousComputedStat -> - val previousValue = previousComputedStat.secondValue ?: previousComputedStat.value - when (computedStat.stat) { - Stat.NET_RESULT, Stat.DURATION, Stat.BB_NET_RESULT -> { - computedStat.secondValue = previousValue + computedStat.value + val previousValue = previousComputedStat.progressValue ?: previousComputedStat.value + when (computedStat.stat) { + Stat.NET_RESULT, Stat.DURATION, Stat.BB_NET_RESULT, Stat.BB_SESSION_COUNT, + Stat.WINNING_SESSION_COUNT, Stat.TOTAL_BUYIN, Stat.HANDS_PLAYED -> { + computedStat.progressValue = previousValue + computedStat.value + } + else -> {} } } } } this._computedStats[computedStat.stat] = computedStat + } fun consolidateEvolutionStat() { + val netResult = this.computedStat(Stat.NET_RESULT)?.secondValue + val bbNetResult = this.computedStat(Stat.BB_NET_RESULT)?.secondValue + val duration = this.computedStat(Stat.DURATION)?.secondValue + val numberOfGames = this.computedStat(Stat.NUMBER_OF_GAMES)?.secondValue + val numberOfSets = this.computedStat(Stat.NUMBER_OF_SETS)?.secondValue + val handsPlayed = this.computedStat(Stat.HANDS_PLAYED)?.secondValue + val winningCount = this.computedStat(Stat.WINNING_SESSION_COUNT)?.secondValue + val bbSessionCount = this.computedStat(Stat.BB_SESSION_COUNT)?.secondValue + val totalBuyin = this.computedStat(Stat.TOTAL_BUYIN)?.secondValue + this.allStats().forEach { computedStat -> when (computedStat.stat) { - + Stat.HOURLY_RATE -> { + if (netResult != null && duration != null) { + computedStat.secondValue = netResult / duration + } + } + Stat.AVERAGE -> { + if (netResult != null && numberOfGames != null) { + computedStat.secondValue = netResult / numberOfGames + } + } + Stat.AVERAGE_DURATION -> { + if (duration != null && numberOfSets != null) { + computedStat.secondValue = duration / numberOfSets + } + } + Stat.NET_BB_PER_100_HANDS -> { + if (bbNetResult != null && handsPlayed != null) { + computedStat.secondValue = Stat.netBBPer100Hands(bbNetResult, handsPlayed) + } + } + Stat.HOURLY_RATE_BB -> { + if (bbNetResult != null && duration != null) { + computedStat.secondValue = bbNetResult / duration + } + } + Stat.AVERAGE_NET_BB -> { + if (bbNetResult != null && bbSessionCount != null) { + computedStat.secondValue = bbNetResult / bbSessionCount + } + } + Stat.WIN_RATIO -> { + if (winningCount != null && numberOfGames != null) { + computedStat.secondValue = winningCount / numberOfGames + } + } + Stat.AVERAGE_BUYIN -> { + if (totalBuyin != null && numberOfGames != null) { + computedStat.secondValue = totalBuyin / numberOfGames + } + } + Stat.ROI -> { + if (totalBuyin != null && netResult != null) { + computedStat.secondValue = Stat.returnOnInvestment(netResult, totalBuyin) + } + } } } + } fun computedStat(stat: Stat): ComputedStat? { @@ -273,13 +340,6 @@ class ComputedResults(group: ComputableGroup) : StatEntry { } } - /** - * Returns the number of computed stats - */ - fun numberOfStats(): Int { - return this._computedStats.size - } - // MPAndroidChart fun defaultStatEntries(stat: Stat): List { diff --git a/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt b/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt index 9cf06183..4e1aea9b 100644 --- a/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt +++ b/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt @@ -269,6 +269,11 @@ class ComputedStat(var stat: Stat, var value: Double, var secondValue: Double? = } } + /** + * The value used to get evolution dataset + */ + var progressValue: Double? = null + /** * The variation of the stat */