Merge branch 'dev' of gitlab.com:stax-river/poker-analytics into dev

feature/top10
Aurelien Hubert 7 years ago
commit 1dc203fbc2
  1. 7
      app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt
  2. 79
      app/src/main/java/net/pokeranalytics/android/calculus/Report.kt

@ -135,7 +135,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>()
@ -143,10 +142,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) {
@ -180,6 +177,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 ->
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.NET_RESULT, Stat.DURATION, Stat.BB_NET_RESULT, Stat.BB_SESSION_COUNT,
Stat.WINNING_SESSION_COUNT, Stat.TOTAL_BUYIN, Stat.HANDS_PLAYED -> { 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 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
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 -> this.allStats().forEach { computedStat ->
when (computedStat.stat) { when (computedStat.stat) {
Stat.HOURLY_RATE -> { Stat.HOURLY_RATE -> {
if (netResult != null && duration != null) { if (netResult != null && duration != null) {
computedStat.secondValue = netResult / duration computedStat.progressValue = netResult / duration
} }
} }
Stat.AVERAGE -> { Stat.AVERAGE -> {
if (netResult != null && numberOfGames != null) { if (netResult != null && numberOfGames != null) {
computedStat.secondValue = netResult / numberOfGames computedStat.progressValue = netResult / numberOfGames
} }
} }
Stat.AVERAGE_DURATION -> { Stat.AVERAGE_DURATION -> {
if (duration != null && numberOfSets != null) { if (duration != null && numberOfSets != null) {
computedStat.secondValue = duration / numberOfSets computedStat.progressValue = 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.secondValue = Stat.netBBPer100Hands(bbNetResult, handsPlayed) computedStat.progressValue = Stat.netBBPer100Hands(bbNetResult, handsPlayed)
} }
} }
Stat.HOURLY_RATE_BB -> { Stat.HOURLY_RATE_BB -> {
if (bbNetResult != null && duration != null) { if (bbNetResult != null && duration != null) {
computedStat.secondValue = bbNetResult / duration computedStat.progressValue = bbNetResult / duration
} }
} }
Stat.AVERAGE_NET_BB -> { Stat.AVERAGE_NET_BB -> {
if (bbNetResult != null && bbSessionCount != null) { if (bbNetResult != null && bbSessionCount != null) {
computedStat.secondValue = bbNetResult / bbSessionCount computedStat.progressValue = bbNetResult / bbSessionCount
} }
} }
Stat.WIN_RATIO -> { Stat.WIN_RATIO -> {
if (winningCount != null && numberOfGames != null) { if (winningCount != null && numberOfGames != null) {
computedStat.secondValue = winningCount / numberOfGames computedStat.progressValue = winningCount / numberOfGames
} }
} }
Stat.AVERAGE_BUYIN -> { Stat.AVERAGE_BUYIN -> {
if (totalBuyin != null && numberOfGames != null) { if (totalBuyin != null && numberOfGames != null) {
computedStat.secondValue = totalBuyin / numberOfGames computedStat.progressValue = totalBuyin / numberOfGames
} }
} }
Stat.ROI -> { Stat.ROI -> {
if (totalBuyin != null && netResult != null) { if (totalBuyin != null && netResult != null) {
computedStat.secondValue = Stat.returnOnInvestment(netResult, totalBuyin) computedStat.progressValue = 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) {
@ -390,9 +390,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