@ -11,9 +11,9 @@ import io.realm.annotations.LinkingObjects
import io.realm.annotations.PrimaryKey
import io.realm.annotations.PrimaryKey
import io.realm.kotlin.where
import io.realm.kotlin.where
import net.pokeranalytics.android.R
import net.pokeranalytics.android.R
import net.pokeranalytics.android.calculus.DataManager
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.calculus.StatFormattingException
import net.pokeranalytics.android.calculus.StatFormattingException
import net.pokeranalytics.android.exceptions.ModelException
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.Stakes
import net.pokeranalytics.android.model.Stakes
@ -27,6 +27,7 @@ import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.filter.QueryCondition.*
import net.pokeranalytics.android.model.filter.QueryCondition.*
import net.pokeranalytics.android.model.interfaces.*
import net.pokeranalytics.android.model.interfaces.*
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.utils.SessionSetManager
import net.pokeranalytics.android.ui.adapter.UnmanagedRowRepresentableException
import net.pokeranalytics.android.ui.adapter.UnmanagedRowRepresentableException
import net.pokeranalytics.android.ui.graph.Graph
import net.pokeranalytics.android.ui.graph.Graph
import net.pokeranalytics.android.ui.view.*
import net.pokeranalytics.android.ui.view.*
@ -44,7 +45,7 @@ import java.util.Currency
typealias BB = Double
typealias BB = Double
open class Session : RealmObject ( ) , Savable , RowRepresentable , Timed ,
open class Session : RealmObject ( ) , Savable , RowUpdatable , Row Representable , Timed ,
TimeFilterable , Filterable , DatedBankrollGraphEntry , StakesHolder {
TimeFilterable , Filterable , DatedBankrollGraphEntry , StakesHolder {
enum class Type ( val value : String ) {
enum class Type ( val value : String ) {
@ -66,23 +67,24 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
companion object {
companion object {
fun newInstance ( realm : Realm , isTournament : Boolean , bankroll : Bankroll ? = null ) : Session {
fun newInstance ( realm : Realm , isTournament : Boolean , bankroll : Bankroll ? = null , managed : Boolean = true ) : Session {
val session = Session ( )
val session = Session ( )
session . result = Result ( )
val br : Bankroll ? = bankroll ?: realm . where < Bankroll > ( ) . findFirst ( )
if ( bankroll != null ) {
br ?. let {
session . bankroll = bankroll
session . bankroll = realm . copyFromRealm ( br )
} else {
session . bankroll = realm . where < Bankroll > ( ) . findFirst ( )
}
}
session . type = if ( isTournament ) Type . TOURNAMENT . ordinal else Type . CASH _GAME . ordinal
session . type = if ( isTournament ) Type . TOURNAMENT . ordinal else Type . CASH _GAME . ordinal
session . limit = Limit . NO . ordinal
session . limit = Limit . NO . ordinal
session . game = realm . where ( Game :: class . java ) . equalTo ( " shortName " , " HE " ) . findFirst ( )
val game = realm . where ( Game :: class . java ) . equalTo ( " shortName " , " HE " ) . findFirst ( )
return if ( managed ) {
game ?. let {
realm . copyToRealm ( session )
session . game = realm . copyFromRealm ( game )
} else {
session
}
}
return session
}
}
fun fieldNameForQueryType ( queryCondition : Class < out QueryCondition > ) : String ? {
fun fieldNameForQueryType ( queryCondition : Class < out QueryCondition > ) : String ? {
@ -100,9 +102,9 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
AnyStake :: class . java -> " cgStakes "
AnyStake :: class . java -> " cgStakes "
NumberOfTable :: class . java -> " numberOfTables "
NumberOfTable :: class . java -> " numberOfTables "
NetAmountWon :: class . java , NetAmountLost :: class . java -> " computableResults.ratedNet "
NetAmountWon :: class . java , NetAmountLost :: class . java -> " computableResults.ratedNet "
NumberOfRebuy :: class . java -> " numberOfRebuy "
NumberOfRebuy :: class . java -> " result. numberOfRebuy"
TournamentNumberOfPlayer :: class . java -> " tournamentNumberOfPlayers "
TournamentNumberOfPlayer :: class . java -> " tournamentNumberOfPlayers "
TournamentFinalPosition :: class . java -> " tournamentFinalPosition "
TournamentFinalPosition :: class . java -> " result. tournamentFinalPosition"
TournamentFee :: class . java -> " tournamentEntryFee "
TournamentFee :: class . java -> " tournamentEntryFee "
StartedFromDate :: class . java , StartedToDate :: class . java , EndedFromDate :: class . java , EndedToDate :: class . java -> " startDate "
StartedFromDate :: class . java , StartedToDate :: class . java , EndedFromDate :: class . java , EndedToDate :: class . java -> " startDate "
AnyDayOfWeek :: class . java , IsWeekEnd :: class . java , IsWeekDay :: class . java -> " dayOfWeek "
AnyDayOfWeek :: class . java , IsWeekEnd :: class . java , IsWeekDay :: class . java -> " dayOfWeek "
@ -116,7 +118,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
Duration :: class . java -> " netDuration "
Duration :: class . java -> " netDuration "
CustomFieldListQuery :: class . java -> " customFieldEntries.id "
CustomFieldListQuery :: class . java -> " customFieldEntries.id "
CustomFieldAmountQuery :: class . java , CustomFieldNumberQuery :: class . java -> " customFieldEntries.numericValue "
CustomFieldAmountQuery :: class . java , CustomFieldNumberQuery :: class . java -> " customFieldEntries.numericValue "
CustomFieldQuery :: class . java -> " customFieldEntries.customField.id "
CustomFieldQuery :: class . java -> " customFieldEntries.customFields .id "
DateNotNull :: class . java -> " startDate "
DateNotNull :: class . java -> " startDate "
EndDateNotNull :: class . java -> " endDate "
EndDateNotNull :: class . java -> " endDate "
BiggestBetNotNull :: class . java -> " cgBiggestBet "
BiggestBetNotNull :: class . java -> " cgBiggestBet "
@ -146,7 +148,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
val sessionType : Type
val sessionType : Type
get ( ) { return Type . values ( ) [ this . type ] }
get ( ) { return Type . values ( ) [ this . type ] }
// Not used anymore
// The result of the main user
var result : Result ? = null
var result : Result ? = null
@LinkingObjects ( " session " )
@LinkingObjects ( " session " )
@ -207,7 +209,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
this . endDate = null
this . endDate = null
}
}
this . dateChanged ( )
this . dateChanged ( )
this . addToComputeQueue ( )
this . computeStats ( )
}
}
/ * *
/ * *
@ -228,7 +230,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
this . computeNetDuration ( )
this . computeNetDuration ( )
this . dateChanged ( )
this . dateChanged ( )
this . defineDefaultTournamentBuyinIfNecessary ( )
this . defineDefaultTournamentBuyinIfNecessary ( )
this . addToComputeQueue ( )
this . computeStats ( )
}
}
/ * *
/ * *
@ -238,7 +240,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
set ( value ) {
set ( value ) {
field = value
field = value
this . computeNetDuration ( )
this . computeNetDuration ( )
this . addToComputeQueue ( )
this . computeStats ( )
}
}
/ * *
/ * *
@ -250,6 +252,10 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
* The start date of the break
* The start date of the break
* /
* /
override var pauseDate : Date ? = null
override var pauseDate : Date ? = null
set ( value ) {
field = value
// this.updateRowRepresentation()
}
// The session set containing the sessions, which can contain multiple endedSessions
// The session set containing the sessions, which can contain multiple endedSessions
var sessionSet : SessionSet ? = null
var sessionSet : SessionSet ? = null
@ -262,7 +268,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
set ( value ) {
set ( value ) {
field = value
field = value
this . generateStakes ( )
this . generateStakes ( )
this . addToComputeQueue ( )
this . computeStats ( )
// this.updateRowRepresentation()
// this.updateRowRepresentation()
}
}
@ -290,7 +296,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
set ( value ) {
set ( value ) {
if ( value > 0 ) {
if ( value > 0 ) {
field = value
field = value
this . addToComputeQueue ( )
this . computeStats ( )
}
}
}
}
@ -308,13 +314,16 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
// The small blind value
// The small blind value
var cgOldSmallBlind : Double ? = null
var cgOldSmallBlind : Double ? = null
set ( value ) {
field = value
}
// The big blind value
// The big blind value
var cgOldBigBlind : Double ? = null
var cgOldBigBlind : Double ? = null
set ( value ) {
set ( value ) {
field = value
field = value
this . addToComputeQueue ( )
this . computeStats ( )
this . computeNumberOfRebuy ( )
this . result ?. computeNumberOfRebuy ( )
}
}
// var blinds: String? = null
// var blinds: String? = null
@ -325,8 +334,8 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
field = value
field = value
this . generateStakes ( )
this . generateStakes ( )
this . defineHighestBet ( )
this . defineHighestBet ( )
this . addToComputeQueue ( )
this . computeStats ( )
this . computeNumberOfRebuy ( )
this . result ?. computeNumberOfRebuy ( )
}
}
var cgBlinds : String ? = null
var cgBlinds : String ? = null
@ -334,8 +343,8 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
field = cleanupBlinds ( value )
field = cleanupBlinds ( value )
this . generateStakes ( )
this . generateStakes ( )
this . defineHighestBet ( )
this . defineHighestBet ( )
this . addToComputeQueue ( )
this . computeStats ( )
this . computeNumberOfRebuy ( )
this . result ?. computeNumberOfRebuy ( )
}
}
var cgBiggestBet : Double ? = null
var cgBiggestBet : Double ? = null
@ -348,7 +357,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
var tournamentEntryFee : Double ? = null
var tournamentEntryFee : Double ? = null
set ( value ) {
set ( value ) {
field = value
field = value
this . computeNumberOfRebuy ( )
this . result ?. computeNumberOfRebuy ( )
}
}
// The total number of players who participated in the tournament
// The total number of players who participated in the tournament
@ -370,131 +379,9 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
var handsCount : Int ? = null
var handsCount : Int ? = null
set ( value ) {
set ( value ) {
field = value
field = value
this . addToComputeQueue ( )
this . computeStats ( )
}
/ * *
* The buyin amount
* /
var buyin : Double ? = null
set ( value ) {
field = value
this . computeNumberOfRebuy ( )
this . computeNet ( true )
}
/ * *
* The cashed out amount
* /
var cashout : Double ? = null
set ( value ) {
field = value
this . computeNet ( true )
}
/ * *
* The net result
* /
var netResult : Double ? = null
set ( value ) {
field = value
this . computeNet ( false )
}
/ * *
* The pre - computed net ( readonly )
* /
var net : Double = 0.0
private set
/ * *
* Tips
* /
var tips : Double ? = null
set ( value ) {
field = value
this . addToComputeQueue ( )
}
// The transactions associated with the Result, impacting the result
var transactions : RealmList < Transaction > = RealmList ( )
set ( value ) {
field = value
this . computeNet ( )
}
// The tournament final position, if applicable
var tournamentFinalPosition : Int ? = null
// Number of rebuys
var numberOfRebuy : Double ? = null
//////////////////////////////
// Computes the Net
fun computeNet ( withBuyin : Boolean ? = null ) {
val transactionsSum = transactions . sumOf { it . amount }
// choose the method to compute the net
var useBuyin = withBuyin ?: true
if ( withBuyin == null ) {
if ( netResult != null ) {
useBuyin = false
} else if ( buyin != null || cashout != null ) {
useBuyin = true
} else {
if ( this . isCashGame ( ) && ! this . isLive ) {
useBuyin = false
}
}
}
}
if ( useBuyin ) {
val buyin = this . buyin ?: 0.0
val cashOut = this . cashout ?: 0.0
this . net = cashOut - buyin + transactionsSum
} else {
val netResult = this . netResult ?: 0.0
this . net = netResult + transactionsSum
}
// Precompute results
this . addToComputeQueue ( )
}
// Computes the number of rebuy
fun computeNumberOfRebuy ( ) {
if ( this . isCashGame ( ) ) {
this . cgBiggestBet ?. let { bb ->
if ( bb > 0.0 ) {
this . numberOfRebuy = ( this . buyin ?: 0.0 ) / ( bb * 100.0 )
} else {
this . numberOfRebuy = null
}
}
} else {
this . tournamentEntryFee ?. let { entryFee ->
if ( entryFee > 0.0 ) {
this . numberOfRebuy = ( this . buyin ?: 0.0 ) / entryFee
} else {
this . numberOfRebuy = null
}
}
}
}
val isPositive : Int
get ( ) {
return if ( this . isTournament ( ) ) {
if ( ( this . cashout ?: - 1.0 ) >= 0.0 ) 1 else 0 // if cashout is null we want to count a negative session
} else {
if ( this . net >= 0.0 ) 1 else 0
}
}
//////////////////////////////
fun bankrollHasBeenUpdated ( ) {
fun bankrollHasBeenUpdated ( ) {
this . generateStakes ( )
this . generateStakes ( )
}
}
@ -504,15 +391,11 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
* Should be called when the start / end date are changed
* Should be called when the start / end date are changed
* /
* /
private fun dateChanged ( ) {
private fun dateChanged ( ) {
if ( this . endDate != null ) {
DataManager . sessionDateChanged ( this )
SessionSetManager . updateTimeline ( this )
} else if ( this . sessionSet != null ) {
// if (this.endDate != null) {
SessionSetManager . removeFromTimeline ( this )
// SessionSetManager.updateTimeline(this)
}
// } else if (this.sessionSet != null) {
// SessionSetManager.removeFromTimeline(this)
// }
// this.updateRowRepresentation()
// this.updateRowRepresentation()
}
}
@ -552,9 +435,9 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
val bbNet : BB
val bbNet : BB
get ( ) {
get ( ) {
val bb = this . cgBiggestBet
val bb = this . cgBiggestBet
// val result = this. result
val result = this . result
return if ( bb != null ) {
return if ( bb != null && result != null ) {
this . net / bb
result . net / bb
} else {
} else {
0.0
0.0
}
}
@ -585,14 +468,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
@Ignore
@Ignore
override var amount : Double = 0.0
override var amount : Double = 0.0
get ( ) {
get ( ) {
return this . net
return this . result ?. net ?: 0.0
}
/ * *
* Pre - compute various statIds
* /
private fun addToComputeQueue ( ) {
DataManager . sessionToCompute ( this )
}
}
/ * *
/ * *
@ -625,13 +501,17 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
val numberOfHandsPerHour : Double
val numberOfHandsPerHour : Double
get ( ) {
get ( ) {
val tableSize = this . tableSize ?: 9 // 9 is the default table size if null
val tableSize = this . tableSize ?: 9 // 9 is the default table size if null
val dealtHandsPerHour = if ( this . isLive ) UserConfigObserver . liveDealtHandsPerHour else UserConfigObserver . onlineDealtHandsPerHour
val config = UserConfig . getConfiguration ( this . realm )
return this . numberOfTables * dealtHandsPerHour / tableSize . toDouble ( )
val playerHandsPerHour = if ( this . isLive ) config . liveDealtHandsPerHour else config . onlineDealtHandsPerHour
return this . numberOfTables * playerHandsPerHour / tableSize . toDouble ( )
}
}
val hourlyRate : Double
val hourlyRate : Double
get ( ) {
get ( ) {
return this . net / this . hourlyDuration
this . result ?. let { result ->
return result . net / this . hourlyDuration
}
throw ModelException ( " Session should have an existing Result relationship " )
}
}
private val bbHourlyRate : BB
private val bbHourlyRate : BB
@ -649,12 +529,12 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
val hasBuyin : Boolean
val hasBuyin : Boolean
get ( ) {
get ( ) {
return this . buyin != null
return this . result ?. buyin != null
}
}
val hasNetResult : Boolean
val hasNetResult : Boolean
get ( ) {
get ( ) {
return this . netResult != null
return this . result ?. netResult != null
}
}
// Manageable
// Manageable
@ -677,6 +557,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
* Start or continue a session
* Start or continue a session
* /
* /
fun startOrContinue ( ) {
fun startOrContinue ( ) {
realm . executeTransaction {
when ( val state = getState ( ) ) {
when ( val state = getState ( ) ) {
SessionState . PENDING , SessionState . PLANNED -> {
SessionState . PENDING , SessionState . PLANNED -> {
this . startDate = Date ( )
this . startDate = Date ( )
@ -696,10 +577,11 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
}
}
}
}
}
}
}
private fun defineDefaultTournamentBuyinIfNecessary ( ) {
private fun defineDefaultTournamentBuyinIfNecessary ( ) {
if ( this . tournamentEntryFee != null && this . buyin == null ) {
if ( this . tournamentEntryFee != null && this . result ?. buyin == null ) {
this . buyin = this . tournamentEntryFee
this . result ?. buyin = this . tournamentEntryFee
}
}
}
}
@ -707,6 +589,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
* Pause a session
* Pause a session
* /
* /
fun pause ( ) {
fun pause ( ) {
realm . executeTransaction {
when ( val state = getState ( ) ) {
when ( val state = getState ( ) ) {
SessionState . STARTED -> {
SessionState . STARTED -> {
this . pauseDate = Date ( )
this . pauseDate = Date ( )
@ -714,17 +597,20 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
else -> throw PAIllegalStateException ( " Pausing a session in an unmanaged state: $state " )
else -> throw PAIllegalStateException ( " Pausing a session in an unmanaged state: $state " )
}
}
}
}
}
/ * *
/ * *
* Stop a session
* Stop a session
* /
* /
fun stop ( context : Context ) {
fun stop ( context : Context ) {
realm . executeTransaction {
when ( val state = getState ( ) ) {
when ( val state = getState ( ) ) {
SessionState . STARTED , SessionState . PAUSED -> {
SessionState . STARTED , SessionState . PAUSED -> {
this . end ( )
this . end ( )
}
}
else -> throw Exception ( " Stopping session in unmanaged state: $state " )
else -> throw Exception ( " Stopping session in unmanaged state: $state " )
}
}
}
cancelStopNotification ( context )
cancelStopNotification ( context )
}
}
@ -732,11 +618,13 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
* Restart a session
* Restart a session
* /
* /
fun restart ( ) {
fun restart ( ) {
realm . executeTransaction {
this . pauseDate = null
this . pauseDate = null
this . startDate = Date ( )
this . startDate = Date ( )
this . endDate = null
this . endDate = null
this . breakDuration = 0L
this . breakDuration = 0L
}
}
}
/ * *
/ * *
* Utility method to cleanly end a session
* Utility method to cleanly end a session
@ -800,11 +688,10 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
if ( isValid ) {
if ( isValid ) {
// CrashLogging.log("Deletes session. Id = ${this.id}")
// CrashLogging.log("Deletes session. Id = ${this.id}")
realm . executeTransaction {
// realm.executeTransaction {
cleanup ( )
cleanup ( )
deleteFromRealm ( )
deleteFromRealm ( )
// }
}
} else {
} else {
CrashLogging . log ( " Attempt to delete an invalid session " )
CrashLogging . log ( " Attempt to delete an invalid session " )
}
}
@ -817,10 +704,10 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
// Updates the timeline
// Updates the timeline
this . sessionSet ?. let {
this . sessionSet ?. let {
Data Manager. removeFromTimeline ( this )
SessionSet Manager. removeFromTimeline ( this )
}
}
// cleanup unnecessary related objects
// cleanup unnecessary related objects
// this.deleteFromRealm( )
this . result ?. deleteFromRealm ( )
this . computableResults ?. deleteAllFromRealm ( )
this . computableResults ?. deleteAllFromRealm ( )
}
}
@ -851,7 +738,7 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
return " Session ${this.creationDate} "
return " Session ${this.creationDate} "
}
}
fun updateValue ( value : Any ? , row : RowRepresentable ) {
override fun updateValue ( value : Any ? , row : RowRepresentable ) {
when ( row ) {
when ( row ) {
SessionPropertiesRow . BANKROLL -> bankroll = value as Bankroll ?
SessionPropertiesRow . BANKROLL -> bankroll = value as Bankroll ?
@ -870,32 +757,23 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
this . breakDuration = ( value as Double ? ?: 0.0 ) . toLong ( ) * 60 * 1000
this . breakDuration = ( value as Double ? ?: 0.0 ) . toLong ( ) * 60 * 1000
}
}
SessionPropertiesRow . BUY _IN -> {
SessionPropertiesRow . BUY _IN -> {
// val localResult = getOrCreateResult( )
val localResult = getOrCreateResult ( )
this . buyin = value as Double ?
localResult . buyin = value as Double ?
}
}
SessionPropertiesRow . CASHED _OUT , SessionPropertiesRow . PRIZE -> {
SessionPropertiesRow . CASHED _OUT , SessionPropertiesRow . PRIZE -> {
// val localResult = getOrCreateResult()
val localResult = getOrCreateResult ( )
val cashOut = value as Double ?
localResult . cashout = value as Double ?
this . cashout = cashOut
if ( cashOut != null ) {
this . end ( )
}
}
}
SessionPropertiesRow . NET _RESULT -> {
SessionPropertiesRow . NET _RESULT -> {
// val localResult = getOrCreateResult()
val localResult = getOrCreateResult ( )
val netResult = value as Double ?
localResult . netResult = value as Double ?
this . netResult = netResult
if ( netResult != null ) {
this . end ( )
}
}
}
SessionPropertiesRow . COMMENT -> comment = value as String ? ?: " "
SessionPropertiesRow . COMMENT -> comment = value as String ? ?: " "
SessionPropertiesRow . END _DATE -> if ( value is Date ? ) {
SessionPropertiesRow . END _DATE -> if ( value is Date ? ) {
this . endDate = value
this . endDate = value
}
}
SessionPropertiesRow . GAME -> {
SessionPropertiesRow . GAME -> {
when ( value ) {
if ( value is ArrayList < * > ) {
is ArrayList < * > -> {
limit = try {
limit = try {
( value [ 0 ] as Int ? )
( value [ 0 ] as Int ? )
} catch ( e : Exception ) {
} catch ( e : Exception ) {
@ -906,16 +784,13 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
} catch ( e : Exception ) {
} catch ( e : Exception ) {
null
null
}
}
}
} else if ( value is Game ) {
is Game -> {
game = value
game = value
}
} else if ( value == null ) {
null -> {
limit = null
limit = null
game = null
game = null
}
}
}
}
}
SessionPropertiesRow . INITIAL _BUY _IN -> {
SessionPropertiesRow . INITIAL _BUY _IN -> {
this . tournamentEntryFee = ( value as Double ? )
this . tournamentEntryFee = ( value as Double ? )
}
}
@ -928,21 +803,21 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
}
}
}
}
SessionPropertiesRow . POSITION -> {
SessionPropertiesRow . POSITION -> {
// val localResult = if (result != null) result as Result else realm.createObject(Result::class.java )
val localResult = if ( result != null ) result as Result else realm . createObject ( Result :: class . java )
if ( value is Double ) {
if ( value is Double ) {
this . tournamentFinalPosition = value . toInt ( )
localResult . tournamentFinalPosition = value . toInt ( )
} else {
} else {
this . tournamentFinalPosition = null
localResult . tournamentFinalPosition = null
}
}
// result = localResult
result = localResult
}
}
SessionPropertiesRow . START _DATE -> if ( value is Date ) {
SessionPropertiesRow . START _DATE -> if ( value is Date ) {
this . startDate = value
this . startDate = value
}
}
SessionPropertiesRow . TABLE _SIZE -> tableSize = value as Int ?
SessionPropertiesRow . TABLE _SIZE -> tableSize = value as Int ?
SessionPropertiesRow . TIPS -> {
SessionPropertiesRow . TIPS -> {
// val localResult = getOrCreateResult( )
val localResult = getOrCreateResult ( )
this . tips = value as Double ?
localResult . tips = value as Double ?
}
}
SessionPropertiesRow . TOURNAMENT _NAME -> tournamentName = value as TournamentName ?
SessionPropertiesRow . TOURNAMENT _NAME -> tournamentName = value as TournamentName ?
SessionPropertiesRow . TOURNAMENT _TYPE -> tournamentType = ( value as TournamentType ? ) ?. ordinal
SessionPropertiesRow . TOURNAMENT _TYPE -> tournamentType = ( value as TournamentType ? ) ?. ordinal
@ -967,7 +842,6 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
if ( value != null ) {
if ( value != null ) {
val customFieldEntry = CustomFieldEntry ( )
val customFieldEntry = CustomFieldEntry ( )
customFieldEntry . numericValue = value as Double ?
customFieldEntry . numericValue = value as Double ?
customFieldEntry . customField = row
customFieldEntries . add ( customFieldEntry )
customFieldEntries . add ( customFieldEntry )
row . entries . add ( customFieldEntry )
row . entries . add ( customFieldEntry )
}
}
@ -983,25 +857,14 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
}
}
// private fun customFieldEntries(realm: Realm, customField: CustomField): List<CustomFieldEntry> {
private fun getOrCreateResult ( ) : Result {
//
return this . result
//// val cfEntries = customField.entries
?: run {
//// val sessionEntries = this.customFieldEntries
val result = realm . createObject ( Result :: class . java )
////
this . result = result
//// val entries = realm.where<CustomFieldEntry>()
result
//// .`in`()
}
//
}
// return listOf()
// }
// private fun getOrCreateResult(): Result {
// return this.result
// ?: run {
// val result = realm.createObject(Result::class.java)
// this.result = result
// result
// }
// }
// Stat Entry
// Stat Entry
@ -1016,13 +879,15 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
override fun formattedValue ( stat : Stat ) : TextFormat {
override fun formattedValue ( stat : Stat ) : TextFormat {
this . result ?. let { result ->
val value : Double ? = when ( stat ) {
val value : Double ? = when ( stat ) {
Stat . NET _RESULT , Stat . AVERAGE , Stat . STANDARD _DEVIATION -> this . net
Stat . NET _RESULT , Stat . AVERAGE , Stat . STANDARD _DEVIATION -> result . net
Stat . NUMBER _OF _GAMES , Stat . NUMBER _OF _SETS -> 1.0
Stat . NUMBER _OF _GAMES , Stat . NUMBER _OF _SETS -> 1.0
Stat . AVERAGE _BUYIN -> this . buyin
Stat . AVERAGE _BUYIN -> result . buyin
Stat . ROI -> {
Stat . ROI -> {
this . buyin ?. let {
result . buyin ?. let {
Stat . returnOnInvestment ( this . net , it )
Stat . returnOnInvestment ( result . net , it )
} ?: run {
} ?: run {
null
null
}
}
@ -1046,6 +911,10 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
return TextFormat ( NULL _TEXT )
return TextFormat ( NULL _TEXT )
}
}
} ?: run {
throw PAIllegalStateException ( " Asking for statIds on Session without Result " )
}
}
}
override fun legendValues (
override fun legendValues (
@ -1096,25 +965,25 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
@Ignore
@Ignore
override val realmObjectClass : Class < out Identifiable > = Session :: class . java
override val realmObjectClass : Class < out Identifiable > = Session :: class . java
fun charSequenceForRow ( row : RowRepresentable , context : Context , realm : Realm ) : String {
fun charSequenceForRow ( row : RowRepresentable , context : Context ) : String {
return when ( row ) {
return when ( row ) {
SessionPropertiesRow . BANKROLL -> bankroll ?. name ?: NULL _TEXT
SessionPropertiesRow . BANKROLL -> bankroll ?. name ?: NULL _TEXT
SessionPropertiesRow . STAKES -> getFormattedStakes ( )
SessionPropertiesRow . STAKES -> getFormattedStakes ( )
SessionPropertiesRow . BREAK _TIME -> if ( this . breakDuration > 0.0 ) this . breakDuration . toMinutes ( ) else NULL _TEXT
SessionPropertiesRow . BREAK _TIME -> if ( this . breakDuration > 0.0 ) this . breakDuration . toMinutes ( ) else NULL _TEXT
SessionPropertiesRow . BUY _IN -> this . buyin ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . BUY _IN -> this . result ?. buyin ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . CASHED _OUT , SessionPropertiesRow . PRIZE -> this . cashout ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . CASHED _OUT , SessionPropertiesRow . PRIZE -> this . result ?. cashout ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . NET _RESULT -> this . netResult ?. 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 -> if ( this . comment . isNotEmpty ( ) ) this . comment else NULL _TEXT
SessionPropertiesRow . END _DATE -> this . endDate ?. shortDateTime ( ) ?: NULL _TEXT
SessionPropertiesRow . END _DATE -> this . endDate ?. shortDateTime ( ) ?: NULL _TEXT
SessionPropertiesRow . GAME -> getFormattedGame ( )
SessionPropertiesRow . GAME -> getFormattedGame ( )
SessionPropertiesRow . INITIAL _BUY _IN -> tournamentEntryFee ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . INITIAL _BUY _IN -> tournamentEntryFee ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . LOCATION -> location ?. name ?: NULL _TEXT
SessionPropertiesRow . LOCATION -> location ?. name ?: NULL _TEXT
SessionPropertiesRow . PLAYERS -> tournamentNumberOfPlayers ?. toString ( ) ?: NULL _TEXT
SessionPropertiesRow . PLAYERS -> tournamentNumberOfPlayers ?. toString ( ) ?: NULL _TEXT
SessionPropertiesRow . POSITION -> this . tournamentFinalPosition ?. toString ( ) ?: NULL _TEXT
SessionPropertiesRow . POSITION -> result ? .tournamentFinalPosition ?. toString ( ) ?: NULL _TEXT
SessionPropertiesRow . START _DATE -> this . startDate ?. shortDateTime ( ) ?: NULL _TEXT
SessionPropertiesRow . START _DATE -> this . startDate ?. shortDateTime ( ) ?: NULL _TEXT
SessionPropertiesRow . TABLE _SIZE -> this . tableSize ?. let { TableSize ( it ) . localizedTitle ( context ) } ?: NULL _TEXT
SessionPropertiesRow . TABLE _SIZE -> this . tableSize ?. let { TableSize ( it ) . localizedTitle ( context ) } ?: NULL _TEXT
SessionPropertiesRow . TIPS -> this . tips ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . TIPS -> result ? .tips ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . TOURNAMENT _TYPE -> {
SessionPropertiesRow . TOURNAMENT _TYPE -> {
this . tournamentType ?. let {
this . tournamentType ?. let {
TournamentType . values ( ) [ it ] . localizedTitle ( context )
TournamentType . values ( ) [ it ] . localizedTitle ( context )
@ -1136,14 +1005,10 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
}
}
}
}
SessionPropertiesRow . TOURNAMENT _NAME -> tournamentName ?. name ?: NULL _TEXT
SessionPropertiesRow . TOURNAMENT _NAME -> tournamentName ?. name ?: NULL _TEXT
SessionPropertiesRow . HANDS -> {
SessionPropertiesRow . HANDS -> this . handHistories ?. size . toString ( )
val handHistories = realm . where ( HandHistory :: class . java ) . equalTo ( " session.id " , this . id ) . findAll ( )
handHistories . size . toString ( )
}
SessionPropertiesRow . HANDS _COUNT -> this . handsCountFormatted ( context )
SessionPropertiesRow . HANDS _COUNT -> this . handsCountFormatted ( context )
SessionPropertiesRow . NUMBER _OF _TABLES -> this . numberOfTables . toString ( )
SessionPropertiesRow . NUMBER _OF _TABLES -> this . numberOfTables . toString ( )
is CustomField -> {
is CustomField -> {
// Timber.d("entries count = ${customFieldEntries.size}")
customFieldEntries . find { it . customField ?. id == row . id } ?. let { customFieldEntry ->
customFieldEntries . find { it . customField ?. id == row . id } ?. let { customFieldEntry ->
return customFieldEntry . getFormattedValue ( currency )
return customFieldEntry . getFormattedValue ( currency )
}
}
@ -1159,12 +1024,12 @@ open class Session : RealmObject(), Savable, RowRepresentable, Timed,
}
}
fun clearBuyinCashedOut ( ) {
fun clearBuyinCashedOut ( ) {
this . buyin = null
this . result ?. buyin = null
this . cashout = null
this . result ?. cashout = null
}
}
fun clearNetResult ( ) {
fun clearNetResult ( ) {
this . netResult = null
this . result ?. netResult = null
}
}
private fun cleanupBlinds ( blinds : String ? ) : String ? {
private fun cleanupBlinds ( blinds : String ? ) : String ? {