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 79887e01..b5428459 100644 --- a/app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt +++ b/app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt @@ -130,7 +130,6 @@ class Calculator { val computableGroups: MutableList = mutableListOf() - var previousGroup: ComputableGroup? = null comparators.combined().forEach { comparatorConditions -> val allConditions = mutableListOf() @@ -138,10 +137,8 @@ class Calculator { allConditions.addAll(comparatorConditions) val group = ComputableGroup(allConditions.name(), allConditions) - group.comparedGroup = previousGroup computableGroups.add(group) - previousGroup = group } if (computableGroups.size == 0) { @@ -175,6 +172,10 @@ class Calculator { results.computeStatVariations(comparedResults) } + if (options.shouldManageMultiGroupProgressValues == true) { + group.comparedComputedResults = report.results.lastOrNull() + } + results.finalize(options) // later treatment, such as evolution numericValues sorting report.addResults(results) 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 6ffaa8ad..4b334d73 100644 --- a/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt +++ b/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt @@ -38,8 +38,8 @@ class Report(var options: Calculator.Options) { val entries = mutableListOf() this._results.forEachIndexed { index, results -> - results.computedStat(stat)?.progressValue?.let { evoValue -> - entries.add(Entry(index.toFloat(), evoValue.toFloat(), results)) + results.computedStat(stat)?.progressValue?.let { progressValue -> + entries.add(Entry(index.toFloat(), progressValue.toFloat(), results)) } } return entries @@ -220,94 +220,94 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu * Also computes evolution values using the previously computed values */ private fun addComputedStat(computedStat: ComputedStat) { + this._computedStats[computedStat.stat] = computedStat + } - 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 -> + private fun consolidateProgressStats() { - result.computedStat(computedStat.stat)?.let { previousComputedStat -> + if (this.shouldManageMultiGroupProgressValues) { - 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 + this.group.comparedComputedResults?.let { previousResult -> + this.allStats().forEach { computedStat -> + val stat = computedStat.stat + previousResult.computedStat(stat)?.let { previousComputedStat -> + when (stat) { + Stat.NET_RESULT, Stat.DURATION, Stat.BB_NET_RESULT, Stat.BB_SESSION_COUNT, + Stat.WINNING_SESSION_COUNT, Stat.TOTAL_BUYIN, Stat.HANDS_PLAYED, Stat.NUMBER_OF_GAMES, Stat.NUMBER_OF_SETS -> { + val previousValue = previousComputedStat.progressValue ?: previousComputedStat.value + computedStat.progressValue = previousValue + computedStat.value + } + else -> {} } - else -> {} + } ?: run { + computedStat.progressValue = computedStat.value } } } - } - 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 + val netResult = this.computedStat(Stat.NET_RESULT)?.progressValue + val bbNetResult = this.computedStat(Stat.BB_NET_RESULT)?.progressValue + val duration = this.computedStat(Stat.DURATION)?.progressValue + val numberOfGames = this.computedStat(Stat.NUMBER_OF_GAMES)?.progressValue + val numberOfSets = this.computedStat(Stat.NUMBER_OF_SETS)?.progressValue + val handsPlayed = this.computedStat(Stat.HANDS_PLAYED)?.progressValue + val winningCount = this.computedStat(Stat.WINNING_SESSION_COUNT)?.progressValue + val bbSessionCount = this.computedStat(Stat.BB_SESSION_COUNT)?.progressValue + val totalBuyin = this.computedStat(Stat.TOTAL_BUYIN)?.progressValue + + this.allStats().forEach { computedStat -> + when (computedStat.stat) { + Stat.HOURLY_RATE -> { + if (netResult != null && duration != null) { + computedStat.progressValue = netResult / duration + } } - } - Stat.AVERAGE -> { - if (netResult != null && numberOfGames != null) { - computedStat.secondValue = netResult / numberOfGames + Stat.AVERAGE -> { + if (netResult != null && numberOfGames != null) { + computedStat.progressValue = netResult / numberOfGames + } } - } - Stat.AVERAGE_DURATION -> { - if (duration != null && numberOfSets != null) { - computedStat.secondValue = duration / numberOfSets + Stat.AVERAGE_DURATION -> { + if (duration != null && numberOfSets != null) { + computedStat.progressValue = duration / numberOfSets + } } - } - Stat.NET_BB_PER_100_HANDS -> { - if (bbNetResult != null && handsPlayed != null) { - computedStat.secondValue = Stat.netBBPer100Hands(bbNetResult, handsPlayed) + Stat.NET_BB_PER_100_HANDS -> { + if (bbNetResult != null && handsPlayed != null) { + computedStat.progressValue = Stat.netBBPer100Hands(bbNetResult, handsPlayed) + } } - } - Stat.HOURLY_RATE_BB -> { - if (bbNetResult != null && duration != null) { - computedStat.secondValue = bbNetResult / duration + Stat.HOURLY_RATE_BB -> { + if (bbNetResult != null && duration != null) { + computedStat.progressValue = bbNetResult / duration + } } - } - Stat.AVERAGE_NET_BB -> { - if (bbNetResult != null && bbSessionCount != null) { - computedStat.secondValue = bbNetResult / bbSessionCount + Stat.AVERAGE_NET_BB -> { + if (bbNetResult != null && bbSessionCount != null) { + computedStat.progressValue = bbNetResult / bbSessionCount + } } - } - Stat.WIN_RATIO -> { - if (winningCount != null && numberOfGames != null) { - computedStat.secondValue = winningCount / numberOfGames + Stat.WIN_RATIO -> { + if (winningCount != null && numberOfGames != null) { + computedStat.progressValue = winningCount / numberOfGames + } } - } - Stat.AVERAGE_BUYIN -> { - if (totalBuyin != null && numberOfGames != null) { - computedStat.secondValue = totalBuyin / numberOfGames + Stat.AVERAGE_BUYIN -> { + if (totalBuyin != null && numberOfGames != null) { + computedStat.progressValue = totalBuyin / numberOfGames + } } - } - Stat.ROI -> { - if (totalBuyin != null && netResult != null) { - computedStat.secondValue = Stat.returnOnInvestment(netResult, totalBuyin) + Stat.ROI -> { + if (totalBuyin != null && netResult != null) { + computedStat.progressValue = Stat.returnOnInvestment(netResult, totalBuyin) + } } } } + } + } fun computedStat(stat: Stat): ComputedStat? { @@ -326,7 +326,7 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu fun finalize(options: Calculator.Options) { - this.consolidateEvolutionStat() + this.consolidateProgressStats() if (options.evolutionValues != Calculator.Options.EvolutionValues.NONE) { @@ -388,9 +388,8 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu override val entryTitle: String = this.group.name override fun formattedValue(stat: Stat, context: Context): TextFormat { - this.computedStat(stat)?.progressValue?.let { - return stat.format(it, context = context) -// return it.format(context) + this.computedStat(stat)?.let { + return it.format(context) } ?: run { throw IllegalStateException("Missing stat in results") }