Fixing progress values at group level

feature/top10
Laurent 7 years ago
parent dcc3113fe6
commit b1696fa35a
  1. 7
      app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt
  2. 145
      app/src/main/java/net/pokeranalytics/android/calculus/Report.kt

@ -130,7 +130,6 @@ class Calculator {
val computableGroups: MutableList<ComputableGroup> = mutableListOf() val computableGroups: MutableList<ComputableGroup> = mutableListOf()
var previousGroup: ComputableGroup? = null
comparators.combined().forEach { comparatorConditions -> comparators.combined().forEach { comparatorConditions ->
val allConditions = mutableListOf<QueryCondition>() val allConditions = mutableListOf<QueryCondition>()
@ -138,10 +137,8 @@ class Calculator {
allConditions.addAll(comparatorConditions) allConditions.addAll(comparatorConditions)
val group = ComputableGroup(allConditions.name(), allConditions) val group = ComputableGroup(allConditions.name(), allConditions)
group.comparedGroup = previousGroup
computableGroups.add(group) computableGroups.add(group)
previousGroup = group
} }
if (computableGroups.size == 0) { if (computableGroups.size == 0) {
@ -175,6 +172,10 @@ class Calculator {
results.computeStatVariations(comparedResults) results.computeStatVariations(comparedResults)
} }
if (options.shouldManageMultiGroupProgressValues == true) {
group.comparedComputedResults = report.results.lastOrNull()
}
results.finalize(options) // later treatment, such as evolution numericValues sorting results.finalize(options) // later treatment, such as evolution numericValues sorting
report.addResults(results) report.addResults(results)

@ -38,8 +38,8 @@ class Report(var options: Calculator.Options) {
val entries = mutableListOf<Entry>() val entries = mutableListOf<Entry>()
this._results.forEachIndexed { index, results -> this._results.forEachIndexed { index, results ->
results.computedStat(stat)?.progressValue?.let { evoValue -> results.computedStat(stat)?.progressValue?.let { progressValue ->
entries.add(Entry(index.toFloat(), evoValue.toFloat(), results)) entries.add(Entry(index.toFloat(), progressValue.toFloat(), results))
} }
} }
return entries return entries
@ -220,94 +220,94 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu
* Also computes evolution values using the previously computed values * Also computes evolution values using the previously computed values
*/ */
private fun addComputedStat(computedStat: ComputedStat) { private fun addComputedStat(computedStat: ComputedStat) {
this._computedStats[computedStat.stat] = computedStat
}
if (this.shouldManageMultiGroupProgressValues) { private fun consolidateProgressStats() {
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 -> if (this.shouldManageMultiGroupProgressValues) {
val previousValue = previousComputedStat.progressValue ?: previousComputedStat.value this.group.comparedComputedResults?.let { previousResult ->
when (computedStat.stat) { this.allStats().forEach { computedStat ->
Stat.NET_RESULT, Stat.DURATION, Stat.BB_NET_RESULT, Stat.BB_SESSION_COUNT, val stat = computedStat.stat
Stat.WINNING_SESSION_COUNT, Stat.TOTAL_BUYIN, Stat.HANDS_PLAYED -> { previousResult.computedStat(stat)?.let { previousComputedStat ->
computedStat.progressValue = previousValue + computedStat.value 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 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
fun consolidateEvolutionStat() { val numberOfSets = this.computedStat(Stat.NUMBER_OF_SETS)?.progressValue
val handsPlayed = this.computedStat(Stat.HANDS_PLAYED)?.progressValue
val netResult = this.computedStat(Stat.NET_RESULT)?.secondValue val winningCount = this.computedStat(Stat.WINNING_SESSION_COUNT)?.progressValue
val bbNetResult = this.computedStat(Stat.BB_NET_RESULT)?.secondValue val bbSessionCount = this.computedStat(Stat.BB_SESSION_COUNT)?.progressValue
val duration = this.computedStat(Stat.DURATION)?.secondValue val totalBuyin = this.computedStat(Stat.TOTAL_BUYIN)?.progressValue
val numberOfGames = this.computedStat(Stat.NUMBER_OF_GAMES)?.secondValue
val numberOfSets = this.computedStat(Stat.NUMBER_OF_SETS)?.secondValue this.allStats().forEach { computedStat ->
val handsPlayed = this.computedStat(Stat.HANDS_PLAYED)?.secondValue when (computedStat.stat) {
val winningCount = this.computedStat(Stat.WINNING_SESSION_COUNT)?.secondValue Stat.HOURLY_RATE -> {
val bbSessionCount = this.computedStat(Stat.BB_SESSION_COUNT)?.secondValue if (netResult != null && duration != null) {
val totalBuyin = this.computedStat(Stat.TOTAL_BUYIN)?.secondValue computedStat.progressValue = netResult / duration
}
this.allStats().forEach { computedStat ->
when (computedStat.stat) {
Stat.HOURLY_RATE -> {
if (netResult != null && duration != null) {
computedStat.secondValue = netResult / duration
} }
} Stat.AVERAGE -> {
Stat.AVERAGE -> { if (netResult != null && numberOfGames != null) {
if (netResult != null && numberOfGames != null) { computedStat.progressValue = netResult / numberOfGames
computedStat.secondValue = netResult / numberOfGames }
} }
} Stat.AVERAGE_DURATION -> {
Stat.AVERAGE_DURATION -> { if (duration != null && numberOfSets != null) {
if (duration != null && numberOfSets != null) { computedStat.progressValue = duration / numberOfSets
computedStat.secondValue = duration / numberOfSets }
} }
} Stat.NET_BB_PER_100_HANDS -> {
Stat.NET_BB_PER_100_HANDS -> { if (bbNetResult != null && handsPlayed != null) {
if (bbNetResult != null && handsPlayed != null) { computedStat.progressValue = Stat.netBBPer100Hands(bbNetResult, handsPlayed)
computedStat.secondValue = Stat.netBBPer100Hands(bbNetResult, handsPlayed) }
} }
} Stat.HOURLY_RATE_BB -> {
Stat.HOURLY_RATE_BB -> { if (bbNetResult != null && duration != null) {
if (bbNetResult != null && duration != null) { computedStat.progressValue = bbNetResult / duration
computedStat.secondValue = bbNetResult / duration }
} }
} Stat.AVERAGE_NET_BB -> {
Stat.AVERAGE_NET_BB -> { if (bbNetResult != null && bbSessionCount != null) {
if (bbNetResult != null && bbSessionCount != null) { computedStat.progressValue = bbNetResult / bbSessionCount
computedStat.secondValue = bbNetResult / bbSessionCount }
} }
} Stat.WIN_RATIO -> {
Stat.WIN_RATIO -> { if (winningCount != null && numberOfGames != null) {
if (winningCount != null && numberOfGames != null) { computedStat.progressValue = winningCount / numberOfGames
computedStat.secondValue = winningCount / numberOfGames }
} }
} Stat.AVERAGE_BUYIN -> {
Stat.AVERAGE_BUYIN -> { if (totalBuyin != null && numberOfGames != null) {
if (totalBuyin != null && numberOfGames != null) { computedStat.progressValue = totalBuyin / numberOfGames
computedStat.secondValue = totalBuyin / numberOfGames }
} }
} Stat.ROI -> {
Stat.ROI -> { if (totalBuyin != null && netResult != null) {
if (totalBuyin != null && netResult != null) { computedStat.progressValue = Stat.returnOnInvestment(netResult, totalBuyin)
computedStat.secondValue = Stat.returnOnInvestment(netResult, totalBuyin) }
} }
} }
} }
} }
} }
fun computedStat(stat: Stat): ComputedStat? { fun computedStat(stat: Stat): ComputedStat? {
@ -326,7 +326,7 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu
fun finalize(options: Calculator.Options) { fun finalize(options: Calculator.Options) {
this.consolidateEvolutionStat() this.consolidateProgressStats()
if (options.evolutionValues != Calculator.Options.EvolutionValues.NONE) { if (options.evolutionValues != Calculator.Options.EvolutionValues.NONE) {
@ -388,9 +388,8 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu
override val entryTitle: String = this.group.name override val entryTitle: String = this.group.name
override fun formattedValue(stat: Stat, context: Context): TextFormat { override fun formattedValue(stat: Stat, context: Context): TextFormat {
this.computedStat(stat)?.progressValue?.let { this.computedStat(stat)?.let {
return stat.format(it, context = context) return it.format(context)
// return it.format(context)
} ?: run { } ?: run {
throw IllegalStateException("Missing stat in results") throw IllegalStateException("Missing stat in results")
} }

Loading…
Cancel
Save