Merge remote-tracking branch 'origin/dev' into dev

feature/top10
Razmig Sarkissian 7 years ago
commit fe138764d9
  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()
var previousGroup: ComputableGroup? = null
comparators.combined().forEach { comparatorConditions ->
val allConditions = mutableListOf<QueryCondition>()
@ -143,10 +142,8 @@ class Calculator {
allConditions.addAll(comparatorConditions)
val group = ComputableGroup(allConditions.name(), allConditions)
group.comparedGroup = previousGroup
computableGroups.add(group)
previousGroup = group
}
if (computableGroups.size == 0) {
@ -180,6 +177,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)

@ -38,8 +38,8 @@ class Report(var options: Calculator.Options) {
val entries = mutableListOf<Entry>()
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) {
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.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 -> {}
}
} ?: 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
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.secondValue = netResult / duration
computedStat.progressValue = netResult / duration
}
}
Stat.AVERAGE -> {
if (netResult != null && numberOfGames != null) {
computedStat.secondValue = netResult / numberOfGames
computedStat.progressValue = netResult / numberOfGames
}
}
Stat.AVERAGE_DURATION -> {
if (duration != null && numberOfSets != null) {
computedStat.secondValue = duration / numberOfSets
computedStat.progressValue = duration / numberOfSets
}
}
Stat.NET_BB_PER_100_HANDS -> {
if (bbNetResult != null && handsPlayed != null) {
computedStat.secondValue = Stat.netBBPer100Hands(bbNetResult, handsPlayed)
computedStat.progressValue = Stat.netBBPer100Hands(bbNetResult, handsPlayed)
}
}
Stat.HOURLY_RATE_BB -> {
if (bbNetResult != null && duration != null) {
computedStat.secondValue = bbNetResult / duration
computedStat.progressValue = bbNetResult / duration
}
}
Stat.AVERAGE_NET_BB -> {
if (bbNetResult != null && bbSessionCount != null) {
computedStat.secondValue = bbNetResult / bbSessionCount
computedStat.progressValue = bbNetResult / bbSessionCount
}
}
Stat.WIN_RATIO -> {
if (winningCount != null && numberOfGames != null) {
computedStat.secondValue = winningCount / numberOfGames
computedStat.progressValue = winningCount / numberOfGames
}
}
Stat.AVERAGE_BUYIN -> {
if (totalBuyin != null && numberOfGames != null) {
computedStat.secondValue = totalBuyin / numberOfGames
computedStat.progressValue = totalBuyin / numberOfGames
}
}
Stat.ROI -> {
if (totalBuyin != null && netResult != null) {
computedStat.secondValue = Stat.returnOnInvestment(netResult, totalBuyin)
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")
}

Loading…
Cancel
Save