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 val computeLongestStreak: Boolean
get() {
return this.displayedStats.contains(LONGEST_STREAKS)
}
val shouldSortValues: Boolean
get() { get() {
return this.displayedStats.contains(LONGEST_STREAKS) return this.evolutionValues != EvolutionValues.NONE || this.computeLongestStreak
} }
val computeLocationsPlayed: Boolean val computeLocationsPlayed: Boolean
get() { get() {
@ -200,14 +204,10 @@ class Calculator {
val results = ComputedResults(computableGroup, options.shouldManageMultiGroupProgressValues) 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") Timber.d(">>>> Start computing group ${computableGroup.name}, ${computables.size} computables")
results.addStat(NUMBER_OF_GAMES, computables.size.toDouble()) 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() val sum = computables.sum(ComputableResult.Field.RATED_NET.identifier).toDouble()
results.addStat(NET_RESULT, sum) results.addStat(NET_RESULT, sum)
@ -265,7 +265,7 @@ class Calculator {
val shouldIterateOverComputables = val shouldIterateOverComputables =
(options.evolutionValues == Options.EvolutionValues.STANDARD || options.computeLongestStreak) (options.evolutionValues == Options.EvolutionValues.STANDARD || options.computeLongestStreak)
// Iterate for each session // Computable Result
if (shouldIterateOverComputables) { if (shouldIterateOverComputables) {
var index = 0 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()) results.addStat(NUMBER_OF_SETS, sessionSets.size.toDouble())
var gHourlyDuration: Double? = null var gHourlyDuration: Double? = null
@ -360,6 +360,7 @@ class Calculator {
options.evolutionValues != Options.EvolutionValues.NONE || options.evolutionValues != Options.EvolutionValues.NONE ||
options.computeDaysPlayed options.computeDaysPlayed
// Session Set
if (shouldIterateOverSets) { if (shouldIterateOverSets) {
var tHourlyDuration = 0.0 var tHourlyDuration = 0.0
@ -419,7 +420,7 @@ class Calculator {
sessionSet sessionSet
) )
results.addEvolutionValue( results.addEvolutionValue(
sessionSet.netDuration.toDouble(), sessionSet.hourlyDuration,
tHourlyDuration, tHourlyDuration,
DURATION, DURATION,
sessionSet 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] * 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) // if computables exists and is valid (previous realm not closed)
this._computables?.let { 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 this._computables = computables
return 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] * 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) // if computables exists and is valid (previous realm not closed)
this._sessionSets?.let { this._sessionSets?.let {
if (it.isValid) { 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 this._sessionSets = sets
return sets return sets
} }

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

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

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

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

Loading…
Cancel
Save