|
|
|
|
@ -33,8 +33,11 @@ import net.pokeranalytics.android.ui.graph.Graph |
|
|
|
|
import net.pokeranalytics.android.ui.view.* |
|
|
|
|
import net.pokeranalytics.android.ui.view.rows.SessionPropertiesRow |
|
|
|
|
import net.pokeranalytics.android.util.* |
|
|
|
|
import net.pokeranalytics.android.util.extensions.* |
|
|
|
|
import java.lang.ref.WeakReference |
|
|
|
|
import net.pokeranalytics.android.util.extensions.hourMinute |
|
|
|
|
import net.pokeranalytics.android.util.extensions.shortDateTime |
|
|
|
|
import net.pokeranalytics.android.util.extensions.toCurrency |
|
|
|
|
import net.pokeranalytics.android.util.extensions.toMinutes |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.text.DateFormat |
|
|
|
|
import java.text.NumberFormat |
|
|
|
|
import java.text.ParseException |
|
|
|
|
@ -68,7 +71,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
fun newInstance(realm: Realm, isTournament: Boolean, bankroll: Bankroll? = null): Session { |
|
|
|
|
val session = Session() |
|
|
|
|
val result = Result() |
|
|
|
|
result.inverseSession = WeakReference(session) |
|
|
|
|
// result.inverseSession = WeakReference(session) |
|
|
|
|
session.result = result |
|
|
|
|
|
|
|
|
|
if (bankroll != null) { |
|
|
|
|
@ -160,18 +163,10 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
var result: Result? = null |
|
|
|
|
|
|
|
|
|
@LinkingObjects("session") |
|
|
|
|
private val managedComputableResults: RealmResults<ComputableResult>? = null |
|
|
|
|
private val computableResults: RealmResults<ComputableResult>? = null |
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
|
val managedComputableResult: ComputableResult? = this.managedComputableResults?.firstOrNull() |
|
|
|
|
|
|
|
|
|
@Ignore |
|
|
|
|
var inverseComputableResult: WeakReference<ComputableResult>? = null |
|
|
|
|
|
|
|
|
|
// @Ignore |
|
|
|
|
fun computableResult() : ComputableResult? { |
|
|
|
|
return this.inverseComputableResult?.get() |
|
|
|
|
} |
|
|
|
|
val computableResult: ComputableResult? = this.computableResults?.firstOrNull() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Timed interface |
|
|
|
|
@ -225,8 +220,8 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
if (value != null && this.endDate != null && value.after(this.endDate)) { |
|
|
|
|
this.endDate = null |
|
|
|
|
} |
|
|
|
|
// this.dateChanged() |
|
|
|
|
this.computeStats() |
|
|
|
|
this.dateChanged() |
|
|
|
|
// this.computeStats() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -245,9 +240,9 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.computeNetDuration() |
|
|
|
|
// this.dateChanged() |
|
|
|
|
this.dateChanged() |
|
|
|
|
this.defineDefaultTournamentBuyinIfNecessary() |
|
|
|
|
this.computeStats() |
|
|
|
|
// this.computeStats() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -257,7 +252,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.computeNetDuration() |
|
|
|
|
this.computeStats() |
|
|
|
|
// this.computeStats() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -285,7 +280,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.generateStakes() |
|
|
|
|
this.computeStats() |
|
|
|
|
// this.computeStats() |
|
|
|
|
// this.updateRowRepresentation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -313,7 +308,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
set(value) { |
|
|
|
|
if (value > 0) { |
|
|
|
|
field = value |
|
|
|
|
this.computeStats() |
|
|
|
|
// this.computeStats() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -340,7 +335,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.computeStats() |
|
|
|
|
this.result?.computeNumberOfRebuy() |
|
|
|
|
// this.result?.computeNumberOfRebuy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// var blinds: String? = null |
|
|
|
|
@ -351,8 +346,8 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
field = value |
|
|
|
|
this.generateStakes() |
|
|
|
|
this.defineHighestBet() |
|
|
|
|
this.computeStats() |
|
|
|
|
this.result?.computeNumberOfRebuy() |
|
|
|
|
// this.computeStats() |
|
|
|
|
// this.result?.computeNumberOfRebuy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var cgBlinds: String? = null |
|
|
|
|
@ -360,8 +355,8 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
field = cleanupBlinds(value) |
|
|
|
|
this.generateStakes() |
|
|
|
|
this.defineHighestBet() |
|
|
|
|
this.computeStats() |
|
|
|
|
this.result?.computeNumberOfRebuy() |
|
|
|
|
// this.computeStats() |
|
|
|
|
// this.result?.computeNumberOfRebuy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var cgBiggestBet: Double? = null |
|
|
|
|
@ -374,7 +369,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
var tournamentEntryFee: Double? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.result?.computeNumberOfRebuy() |
|
|
|
|
// this.result?.computeNumberOfRebuy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// The total number of players who participated in the tournament |
|
|
|
|
@ -396,13 +391,17 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
var handsCount: Int? = null |
|
|
|
|
set(value) { |
|
|
|
|
field = value |
|
|
|
|
this.computeStats() |
|
|
|
|
// this.computeStats() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun bankrollHasBeenUpdated() { |
|
|
|
|
this.generateStakes() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun dateChanged() { |
|
|
|
|
SessionSetManager.dateChange = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// /** |
|
|
|
|
// * Manages impacts on SessionSets |
|
|
|
|
// * Should be called when the start / end date are changed |
|
|
|
|
@ -489,35 +488,35 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
return this.result?.net ?: 0.0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun preCompute() { |
|
|
|
|
this.computeStats() |
|
|
|
|
this.sessionSet?.computeStats() |
|
|
|
|
this.result?.computeNumberOfRebuy() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Pre-compute various statIds |
|
|
|
|
*/ |
|
|
|
|
fun computeStats() { |
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
val currentComputableResult = realm.computableResult(this) |
|
|
|
|
|
|
|
|
|
// ComputableResult are created only when a session is over |
|
|
|
|
if (this.startDate != null && this.endDate != null && currentComputableResult == null && this.inverseComputableResult?.get() == null) { |
|
|
|
|
val computableResult = ComputableResult() |
|
|
|
|
if (this.startDate != null && this.endDate != null && this.computableResults?.size == 0) { |
|
|
|
|
val computableResult = realm.createObject(ComputableResult::class.java) |
|
|
|
|
computableResult.session = this |
|
|
|
|
this.inverseComputableResult = WeakReference(computableResult) |
|
|
|
|
} // if a ComputableResult exists and the session is not completed, delete it |
|
|
|
|
else if ((this.startDate == null || this.endDate == null) && currentComputableResult != null && currentComputableResult.isValid) { |
|
|
|
|
currentComputableResult.deleteFromRealm() |
|
|
|
|
else if ((this.startDate == null || this.endDate == null) && this.computableResult != null && this.computableResult.isValid) { |
|
|
|
|
this.computableResult.deleteFromRealm() |
|
|
|
|
} |
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
this.computableResult()?.updateWith(this) |
|
|
|
|
|
|
|
|
|
// Update the ComputableResult |
|
|
|
|
// this.computableResult()?.forEachIndexed { index, computableResult -> |
|
|
|
|
// computableResult.updateWith(this) |
|
|
|
|
// if (index > 0) { |
|
|
|
|
// throw PAIllegalStateException("Session cannot have more than one computable result") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
this.computableResults?.forEachIndexed { index, computableResult -> |
|
|
|
|
computableResult.updateWith(this) |
|
|
|
|
if (index > 0) { |
|
|
|
|
throw PAIllegalStateException("Session cannot have more than one computable result") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
this.sessionSet?.computeStats() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -707,42 +706,9 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getFormattedStakes(): String { |
|
|
|
|
|
|
|
|
|
return this.cgStakes?.let { StakesHolder.readableStakes(it) } ?: run { NULL_TEXT } |
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
// val formattedBlinds = StakesHolder.formattedBlinds(this.cgBlinds, this.currency) |
|
|
|
|
// val formattedAntes = StakesHolder.formattedAnte(this.cgAnte, this.currency) |
|
|
|
|
// |
|
|
|
|
// return StakesHolder.formattedStakes(formattedBlinds, formattedAntes) |
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// val components = arrayListOf<String>() |
|
|
|
|
// this.formattedBlinds?.let { components.add(it) } |
|
|
|
|
// this.formattedAnte?.let { components.add("($it)") } |
|
|
|
|
// |
|
|
|
|
// return if (components.isNotEmpty()) { |
|
|
|
|
// components.joinToString(" ") |
|
|
|
|
// } else { |
|
|
|
|
// NULL_TEXT |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// fun formatBlinds() { |
|
|
|
|
// blinds = null |
|
|
|
|
// if (cgBigBlind == null) return |
|
|
|
|
// cgBigBlind?.let { bb -> |
|
|
|
|
// val sb = cgSmallBlind ?: bb / 2.0 |
|
|
|
|
// val preFormattedBlinds = "${sb.formatted}/${bb.round()}" |
|
|
|
|
// println("<<<<<< bb.toCurrency(currency) : ${bb.toCurrency(currency)}") |
|
|
|
|
// println("<<<<<< preFormattedBlinds : $preFormattedBlinds") |
|
|
|
|
// val regex = Regex("-?\\d+(\\.\\d+)?") |
|
|
|
|
// blinds = bb.toCurrency(currency).replace(regex, preFormattedBlinds) |
|
|
|
|
// println("<<<<<< blinds = $blinds") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// LifeCycle |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -772,7 +738,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
} |
|
|
|
|
// cleanup unnecessary related objects |
|
|
|
|
this.result?.deleteFromRealm() |
|
|
|
|
this.computableResult()?.deleteFromRealm() |
|
|
|
|
this.computableResult?.deleteFromRealm() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -807,32 +773,12 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
when (row) { |
|
|
|
|
SessionPropertiesRow.BANKROLL -> bankroll = value as Bankroll? |
|
|
|
|
SessionPropertiesRow.STAKES -> if (value is Stakes) { |
|
|
|
|
|
|
|
|
|
if (value.ante != null) { |
|
|
|
|
this.cgAnte = value.ante |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (value.blinds != null) { |
|
|
|
|
this.cgBlinds = value.blinds |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// cgSmallBlind = try { |
|
|
|
|
// (value[0] as String? ?: "0").toDouble() |
|
|
|
|
// } catch (e: Exception) { |
|
|
|
|
// null |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// cgBigBlind = try { |
|
|
|
|
// (value[1] as String? ?: "0").toDouble() |
|
|
|
|
// } catch (e: Exception) { |
|
|
|
|
// null |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// cgBigBlind?.let { |
|
|
|
|
// if (cgSmallBlind == null || cgSmallBlind == 0.0) { |
|
|
|
|
// cgSmallBlind = it / 2.0 |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
} else if (value == null) { |
|
|
|
|
this.cgBlinds = null |
|
|
|
|
this.cgAnte = null |
|
|
|
|
@ -843,15 +789,21 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
SessionPropertiesRow.BUY_IN -> { |
|
|
|
|
val localResult = getOrCreateResult() |
|
|
|
|
localResult.buyin = value as Double? |
|
|
|
|
// this.updateRowRepresentation() |
|
|
|
|
} |
|
|
|
|
SessionPropertiesRow.CASHED_OUT, SessionPropertiesRow.PRIZE -> { |
|
|
|
|
val localResult = getOrCreateResult() |
|
|
|
|
localResult.cashout = value as Double? |
|
|
|
|
Timber.d("localResult cashout = ${localResult.cashout}") |
|
|
|
|
if (value != null) { |
|
|
|
|
this.end() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SessionPropertiesRow.NET_RESULT -> { |
|
|
|
|
val localResult = getOrCreateResult() |
|
|
|
|
localResult.netResult = value as Double? |
|
|
|
|
if (value != null) { |
|
|
|
|
this.end() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SessionPropertiesRow.COMMENT -> comment = value as String? ?: "" |
|
|
|
|
SessionPropertiesRow.END_DATE -> if (value is Date?) { |
|
|
|
|
@ -907,12 +859,10 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
SessionPropertiesRow.TOURNAMENT_NAME -> tournamentName = value as TournamentName? |
|
|
|
|
SessionPropertiesRow.TOURNAMENT_TYPE -> tournamentType = (value as TournamentType?)?.ordinal |
|
|
|
|
SessionPropertiesRow.TOURNAMENT_FEATURE -> { |
|
|
|
|
|
|
|
|
|
this.tournamentFeatures.clear() |
|
|
|
|
value?.let { |
|
|
|
|
tournamentFeatures = RealmList() |
|
|
|
|
tournamentFeatures.addAll((it as ArrayList<TournamentFeature>)) |
|
|
|
|
} ?: run { |
|
|
|
|
tournamentFeatures.removeAll(this.tournamentFeatures) |
|
|
|
|
tournamentFeatures.addAll((it as List<TournamentFeature>)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SessionPropertiesRow.HANDS_COUNT -> handsCount = (value as Double?)?.toInt() |
|
|
|
|
@ -945,11 +895,11 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
private fun getOrCreateResult(): Result { |
|
|
|
|
return this.result |
|
|
|
|
?: run { |
|
|
|
|
val result = realm.createObject(Result::class.java) |
|
|
|
|
result.inverseSession = WeakReference(this) |
|
|
|
|
this.result = result |
|
|
|
|
result |
|
|
|
|
} |
|
|
|
|
val result = Result() |
|
|
|
|
// result.inverseSession = WeakReference(this) |
|
|
|
|
this.result = result |
|
|
|
|
result |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Stat Entry |
|
|
|
|
@ -1030,7 +980,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
var right: TextFormat? = null |
|
|
|
|
|
|
|
|
|
if (!hasMainCurrencyCode) { |
|
|
|
|
this.managedComputableResult?.ratedNet?.let { ratedNet -> |
|
|
|
|
this.computableResult?.ratedNet?.let { ratedNet -> |
|
|
|
|
right = Stat.NET_RESULT.textFormat(ratedNet) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -1060,7 +1010,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim |
|
|
|
|
SessionPropertiesRow.BUY_IN -> this.result?.buyin?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionPropertiesRow.CASHED_OUT, SessionPropertiesRow.PRIZE -> this.result?.cashout?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionPropertiesRow.NET_RESULT -> this.result?.netResult?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
SessionPropertiesRow.COMMENT -> if (this.comment.isNotEmpty()) this.comment else NULL_TEXT |
|
|
|
|
SessionPropertiesRow.COMMENT -> this.comment.ifEmpty { NULL_TEXT } |
|
|
|
|
SessionPropertiesRow.END_DATE -> this.endDate?.shortDateTime() ?: NULL_TEXT |
|
|
|
|
SessionPropertiesRow.GAME -> getFormattedGame() |
|
|
|
|
SessionPropertiesRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency(currency) ?: NULL_TEXT |
|
|
|
|
|