Refactoring and warning removal

sync
Laurent 3 years ago
parent 7c527699c2
commit 08167f721a
  1. 4
      app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt
  2. 10
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/calculus/calcul/StatRepresentable.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt
  5. 6
      app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt
  6. 6
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  7. 7
      app/src/main/java/net/pokeranalytics/android/ui/modules/calendar/CalendarDetailsFragment.kt
  8. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/data/CustomFieldDataFragment.kt
  9. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/session/SessionFragment.kt

@ -277,12 +277,12 @@ class Calculator {
val maxNetResult = computables.max(ComputableResult.Field.RATED_NET.identifier)?.toDouble() val maxNetResult = computables.max(ComputableResult.Field.RATED_NET.identifier)?.toDouble()
maxNetResult?.let { maxNetResult?.let {
results.addStat(MAXIMUM_NETRESULT, it) results.addStat(MAXIMUM_NET_RESULT, it)
} }
val minNetResult = computables.min(ComputableResult.Field.RATED_NET.identifier)?.toDouble() val minNetResult = computables.min(ComputableResult.Field.RATED_NET.identifier)?.toDouble()
minNetResult?.let { minNetResult?.let {
results.addStat(MINIMUM_NETRESULT, it) results.addStat(MINIMUM_NET_RESULT, it)
} }
Stat.netBBPer100Hands(bbSum, totalHands)?.let { netBB100 -> Stat.netBBPer100Hands(bbSum, totalHands)?.let { netBB100 ->

@ -45,8 +45,8 @@ enum class Stat(override var uniqueIdentifier: Int) : IntIdentifiable, RowRepres
HANDS_PLAYED(18), HANDS_PLAYED(18),
LOCATIONS_PLAYED(19), LOCATIONS_PLAYED(19),
LONGEST_STREAKS(20), LONGEST_STREAKS(20),
MAXIMUM_NETRESULT(21), MAXIMUM_NET_RESULT(21),
MINIMUM_NETRESULT(22), MINIMUM_NET_RESULT(22),
MAXIMUM_DURATION(23), MAXIMUM_DURATION(23),
DAYS_PLAYED(24), DAYS_PLAYED(24),
WINNING_SESSION_COUNT(25), WINNING_SESSION_COUNT(25),
@ -129,8 +129,8 @@ enum class Stat(override var uniqueIdentifier: Int) : IntIdentifiable, RowRepres
HANDS_PLAYED -> R.string.number_of_hands HANDS_PLAYED -> R.string.number_of_hands
LOCATIONS_PLAYED -> R.string.locations_played LOCATIONS_PLAYED -> R.string.locations_played
LONGEST_STREAKS -> R.string.longest_streaks LONGEST_STREAKS -> R.string.longest_streaks
MAXIMUM_NETRESULT -> R.string.max_net_result MAXIMUM_NET_RESULT -> R.string.max_net_result
MINIMUM_NETRESULT -> R.string.min_net_result MINIMUM_NET_RESULT -> R.string.min_net_result
MAXIMUM_DURATION -> R.string.longest_session MAXIMUM_DURATION -> R.string.longest_session
DAYS_PLAYED -> R.string.days_played DAYS_PLAYED -> R.string.days_played
TOTAL_BUYIN -> R.string.total_buyin TOTAL_BUYIN -> R.string.total_buyin
@ -152,7 +152,7 @@ enum class Stat(override var uniqueIdentifier: Int) : IntIdentifiable, RowRepres
when (this) { when (this) {
// Amounts + red/green // Amounts + red/green
NET_RESULT, HOURLY_RATE, AVERAGE, MAXIMUM_NETRESULT, MINIMUM_NETRESULT -> { NET_RESULT, HOURLY_RATE, AVERAGE, MAXIMUM_NET_RESULT, MINIMUM_NET_RESULT -> {
val color = if (value >= this.threshold) R.color.green else R.color.red val color = if (value >= this.threshold) R.color.green else R.color.red
return TextFormat(value.toCurrency(currency), color) return TextFormat(value.toCurrency(currency), color)
} }

@ -34,8 +34,8 @@ class StatRepresentable(var stat: Stat) : RowRepresentable {
Stat.HANDS_PLAYED -> R.string.number_of_hands Stat.HANDS_PLAYED -> R.string.number_of_hands
Stat.LOCATIONS_PLAYED -> R.string.locations_played Stat.LOCATIONS_PLAYED -> R.string.locations_played
Stat.LONGEST_STREAKS -> R.string.longest_streaks Stat.LONGEST_STREAKS -> R.string.longest_streaks
Stat.MAXIMUM_NETRESULT -> R.string.max_net_result Stat.MAXIMUM_NET_RESULT -> R.string.max_net_result
Stat.MINIMUM_NETRESULT -> R.string.min_net_result Stat.MINIMUM_NET_RESULT -> R.string.min_net_result
Stat.MAXIMUM_DURATION -> R.string.longest_session Stat.MAXIMUM_DURATION -> R.string.longest_session
Stat.DAYS_PLAYED -> R.string.days_played Stat.DAYS_PLAYED -> R.string.days_played
Stat.TOTAL_BUYIN -> R.string.total_buyin Stat.TOTAL_BUYIN -> R.string.total_buyin
@ -47,7 +47,7 @@ class StatRepresentable(var stat: Stat) : RowRepresentable {
} }
} }
override val resId: Int? override val resId: Int
get() { get() {
return resId(this.stat) return resId(this.stat)
} }

@ -114,7 +114,7 @@ open class Result : RealmObject(), Filterable {
// Computes the Net // Computes the Net
private fun computeNet(withBuyin: Boolean? = null) { private fun computeNet(withBuyin: Boolean? = null) {
val transactionsSum = transactions.sumByDouble { it.amount } val transactionsSum = transactions.sumOf { it.amount }
// choose the method to compute the net // choose the method to compute the net
var useBuyin = withBuyin ?: true var useBuyin = withBuyin ?: true

@ -61,9 +61,9 @@ open class SessionSet() : RealmObject(), Timed, Filterable {
override var netDuration: Long = 0L override var netDuration: Long = 0L
fun computeStats() { fun computeStats() {
this.ratedNet = this.sessions?.sumByDouble { it.computableResult?.ratedNet ?: 0.0 } ?: 0.0 this.ratedNet = this.sessions?.sumOf { it.computableResult?.ratedNet ?: 0.0 } ?: 0.0
this.estimatedHands = this.sessions?.sumByDouble { it.estimatedHands } ?: 0.0 this.estimatedHands = this.sessions?.sumOf { it.estimatedHands } ?: 0.0
this.bbNet = this.sessions?.sumByDouble { it.bbNet } ?: 0.0 this.bbNet = this.sessions?.sumOf { it.bbNet } ?: 0.0
this.breakDuration = this.sessions?.max("breakDuration")?.toLong() ?: 0L this.breakDuration = this.sessions?.max("breakDuration")?.toLong() ?: 0L
} }

@ -332,7 +332,7 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable,
val sortedActions = this.sortedActions val sortedActions = this.sortedActions
val firstIndexOfStreet = sortedActions.firstOrNull { it.street == street }?.index val firstIndexOfStreet = sortedActions.firstOrNull { it.street == street }?.index
?: sortedActions.size ?: sortedActions.size
return this.anteSum + sortedActions.take(firstIndexOfStreet).sumByDouble { it.effectiveAmount } return this.anteSum + sortedActions.take(firstIndexOfStreet).sumOf { it.effectiveAmount }
} }
@Ignore @Ignore
@ -579,14 +579,14 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable,
val allinPositions = streetActions.filter { it.type?.isAllin == true }.map { it.position } val allinPositions = streetActions.filter { it.type?.isAllin == true }.map { it.position }
if (allinPositions.isEmpty()) { if (allinPositions.isEmpty()) {
runningPotAmount += streetActions.sumByDouble { it.effectiveAmount } runningPotAmount += streetActions.sumOf { it.effectiveAmount }
} else { } else {
val amountsPerPosition = mutableListOf<PositionAmount>() val amountsPerPosition = mutableListOf<PositionAmount>()
// get all committed amounts for the street by player, by allin // get all committed amounts for the street by player, by allin
this.positionIndexes.map { position -> this.positionIndexes.map { position ->
val playerActions = streetActions.filter { it.position == position } val playerActions = streetActions.filter { it.position == position }
val sum = playerActions.sumByDouble { it.effectiveAmount } val sum = playerActions.sumOf { it.effectiveAmount }
amountsPerPosition.add(PositionAmount(position, sum, allinPositions.contains(position))) amountsPerPosition.add(PositionAmount(position, sum, allinPositions.contains(position)))
} }
amountsPerPosition.sortWith(this) // sort by value, then allin. Allin must be first of equal values sequence amountsPerPosition.sortWith(this) // sort by value, then allin. Allin must be first of equal values sequence

@ -17,9 +17,9 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.calcul.defaultStatEntries
import net.pokeranalytics.android.calculus.Calculator import net.pokeranalytics.android.calculus.Calculator
import net.pokeranalytics.android.calculus.Stat import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.calculus.calcul.defaultStatEntries
import net.pokeranalytics.android.databinding.FragmentCalendarDetailsBinding import net.pokeranalytics.android.databinding.FragmentCalendarDetailsBinding
import net.pokeranalytics.android.model.filter.Query import net.pokeranalytics.android.model.filter.Query
import net.pokeranalytics.android.model.filter.QueryCondition import net.pokeranalytics.android.model.filter.QueryCondition
@ -32,11 +32,10 @@ import net.pokeranalytics.android.ui.helpers.AppReviewManager
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.ui.view.rows.CustomizableRowRepresentable import net.pokeranalytics.android.ui.view.rows.CustomizableRowRepresentable
import net.pokeranalytics.android.ui.view.rows.GraphRow
import net.pokeranalytics.android.ui.view.rows.DualStatRow import net.pokeranalytics.android.ui.view.rows.DualStatRow
import net.pokeranalytics.android.ui.view.rows.GraphRow
import timber.log.Timber import timber.log.Timber
import java.util.* import java.util.*
import kotlin.collections.ArrayList
class CalendarDetailsFragment : BaseFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { class CalendarDetailsFragment : BaseFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate {
@ -215,7 +214,7 @@ class CalendarDetailsFragment : BaseFragment(), StaticRowRepresentableDataSource
stat = Stat.STANDARD_DEVIATION stat = Stat.STANDARD_DEVIATION
) )
) )
rowRepresentables.add(DualStatRow(it.computedStat(Stat.WIN_RATIO), it.computedStat(Stat.MAXIMUM_NETRESULT))) rowRepresentables.add(DualStatRow(it.computedStat(Stat.WIN_RATIO), it.computedStat(Stat.MAXIMUM_NET_RESULT)))
rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.volume)) rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.volume))
rowRepresentables.add(GraphRow(durationDataSet, report = report, stat = Stat.HOURLY_DURATION)) rowRepresentables.add(GraphRow(durationDataSet, report = report, stat = Stat.HOURLY_DURATION))
rowRepresentables.add(DualStatRow(it.computedStat(Stat.HOURLY_DURATION), it.computedStat(Stat.AVERAGE_HOURLY_DURATION))) rowRepresentables.add(DualStatRow(it.computedStat(Stat.HOURLY_DURATION), it.computedStat(Stat.AVERAGE_HOURLY_DURATION)))

@ -211,9 +211,9 @@ class CustomFieldDataFragment : EditableDataFragment(), StaticRowRepresentableDa
*/ */
private fun initUI() { private fun initUI() {
val addItem = binding.addItem // val addItem = binding.addItem
val sortChoices = binding.sortChoices // val sortChoices = binding.sortChoices
val sortDescending = binding.sortDescending // val sortDescending = binding.sortDescending
val recyclerView = binding.recyclerView val recyclerView = binding.recyclerView
customField.updateRowRepresentation() customField.updateRowRepresentation()

@ -408,7 +408,7 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate, StaticRowRepr
CoroutineScope(coroutineContext).launch { CoroutineScope(coroutineContext).launch {
var optimalDuration: Double? = null var optimalDuration: Double?
val cr = GlobalScope.async { val cr = GlobalScope.async {
} }

Loading…
Cancel
Save