diff --git a/app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt b/app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt index f96f9269..c319a043 100644 --- a/app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt +++ b/app/src/main/java/net/pokeranalytics/android/calculus/Calculator.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 diff --git a/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt b/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt index 97580595..364b4a61 100644 --- a/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt +++ b/app/src/main/java/net/pokeranalytics/android/calculus/Report.kt @@ -106,7 +106,7 @@ class ComputableGroup(name: String, conditions: List = listOf(), /** * Retrieves the computables on the relative [realm] filtered with the provided [conditions] */ - fun computables(realm: Realm): RealmResults { + fun computables(realm: Realm, sorted: Boolean = false): RealmResults { // if computables exists and is valid (previous realm not closed) this._computables?.let { @@ -115,7 +115,8 @@ class ComputableGroup(name: String, conditions: List = listOf(), } } - val computables: RealmResults = Filter.queryOn(realm, this.conditions) + val sortedField = if (sorted) "session.startDate" else null + val computables = Filter.queryOn(realm, this.conditions, sortedField) this._computables = computables return computables } @@ -128,7 +129,7 @@ class ComputableGroup(name: String, conditions: List = listOf(), /** * Retrieves the session sets on the relative [realm] filtered with the provided [conditions] */ - fun sessionSets(realm: Realm): RealmResults { + fun sessionSets(realm: Realm, sorted: Boolean = false): RealmResults { // 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 = listOf(), } } - val sets: RealmResults = Filter.queryOn(realm, this.conditions) + val sortedField = if (sorted) SessionSet.Field.START_DATE.identifier else null + val sets = Filter.queryOn(realm, this.conditions, sortedField) this._sessionSets = sets return sets } diff --git a/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt b/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt index 3e731206..b7039572 100644 --- a/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt +++ b/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt @@ -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 { diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt index 06e91e6d..3452c022 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/Filter.kt @@ -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().equalTo("id", filterId).findFirst() } - @TestOnly - inline fun queryOn(realm: Realm, queries: List): RealmResults { + inline fun queryOn(realm: Realm, queries: List, sortField: String? = null): RealmResults { var realmQuery = realm.where() 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() } diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt index 1d72ae2a..5b6ca631 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt @@ -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) } } diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt index f5aa245f..9333af4d 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt @@ -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"),