Fixing win ratio legend + potential bugs

feature/top10
Laurent 7 years ago
parent 88acf6af81
commit 777bbb6903
  1. 19
      app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt
  2. 10
      app/src/main/java/net/pokeranalytics/android/calculus/Report.kt
  3. 5
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  4. 11
      app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt
  5. 4
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  6. 1
      app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt

@ -70,8 +70,12 @@ class Calculator {
}
val computeLongestStreak: Boolean
get() {
return this.displayedStats.contains(LONGEST_STREAKS)
}
val shouldSortValues: Boolean
get() {
return this.displayedStats.contains(LONGEST_STREAKS)
return this.evolutionValues != EvolutionValues.NONE || this.computeLongestStreak
}
val computeLocationsPlayed: Boolean
get() {
@ -200,14 +204,10 @@ class Calculator {
val results = ComputedResults(computableGroup, options.shouldManageMultiGroupProgressValues)
val computables = computableGroup.computables(realm)
val computables = computableGroup.computables(realm, options.shouldSortValues)
Timber.d(">>>> Start computing group ${computableGroup.name}, ${computables.size} computables")
results.addStat(NUMBER_OF_GAMES, computables.size.toDouble())
if (options.computeLongestStreak) {
computables.sort("session.startDate")
}
val sum = computables.sum(ComputableResult.Field.RATED_NET.identifier).toDouble()
results.addStat(NET_RESULT, sum)
@ -265,7 +265,7 @@ class Calculator {
val shouldIterateOverComputables =
(options.evolutionValues == Options.EvolutionValues.STANDARD || options.computeLongestStreak)
// Iterate for each session
// Computable Result
if (shouldIterateOverComputables) {
var index = 0
@ -339,7 +339,7 @@ class Calculator {
}
val sessionSets = computableGroup.sessionSets(realm)
val sessionSets = computableGroup.sessionSets(realm, options.shouldSortValues)
results.addStat(NUMBER_OF_SETS, sessionSets.size.toDouble())
var gHourlyDuration: Double? = null
@ -360,6 +360,7 @@ class Calculator {
options.evolutionValues != Options.EvolutionValues.NONE ||
options.computeDaysPlayed
// Session Set
if (shouldIterateOverSets) {
var tHourlyDuration = 0.0
@ -419,7 +420,7 @@ class Calculator {
sessionSet
)
results.addEvolutionValue(
sessionSet.netDuration.toDouble(),
sessionSet.hourlyDuration,
tHourlyDuration,
DURATION,
sessionSet

@ -106,7 +106,7 @@ class ComputableGroup(name: String, conditions: List<QueryCondition> = listOf(),
/**
* Retrieves the computables on the relative [realm] filtered with the provided [conditions]
*/
fun computables(realm: Realm): RealmResults<ComputableResult> {
fun computables(realm: Realm, sorted: Boolean = false): RealmResults<ComputableResult> {
// if computables exists and is valid (previous realm not closed)
this._computables?.let {
@ -115,7 +115,8 @@ class ComputableGroup(name: String, conditions: List<QueryCondition> = listOf(),
}
}
val computables: RealmResults<ComputableResult> = Filter.queryOn(realm, this.conditions)
val sortedField = if (sorted) "session.startDate" else null
val computables = Filter.queryOn<ComputableResult>(realm, this.conditions, sortedField)
this._computables = computables
return computables
}
@ -128,7 +129,7 @@ class ComputableGroup(name: String, conditions: List<QueryCondition> = listOf(),
/**
* Retrieves the session sets on the relative [realm] filtered with the provided [conditions]
*/
fun sessionSets(realm: Realm): RealmResults<SessionSet> {
fun sessionSets(realm: Realm, sorted: Boolean = false): RealmResults<SessionSet> {
// if computables exists and is valid (previous realm not closed)
this._sessionSets?.let {
if (it.isValid) {
@ -136,7 +137,8 @@ class ComputableGroup(name: String, conditions: List<QueryCondition> = listOf(),
}
}
val sets: RealmResults<SessionSet> = Filter.queryOn(realm, this.conditions)
val sortedField = if (sorted) SessionSet.Field.START_DATE.identifier else null
val sets = Filter.queryOn<SessionSet>(realm, this.conditions, sortedField)
this._sessionSets = sets
return sets
}

@ -32,7 +32,7 @@ interface StatEntry {
fun legendValues(stat: Stat, entry: Entry) : LegendView.Values {
return when (stat) {
Stat.NUMBER_OF_SETS, Stat.NUMBER_OF_GAMES -> {
Stat.NUMBER_OF_SETS, Stat.NUMBER_OF_GAMES, Stat.WIN_RATIO -> {
val totalStatValue = stat.format(entry.y.toDouble(), currency = null)
LegendView.Values(this.entryTitle, totalStatValue)
}
@ -216,13 +216,14 @@ enum class Stat : RowRepresentable {
fun cumulativeLabelResId(context: Context): String {
val resId = when (this) {
AVERAGE, AVERAGE_DURATION, NET_BB_PER_100_HANDS,
HOURLY_RATE_BB, AVERAGE_NET_BB, ROI, WIN_RATIO, HOURLY_RATE -> R.string.average
HOURLY_RATE_BB, AVERAGE_NET_BB, ROI, HOURLY_RATE -> R.string.average
NUMBER_OF_SETS -> R.string.number_of_sessions
NUMBER_OF_GAMES -> R.string.number_of_records
NET_RESULT, DURATION -> R.string.total
STANDARD_DEVIATION -> R.string.net_result
STANDARD_DEVIATION_HOURLY -> R.string.hour_rate_without_pauses
STANDARD_DEVIATION_BB_PER_100_HANDS -> R.string.net_result_bb_per_100_hands
WIN_RATIO -> return this.name
else -> null
}
resId?.let {

@ -3,13 +3,9 @@ package net.pokeranalytics.android.model.realm
import io.realm.*
import io.realm.annotations.PrimaryKey
import io.realm.kotlin.where
import net.pokeranalytics.android.exceptions.PokerAnalyticsException
import net.pokeranalytics.android.model.filter.Filterable
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterCategoryRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterElementRow
import net.pokeranalytics.android.ui.view.rowrepresentable.FilterSectionRow
import org.jetbrains.annotations.TestOnly
import timber.log.Timber
import java.util.*
@ -33,13 +29,14 @@ open class Filter : RealmObject() {
return realm.where<Filter>().equalTo("id", filterId).findFirst()
}
@TestOnly
inline fun <reified T : Filterable> queryOn(realm: Realm, queries: List<QueryCondition>): RealmResults<T> {
inline fun <reified T : Filterable> queryOn(realm: Realm, queries: List<QueryCondition>, sortField: String? = null): RealmResults<T> {
var realmQuery = realm.where<T>()
queries.forEach {
Timber.d(">>> sub Filter query: ${realmQuery.description}")
realmQuery = it.queryWith(realmQuery)
}
sortField?.let {
realmQuery.sort(it)
}
Timber.d(">>> Filter query: ${realmQuery.description}")
return realmQuery.findAll()
}

@ -974,8 +974,8 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
}
return LegendView.Values(this.entryTitle, left, right)
} else -> {
}
else -> {
return super.legendValues(stat, entry)
}
}

@ -87,6 +87,7 @@ open class SessionSet() : RealmObject(), Timed, Filterable {
}
enum class Field(val identifier: String) {
START_DATE("startDate"),
RATED_NET("ratedNet"),
HOURLY_RATE("hourlyRate"),
BB_NET("bbNet"),

Loading…
Cancel
Save