@ -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,7 +27,6 @@ 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.*
@ -45,7 +44,7 @@ import java.util.Currency
typealias BB = Double
typealias BB = Double
open class Session : RealmObject ( ) , Savable , RowUpdatable , Row Representable , Timed ,
open class Session : RealmObject ( ) , Savable , RowRepresentable , Timed ,
TimeFilterable , Filterable , DatedBankrollGraphEntry , StakesHolder {
TimeFilterable , Filterable , DatedBankrollGraphEntry , StakesHolder {
enum class Type ( val value : String ) {
enum class Type ( val value : String ) {
@ -67,24 +66,23 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
companion object {
companion object {
fun newInstance ( realm : Realm , isTournament : Boolean , bankroll : Bankroll ? = null , managed : Boolean = true ) : Session {
fun newInstance ( realm : Realm , isTournament : Boolean , bankroll : Bankroll ? = null ) : Session {
val session = Session ( )
val session = Session ( )
session . result = Result ( )
if ( bankroll != null ) {
val br : Bankroll ? = bankroll ?: realm . where < Bankroll > ( ) . findFirst ( )
session . bankroll = bankroll
br ?. let {
} else {
session . bankroll = realm . copyFromRealm ( br )
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 ( )
return if ( managed ) {
val game = realm . where ( Game :: class . java ) . equalTo ( " shortName " , " HE " ) . findFirst ( )
realm . copyToRealm ( session )
game ?. let {
} else {
session . game = realm . copyFromRealm ( game )
session
}
}
return session
}
}
fun fieldNameForQueryType ( queryCondition : Class < out QueryCondition > ) : String ? {
fun fieldNameForQueryType ( queryCondition : Class < out QueryCondition > ) : String ? {
@ -102,9 +100,9 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
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 -> " result. numberOfRebuy"
NumberOfRebuy :: class . java -> " numberOfRebuy "
TournamentNumberOfPlayer :: class . java -> " tournamentNumberOfPlayers "
TournamentNumberOfPlayer :: class . java -> " tournamentNumberOfPlayers "
TournamentFinalPosition :: class . java -> " result. tournamentFinalPosition"
TournamentFinalPosition :: class . java -> " 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 "
@ -118,7 +116,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
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.customFields .id "
CustomFieldQuery :: class . java -> " customFieldEntries.customField.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 "
@ -148,7 +146,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
val sessionType : Type
val sessionType : Type
get ( ) { return Type . values ( ) [ this . type ] }
get ( ) { return Type . values ( ) [ this . type ] }
// The result of the main user
// Not used anymore
var result : Result ? = null
var result : Result ? = null
@LinkingObjects ( " session " )
@LinkingObjects ( " session " )
@ -209,7 +207,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
this . endDate = null
this . endDate = null
}
}
this . dateChanged ( )
this . dateChanged ( )
this . computeStats ( )
this . addToComputeQueue ( )
}
}
/ * *
/ * *
@ -230,7 +228,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
this . computeNetDuration ( )
this . computeNetDuration ( )
this . dateChanged ( )
this . dateChanged ( )
this . defineDefaultTournamentBuyinIfNecessary ( )
this . defineDefaultTournamentBuyinIfNecessary ( )
this . computeStats ( )
this . addToComputeQueue ( )
}
}
/ * *
/ * *
@ -240,7 +238,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
set ( value ) {
set ( value ) {
field = value
field = value
this . computeNetDuration ( )
this . computeNetDuration ( )
this . computeStats ( )
this . addToComputeQueue ( )
}
}
/ * *
/ * *
@ -252,10 +250,6 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
* 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
@ -268,7 +262,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
set ( value ) {
set ( value ) {
field = value
field = value
this . generateStakes ( )
this . generateStakes ( )
this . computeStats ( )
this . addToComputeQueue ( )
// this.updateRowRepresentation()
// this.updateRowRepresentation()
}
}
@ -296,7 +290,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
set ( value ) {
set ( value ) {
if ( value > 0 ) {
if ( value > 0 ) {
field = value
field = value
this . computeStats ( )
this . addToComputeQueue ( )
}
}
}
}
@ -314,16 +308,13 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
// 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 . computeStats ( )
this . addToComputeQueue ( )
this . result ?. computeNumberOfRebuy ( )
this . computeNumberOfRebuy ( )
}
}
// var blinds: String? = null
// var blinds: String? = null
@ -334,8 +325,8 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
field = value
field = value
this . generateStakes ( )
this . generateStakes ( )
this . defineHighestBet ( )
this . defineHighestBet ( )
this . computeStats ( )
this . addToComputeQueue ( )
this . result ?. computeNumberOfRebuy ( )
this . computeNumberOfRebuy ( )
}
}
var cgBlinds : String ? = null
var cgBlinds : String ? = null
@ -343,8 +334,8 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
field = cleanupBlinds ( value )
field = cleanupBlinds ( value )
this . generateStakes ( )
this . generateStakes ( )
this . defineHighestBet ( )
this . defineHighestBet ( )
this . computeStats ( )
this . addToComputeQueue ( )
this . result ?. computeNumberOfRebuy ( )
this . computeNumberOfRebuy ( )
}
}
var cgBiggestBet : Double ? = null
var cgBiggestBet : Double ? = null
@ -357,7 +348,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
var tournamentEntryFee : Double ? = null
var tournamentEntryFee : Double ? = null
set ( value ) {
set ( value ) {
field = value
field = value
this . result ?. computeNumberOfRebuy ( )
this . computeNumberOfRebuy ( )
}
}
// The total number of players who participated in the tournament
// The total number of players who participated in the tournament
@ -379,9 +370,131 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
var handsCount : Int ? = null
var handsCount : Int ? = null
set ( value ) {
set ( value ) {
field = value
field = value
this . computeStats ( )
this . addToComputeQueue ( )
}
/ * *
* 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 ( )
}
}
@ -391,11 +504,15 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
* 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 ) {
SessionSetManager . updateTimeline ( this )
DataManager . sessionDateChanged ( this )
} else if ( this . sessionSet != null ) {
SessionSetManager . removeFromTimeline ( this )
// if (this.endDate != null) {
}
// SessionSetManager.updateTimeline(this)
// } else if (this.sessionSet != null) {
// SessionSetManager.removeFromTimeline(this)
// }
// this.updateRowRepresentation()
// this.updateRowRepresentation()
}
}
@ -435,9 +552,9 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
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 && result != null ) {
return if ( bb != null ) {
result . net / bb
this . net / bb
} else {
} else {
0.0
0.0
}
}
@ -468,9 +585,16 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
@Ignore
@Ignore
override var amount : Double = 0.0
override var amount : Double = 0.0
get ( ) {
get ( ) {
return this . result ?. net ?: 0.0
return this . net
}
}
/ * *
* Pre - compute various statIds
* /
private fun addToComputeQueue ( ) {
DataManager . sessionToCompute ( this )
}
/ * *
/ * *
* Pre - compute various statIds
* Pre - compute various statIds
* /
* /
@ -501,17 +625,13 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
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 config = UserConfig . getConfiguration ( this . realm )
val dealtHandsPerHour = if ( this . isLive ) UserConfigObserver . liveDealtHandsPerHour else UserConfigObserver . onlineDealtHandsPerHour
val playerHandsPerHour = if ( this . isLive ) config . liveDealtHandsPerHour else config . onlineDealtHandsPerHour
return this . numberOfTables * dealtHandsPerHour / tableSize . toDouble ( )
return this . numberOfTables * playerHandsPerHour / tableSize . toDouble ( )
}
}
val hourlyRate : Double
val hourlyRate : Double
get ( ) {
get ( ) {
this . result ?. let { result ->
return this . net / this . hourlyDuration
return result . net / this . hourlyDuration
}
throw ModelException ( " Session should have an existing Result relationship " )
}
}
private val bbHourlyRate : BB
private val bbHourlyRate : BB
@ -529,12 +649,12 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
val hasBuyin : Boolean
val hasBuyin : Boolean
get ( ) {
get ( ) {
return this . result ?. buyin != null
return this . buyin != null
}
}
val hasNetResult : Boolean
val hasNetResult : Boolean
get ( ) {
get ( ) {
return this . result ?. netResult != null
return this . netResult != null
}
}
// Manageable
// Manageable
@ -557,31 +677,29 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
* 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 ( )
this . defineDefaultTournamentBuyinIfNecessary ( )
this . defineDefaultTournamentBuyinIfNecessary ( )
}
}
SessionState . PAUSED -> {
SessionState . PAUSED -> {
val pauseDate = this . pauseDate
val pauseDate = this . pauseDate
if ( pauseDate != null ) {
if ( pauseDate != null ) {
this . breakDuration += Date ( ) . time - pauseDate . time
this . breakDuration += Date ( ) . time - pauseDate . time
} else {
} else {
throw PAIllegalStateException ( " When resuming, the pause date must be set " )
throw PAIllegalStateException ( " When resuming, the pause date must be set " )
}
this . pauseDate = null
}
else -> {
throw PAIllegalStateException ( " unmanaged session state: $state " )
}
}
this . pauseDate = null
}
else -> {
throw PAIllegalStateException ( " unmanaged session state: $state " )
}
}
}
}
}
}
private fun defineDefaultTournamentBuyinIfNecessary ( ) {
private fun defineDefaultTournamentBuyinIfNecessary ( ) {
if ( this . tournamentEntryFee != null && this . result ?. buyin == null ) {
if ( this . tournamentEntryFee != null && this . buyin == null ) {
this . result ?. buyin = this . tournamentEntryFee
this . buyin = this . tournamentEntryFee
}
}
}
}
@ -589,13 +707,11 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
* 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 ( )
}
else -> throw PAIllegalStateException ( " Pausing a session in an unmanaged state: $state " )
}
}
else -> throw PAIllegalStateException ( " Pausing a session in an unmanaged state: $state " )
}
}
}
}
@ -603,13 +719,11 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
* 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 )
}
}
@ -618,12 +732,10 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
* 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
}
}
}
/ * *
/ * *
@ -688,10 +800,11 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
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 " )
}
}
@ -704,10 +817,10 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
// Updates the timeline
// Updates the timeline
this . sessionSet ?. let {
this . sessionSet ?. let {
SessionSet Manager. removeFromTimeline ( this )
Data Manager. removeFromTimeline ( this )
}
}
// cleanup unnecessary related objects
// cleanup unnecessary related objects
this . result ?. deleteFromRealm ( )
// this.deleteFromRealm( )
this . computableResults ?. deleteAllFromRealm ( )
this . computableResults ?. deleteAllFromRealm ( )
}
}
@ -738,7 +851,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
return " Session ${this.creationDate} "
return " Session ${this.creationDate} "
}
}
override fun updateValue ( value : Any ? , row : RowRepresentable ) {
fun updateValue ( value : Any ? , row : RowRepresentable ) {
when ( row ) {
when ( row ) {
SessionPropertiesRow . BANKROLL -> bankroll = value as Bankroll ?
SessionPropertiesRow . BANKROLL -> bankroll = value as Bankroll ?
@ -757,38 +870,50 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
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( )
localResult . buyin = value as Double ?
this . buyin = value as Double ?
}
}
SessionPropertiesRow . CASHED _OUT , SessionPropertiesRow . PRIZE -> {
SessionPropertiesRow . CASHED _OUT , SessionPropertiesRow . PRIZE -> {
val localResult = getOrCreateResult ( )
// val localResult = getOrCreateResult()
localResult . cashout = value as Double ?
val cashOut = value as Double ?
this . cashout = cashOut
if ( cashOut != null ) {
this . end ( )
}
}
}
SessionPropertiesRow . NET _RESULT -> {
SessionPropertiesRow . NET _RESULT -> {
val localResult = getOrCreateResult ( )
// val localResult = getOrCreateResult()
localResult . netResult = value as Double ?
val 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 -> {
if ( value is ArrayList < * > ) {
when ( value ) {
limit = try {
is ArrayList < * > -> {
( value [ 0 ] as Int ? )
limit = try {
} catch ( e : Exception ) {
( value [ 0 ] as Int ? )
null
} catch ( e : Exception ) {
null
}
game = try {
( value [ 1 ] as Game ? )
} catch ( e : Exception ) {
null
}
}
}
game = try {
is Game -> {
( value [ 1 ] as Game ? )
game = value
} catch ( e : Exception ) {
}
null
null -> {
limit = null
game = null
}
}
} else if ( value is Game ) {
game = value
} else if ( value == null ) {
limit = null
game = null
}
}
}
}
SessionPropertiesRow . INITIAL _BUY _IN -> {
SessionPropertiesRow . INITIAL _BUY _IN -> {
@ -803,21 +928,21 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
}
}
}
}
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 ) {
localResult . tournamentFinalPosition = value . toInt ( )
this . tournamentFinalPosition = value . toInt ( )
} else {
} else {
localResult . tournamentFinalPosition = null
this . 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( )
localResult . tips = value as Double ?
this . 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
@ -842,6 +967,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
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 )
}
}
@ -857,14 +983,25 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
}
}
private fun getOrCreateResult ( ) : Result {
// private fun customFieldEntries(realm: Realm, customField: CustomField): List<CustomFieldEntry> {
return this . result
//
?: run {
//// val cfEntries = customField.entries
val result = realm . createObject ( Result :: class . java )
//// val sessionEntries = this.customFieldEntries
this . result = result
////
result
//// val entries = realm.where<CustomFieldEntry>()
}
//// .`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
@ -879,40 +1016,34 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
override fun formattedValue ( stat : Stat ) : TextFormat {
override fun formattedValue ( stat : Stat ) : TextFormat {
this . result ?. let { result ->
val value : Double ? = when ( stat ) {
Stat . NET _RESULT , Stat . AVERAGE , Stat . STANDARD _DEVIATION -> this . net
val value : Double ? = when ( stat ) {
Stat . NUMBER _OF _GAMES , Stat . NUMBER _OF _SETS -> 1.0
Stat . NET _RESULT , Stat . AVERAGE , Stat . STANDARD _DEVIATION -> result . net
Stat . AVERAGE _BUYIN -> this . buyin
Stat . NUMBER _OF _GAMES , Stat . NUMBER _OF _SETS -> 1.0
Stat . ROI -> {
Stat . AVERAGE _BUYIN -> result . buyin
this . buyin ?. let {
Stat . ROI -> {
Stat . returnOnInvestment ( this . net , it )
result . buyin ?. let {
} ?: run {
Stat . returnOnInvestment ( result . net , it )
null
} ?: run {
null
}
}
}
Stat . HOURLY _RATE _BB -> this . bbHourlyRate
Stat . NET _BB _PER _100 _HANDS , Stat . STANDARD _DEVIATION _BB _PER _100 _HANDS -> Stat . netBBPer100Hands (
this . bbNet ,
this . estimatedHands
)
Stat . AVERAGE _NET _BB , Stat . BB _NET _RESULT -> this . bbNet
Stat . HOURLY _DURATION , Stat . AVERAGE _HOURLY _DURATION -> this . netDuration . toDouble ( )
Stat . HOURLY _RATE , Stat . STANDARD _DEVIATION _HOURLY -> this . hourlyRate
Stat . HANDS _PLAYED -> this . estimatedHands
Stat . WIN _RATIO -> null
else -> throw StatFormattingException ( " format undefined for stat ${stat.name} " )
}
value ?. let {
return stat . textFormat ( it , currency = currency )
} ?: run {
return TextFormat ( NULL _TEXT )
}
}
Stat . HOURLY _RATE _BB -> this . bbHourlyRate
Stat . NET _BB _PER _100 _HANDS , Stat . STANDARD _DEVIATION _BB _PER _100 _HANDS -> Stat . netBBPer100Hands (
this . bbNet ,
this . estimatedHands
)
Stat . AVERAGE _NET _BB , Stat . BB _NET _RESULT -> this . bbNet
Stat . HOURLY _DURATION , Stat . AVERAGE _HOURLY _DURATION -> this . netDuration . toDouble ( )
Stat . HOURLY _RATE , Stat . STANDARD _DEVIATION _HOURLY -> this . hourlyRate
Stat . HANDS _PLAYED -> this . estimatedHands
Stat . WIN _RATIO -> null
else -> throw StatFormattingException ( " format undefined for stat ${stat.name} " )
}
value ?. let {
return stat . textFormat ( it , currency = currency )
} ?: run {
} ?: run {
throw PAIllegalStateException ( " Asking for statIds on Session without Result " )
return TextFormat ( NULL _TEXT )
}
}
}
}
@ -965,25 +1096,25 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
@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 ) : String {
fun charSequenceForRow ( row : RowRepresentable , context : Context , realm : Realm ) : 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 . result ?. buyin ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . BUY _IN -> this . buyin ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . CASHED _OUT , SessionPropertiesRow . PRIZE -> this . result ?. cashout ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . CASHED _OUT , SessionPropertiesRow . PRIZE -> this . cashout ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . NET _RESULT -> this . result ?. netResult ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . NET _RESULT -> this . 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 -> result ? .tournamentFinalPosition ?. toString ( ) ?: NULL _TEXT
SessionPropertiesRow . POSITION -> this . 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 -> result ? .tips ?. toCurrency ( currency ) ?: NULL _TEXT
SessionPropertiesRow . TIPS -> this . 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 )
@ -1005,10 +1136,14 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
}
}
}
}
SessionPropertiesRow . TOURNAMENT _NAME -> tournamentName ?. name ?: NULL _TEXT
SessionPropertiesRow . TOURNAMENT _NAME -> tournamentName ?. name ?: NULL _TEXT
SessionPropertiesRow . HANDS -> this . handHistories ?. size . toString ( )
SessionPropertiesRow . HANDS -> {
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 )
}
}
@ -1024,12 +1159,12 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
}
}
fun clearBuyinCashedOut ( ) {
fun clearBuyinCashedOut ( ) {
this . result ?. buyin = null
this . buyin = null
this . result ?. cashout = null
this . cashout = null
}
}
fun clearNetResult ( ) {
fun clearNetResult ( ) {
this . result ?. netResult = null
this . netResult = null
}
}
private fun cleanupBlinds ( blinds : String ? ) : String ? {
private fun cleanupBlinds ( blinds : String ? ) : String ? {