|
|
|
@ -1,17 +1,23 @@ |
|
|
|
package net.pokeranalytics.android.model.realm.handhistory |
|
|
|
package net.pokeranalytics.android.model.realm.handhistory |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import io.realm.RealmList |
|
|
|
import io.realm.RealmList |
|
|
|
import io.realm.RealmObject |
|
|
|
import io.realm.RealmObject |
|
|
|
import io.realm.annotations.Ignore |
|
|
|
import io.realm.annotations.Ignore |
|
|
|
import io.realm.annotations.PrimaryKey |
|
|
|
import io.realm.annotations.PrimaryKey |
|
|
|
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.model.filter.Filterable |
|
|
|
import net.pokeranalytics.android.model.filter.Filterable |
|
|
|
import net.pokeranalytics.android.model.handhistory.HandSetup |
|
|
|
import net.pokeranalytics.android.model.handhistory.HandSetup |
|
|
|
import net.pokeranalytics.android.model.handhistory.Position |
|
|
|
import net.pokeranalytics.android.model.handhistory.Position |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.handhistory.Street |
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
import net.pokeranalytics.android.model.interfaces.TimeFilterable |
|
|
|
import net.pokeranalytics.android.model.interfaces.TimeFilterable |
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.CardHolder |
|
|
|
import net.pokeranalytics.android.ui.modules.handhistory.model.CardHolder |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
|
|
|
import net.pokeranalytics.android.util.extensions.addLineReturn |
|
|
|
|
|
|
|
import net.pokeranalytics.android.util.extensions.formatted |
|
|
|
|
|
|
|
import net.pokeranalytics.android.util.extensions.fullDate |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterable, TimeFilterable, |
|
|
|
open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterable, TimeFilterable, |
|
|
|
@ -148,10 +154,10 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
this.actions.add(action) |
|
|
|
this.actions.add(action) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// fun cardsForStreet(street: Street): MutableList<Card> { |
|
|
|
fun cardsForStreet(street: Street): MutableList<Card> { |
|
|
|
// return this.board.sortedBy { it.index }.take(street.totalBoardCards).toMutableList() |
|
|
|
return this.board.sortedBy { it.index }.take(street.totalBoardCards).toMutableList() |
|
|
|
// } |
|
|
|
} |
|
|
|
// |
|
|
|
|
|
|
|
// fun playerSetupForPosition(position: Int) : PlayerSetup { |
|
|
|
// fun playerSetupForPosition(position: Int) : PlayerSetup { |
|
|
|
// this.playerSetups.firstOrNull { it.position == position }?.let { |
|
|
|
// this.playerSetups.firstOrNull { it.position == position }?.let { |
|
|
|
// return it |
|
|
|
// return it |
|
|
|
@ -182,6 +188,11 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val sortedActions: List<Action> |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
return this.actions.sortedBy { it.index } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun undefinedPositions(): List<Position> { |
|
|
|
fun undefinedPositions(): List<Position> { |
|
|
|
val positions = Position.positionsPerPlayers(this.numberOfPlayers) |
|
|
|
val positions = Position.positionsPerPlayers(this.numberOfPlayers) |
|
|
|
val copy = positions.clone() as LinkedHashSet<Position> |
|
|
|
val copy = positions.clone() as LinkedHashSet<Position> |
|
|
|
@ -198,4 +209,95 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab |
|
|
|
return playerSetup |
|
|
|
return playerSetup |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
|
|
|
* Returns the pot size at the start of the given [street] |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
fun potSizeForStreet(street: Street): Double { |
|
|
|
|
|
|
|
val sortedActions = this.sortedActions |
|
|
|
|
|
|
|
val firstIndexOfStreet = sortedActions.firstOrNull { it.street == street }?.index |
|
|
|
|
|
|
|
?: sortedActions.size |
|
|
|
|
|
|
|
return this.anteSum + sortedActions.take(firstIndexOfStreet).sumByDouble { it.effectiveAmount } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun localizedString(context: Context): CharSequence { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val positions = Position.positionsPerPlayers(this.numberOfPlayers) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var string = "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Settings |
|
|
|
|
|
|
|
val players = "${this.numberOfPlayers} ${context.getString(R.string.players)}" |
|
|
|
|
|
|
|
val firstLineComponents = mutableListOf(this.date.fullDate(), players) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.smallBlind?.let { sb -> |
|
|
|
|
|
|
|
this.bigBlind?.let { bb -> |
|
|
|
|
|
|
|
firstLineComponents.add("$sb/$bb") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.ante > 0.0) { |
|
|
|
|
|
|
|
firstLineComponents.add("ante ${this.ante}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
string = string.plus(firstLineComponents.joinToString(" - ")) |
|
|
|
|
|
|
|
string = string.addLineReturn(2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Players |
|
|
|
|
|
|
|
this.playerSetups.sortedBy { it.position }.forEach { |
|
|
|
|
|
|
|
string = string.plus(localizedPlayerSetup(it, positions, context)) |
|
|
|
|
|
|
|
string = string.addLineReturn() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Actions per street |
|
|
|
|
|
|
|
val sortedActions = this.actions.sortedBy { it.index } |
|
|
|
|
|
|
|
Street.values().forEach { street -> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string = string.addLineReturn(2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val streetActions = sortedActions.filter { it.street == street } |
|
|
|
|
|
|
|
if (streetActions.isNotEmpty()) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val streetItems = mutableListOf<CharSequence>(context.getString(street.resId)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val potSize = this.potSizeForStreet(street) |
|
|
|
|
|
|
|
if (potSize > 0) { |
|
|
|
|
|
|
|
streetItems.add(context.getString(R.string.pot_size)) |
|
|
|
|
|
|
|
streetItems.add(potSize.formatted()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.cards.isNotEmpty()) { |
|
|
|
|
|
|
|
streetItems.add(this.cardsForStreet(street).formatted(context) ?: "") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
string = string.plus(streetItems.joinToString(" ")) |
|
|
|
|
|
|
|
string = string.addLineReturn() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
streetActions.forEach { action -> |
|
|
|
|
|
|
|
string = string.plus(localizedAction(action, positions, context)) |
|
|
|
|
|
|
|
string = string.addLineReturn() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun localizedPlayerSetup(playerSetup: PlayerSetup, positions: LinkedHashSet<Position>, context: Context): String { |
|
|
|
|
|
|
|
val playerItems = mutableListOf(positions.elementAt(playerSetup.position).value) |
|
|
|
|
|
|
|
playerItems.add("[${this.cards.formatted(context)}]") |
|
|
|
|
|
|
|
playerSetup.stack?.let { stack -> |
|
|
|
|
|
|
|
playerItems.add("- $stack") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return playerItems.joinToString(" ") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun localizedAction(action: Action, positions: LinkedHashSet<Position>, context: Context): String { |
|
|
|
|
|
|
|
val actionItems = mutableListOf(positions.elementAt(action.position).value) |
|
|
|
|
|
|
|
action.type?.let { type -> |
|
|
|
|
|
|
|
actionItems.add(context.getString(type.resId)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
action.amount?.let { amount -> |
|
|
|
|
|
|
|
actionItems.add(amount.formatted()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return actionItems.joinToString(" ") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |