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

# Conflicts:
#	app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt
#	app/src/main/java/net/pokeranalytics/android/ui/fragment/StatsFragment.kt
feature/top10
Aurelien Hubert 7 years ago
commit 16abecf46d
  1. 6
      app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt
  2. 122
      app/src/main/java/net/pokeranalytics/android/calculus/Report.kt
  3. 5
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  4. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/StatisticDetailsFragment.kt
  5. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/StatsFragment.kt

@ -82,7 +82,7 @@ class Calculator {
return this.displayedStats.contains(DAYS_PLAYED) return this.displayedStats.contains(DAYS_PLAYED)
} }
val evolutionForAggregatedValues: Boolean val shouldManageMultiGroupProgressValues: Boolean
get() { get() {
if (this.aggregationType != null) { if (this.aggregationType != null) {
return this.aggregationType == AggregationType.MONTH || this.aggregationType == AggregationType.YEAR return this.aggregationType == AggregationType.MONTH || this.aggregationType == AggregationType.YEAR
@ -97,12 +97,14 @@ class Calculator {
fun computeStatsWithEvolutionByAggregationType( fun computeStatsWithEvolutionByAggregationType(
realm: Realm, realm: Realm,
stat: Stat,
group: ComputableGroup, group: ComputableGroup,
aggregationType: AggregationType, aggregationType: AggregationType,
stats: List<Stat>? = null stats: List<Stat>? = null
): Report { ): Report {
val options = Options(evolutionValues = Options.EvolutionValues.STANDARD, aggregationType = aggregationType) val options = Options(evolutionValues = Options.EvolutionValues.STANDARD, aggregationType = aggregationType)
options.displayedStats = listOf(stat)
if (aggregationType == AggregationType.DURATION) { if (aggregationType == AggregationType.DURATION) {
options.evolutionValues = Options.EvolutionValues.TIMED options.evolutionValues = Options.EvolutionValues.TIMED
} }
@ -195,7 +197,7 @@ class Calculator {
*/ */
fun compute(realm: Realm, computableGroup: ComputableGroup, options: Options): ComputedResults { fun compute(realm: Realm, computableGroup: ComputableGroup, options: Options): ComputedResults {
val results = ComputedResults(computableGroup) val results = ComputedResults(computableGroup, options.shouldManageMultiGroupProgressValues)
val computables = computableGroup.computables(realm) val computables = computableGroup.computables(realm)
Timber.d(">>>> Start computing group ${computableGroup.name}, ${computables.size} computables") Timber.d(">>>> Start computing group ${computableGroup.name}, ${computables.size} computables")

@ -16,33 +16,30 @@ import net.pokeranalytics.android.model.realm.SessionSet
*/ */
class Report(var options: Calculator.Options) { class Report(var options: Calculator.Options) {
/**
* The mutable list of ComputedResults, one for each group of data
*/
private var _results: MutableList<ComputedResults> = mutableListOf() private var _results: MutableList<ComputedResults> = mutableListOf()
val results: List<ComputedResults> = this._results val results: List<ComputedResults> = this._results
/**
// private var groups: MutableList<ComputableGroup> = mutableListOf() * Adds a new result to the list of ComputedResults
// */
//
// fun addGroup(group: ComputableGroup) {
// this.groups.add(group)
// }
//
// fun addGroups(groups: Collection<ComputableGroup>) {
// this.groups.addAll(groups)
// }
fun addResults(result: ComputedResults) { fun addResults(result: ComputedResults) {
this._results.add(result) this._results.add(result)
} }
/**
* Returns the list of entries corresponding to the provided [stat]
* One value will be returned by result
*/
fun lineEntries(stat: Stat): List<Entry> { fun lineEntries(stat: Stat): List<Entry> {
val entries = mutableListOf<Entry>() val entries = mutableListOf<Entry>()
this._results.forEachIndexed { index, results -> this._results.forEachIndexed { index, results ->
val cs = results.computedStat(stat) results.computedStat(stat)?.progressValue?.let { evoValue ->
cs?.let { computedStat -> entries.add(Entry(index.toFloat(), evoValue.toFloat(), results))
entries.add(Entry(index.toFloat(), computedStat.value.toFloat(), results))
} }
} }
return entries return entries
@ -165,7 +162,7 @@ class ComputableGroup(name: String, conditions: List<QueryCondition> = listOf(),
} }
class ComputedResults(group: ComputableGroup) : StatEntry { class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValues: Boolean = false) : StatEntry {
/** /**
* The session group used to computed the stats * The session group used to computed the stats
@ -178,6 +175,8 @@ class ComputedResults(group: ComputableGroup) : StatEntry {
// The map containing all evolution numericValues for all stats // The map containing all evolution numericValues for all stats
private var _evolutionValues: MutableMap<Stat, MutableList<Point>> = mutableMapOf() private var _evolutionValues: MutableMap<Stat, MutableList<Point>> = mutableMapOf()
private var shouldManageMultiGroupProgressValues = shouldManageMultiGroupProgressValues
fun allStats(): Collection<ComputedStat> { fun allStats(): Collection<ComputedStat> {
return this._computedStats.values return this._computedStats.values
} }
@ -216,31 +215,99 @@ class ComputedResults(group: ComputableGroup) : StatEntry {
} }
} }
/**
* Adds a [computedStat] to the list of stats
* Also computes evolution values using the previously computed values
*/
private fun addComputedStat(computedStat: ComputedStat) { private fun addComputedStat(computedStat: ComputedStat) {
this.group.comparedComputedResults?.let { result -> 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 ->
result.computedStat(computedStat.stat)?.let { previousComputedStat -> result.computedStat(computedStat.stat)?.let { previousComputedStat ->
val previousValue = previousComputedStat.secondValue ?: previousComputedStat.value val previousValue = previousComputedStat.progressValue ?: previousComputedStat.value
when (computedStat.stat) { when (computedStat.stat) {
Stat.NET_RESULT, Stat.DURATION, Stat.BB_NET_RESULT -> { Stat.NET_RESULT, Stat.DURATION, Stat.BB_NET_RESULT, Stat.BB_SESSION_COUNT,
computedStat.secondValue = previousValue + computedStat.value Stat.WINNING_SESSION_COUNT, Stat.TOTAL_BUYIN, Stat.HANDS_PLAYED -> {
computedStat.progressValue = previousValue + computedStat.value
}
else -> {}
} }
} }
} }
} }
this._computedStats[computedStat.stat] = computedStat this._computedStats[computedStat.stat] = computedStat
} }
fun consolidateEvolutionStat() { 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
this.allStats().forEach { computedStat -> this.allStats().forEach { computedStat ->
when (computedStat.stat) { when (computedStat.stat) {
Stat.HOURLY_RATE -> {
if (netResult != null && duration != null) {
computedStat.secondValue = netResult / duration
}
}
Stat.AVERAGE -> {
if (netResult != null && numberOfGames != null) {
computedStat.secondValue = netResult / numberOfGames
}
}
Stat.AVERAGE_DURATION -> {
if (duration != null && numberOfSets != null) {
computedStat.secondValue = duration / numberOfSets
}
}
Stat.NET_BB_PER_100_HANDS -> {
if (bbNetResult != null && handsPlayed != null) {
computedStat.secondValue = Stat.netBBPer100Hands(bbNetResult, handsPlayed)
}
}
Stat.HOURLY_RATE_BB -> {
if (bbNetResult != null && duration != null) {
computedStat.secondValue = bbNetResult / duration
}
}
Stat.AVERAGE_NET_BB -> {
if (bbNetResult != null && bbSessionCount != null) {
computedStat.secondValue = bbNetResult / bbSessionCount
}
}
Stat.WIN_RATIO -> {
if (winningCount != null && numberOfGames != null) {
computedStat.secondValue = winningCount / numberOfGames
}
}
Stat.AVERAGE_BUYIN -> {
if (totalBuyin != null && numberOfGames != null) {
computedStat.secondValue = totalBuyin / numberOfGames
}
}
Stat.ROI -> {
if (totalBuyin != null && netResult != null) {
computedStat.secondValue = Stat.returnOnInvestment(netResult, totalBuyin)
}
}
} }
} }
} }
fun computedStat(stat: Stat): ComputedStat? { fun computedStat(stat: Stat): ComputedStat? {
@ -273,13 +340,6 @@ class ComputedResults(group: ComputableGroup) : StatEntry {
} }
} }
/**
* Returns the number of computed stats
*/
fun numberOfStats(): Int {
return this._computedStats.size
}
// MPAndroidChart // MPAndroidChart
fun defaultStatEntries(stat: Stat): List<Entry> { fun defaultStatEntries(stat: Stat): List<Entry> {
@ -328,7 +388,7 @@ class ComputedResults(group: ComputableGroup) : StatEntry {
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)?.secondValue?.let { this.computedStat(stat)?.progressValue?.let {
return stat.format(it, context = context) return stat.format(it, context = context)
// return it.format(context) // return it.format(context)
} ?: run { } ?: run {

@ -269,6 +269,11 @@ class ComputedStat(var stat: Stat, var value: Double, var secondValue: Double? =
} }
} }
/**
* The value used to get evolution dataset
*/
var progressValue: Double? = null
/** /**
* The variation of the stat * The variation of the stat
*/ */

@ -146,9 +146,7 @@ class StatisticDetailsFragment : PokerAnalyticsFragment() {
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
val requiredStats: List<Stat> = listOf(stat) val report = Calculator.computeStatsWithEvolutionByAggregationType(realm, stat, computableGroup, aggregationType)
val report = Calculator.computeStatsWithEvolutionByAggregationType(realm, computableGroup, aggregationType, requiredStats)
reports[aggregationType] = report reports[aggregationType] = report
realm.close() realm.close()
@ -162,9 +160,7 @@ class StatisticDetailsFragment : PokerAnalyticsFragment() {
progressBar.hideWithAnimation() progressBar.hideWithAnimation()
graphContainer.showWithAnimation() graphContainer.showWithAnimation()
} }
} }
} }

@ -246,9 +246,8 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
val requiredStats: List<Stat> = listOf(stat)
val aggregationType = stat.aggregationTypes.first() val aggregationType = stat.aggregationTypes.first()
report = Calculator.computeStatsWithEvolutionByAggregationType(realm, computableGroup, aggregationType, requiredStats) report = Calculator.computeStatsWithEvolutionByAggregationType(realm, stat, computableGroup, aggregationType)
realm.close() realm.close()

Loading…
Cancel
Save