Merge branch 'master' of gitlab.com:stax-river/poker-analytics

feature/top10
Razmig Sarkissian 7 years ago
commit 179ca0321e
  1. 2
      app/src/androidTest/java/net/pokeranalytics/android/filter/SessionFilterInstrumentedUnitTest.kt
  2. 4
      app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/calculus/interfaces/Computable.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/model/filter/SessionFilterable.kt
  5. 19
      app/src/main/java/net/pokeranalytics/android/model/realm/ComputableResult.kt
  6. 107
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  7. 9
      app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt
  8. 5
      app/src/main/java/net/pokeranalytics/android/ui/fragment/StatsFragment.kt
  9. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/SessionObserverFragment.kt
  10. 2
      app/src/test/java/net/pokeranalytics/android/ExampleUnitTest.kt

@ -536,7 +536,7 @@ class SessionFilterInstrumentedUnitTest : BaseFilterInstrumentedUnitTest() {
}
@Test
fun tesNetResultFilter() {
fun testNetResultFilter() {
val realm = this.mockRealm
realm.beginTransaction()
val s1 = Session.testInstance(netResult = 200.0)

@ -143,7 +143,7 @@ class Calculator {
computables.forEach { s ->
index++;
tSum += s.ratedNet
tBBSum += s.bbNetResult
tBBSum += s.bbNet
tBBSessionCount += s.hasBigBlind
tWinningSessionCount += s.isPositive
tBuyinSum += s.ratedBuyin
@ -201,7 +201,7 @@ class Calculator {
tHourlyDuration += sessionSet.hourlyDuration
tSum += sessionSet.ratedNet
tTotalHands += sessionSet.estimatedHands
tBBSum += sessionSet.bbNetResult
tBBSum += sessionSet.bbNet
tHourlyRate = gSum / tHourlyDuration
tHourlyRateBB = gBBSum / tHourlyDuration

@ -5,7 +5,7 @@ import net.pokeranalytics.android.model.realm.SessionSet
interface Computable {
var ratedNet: Double
var bbNetResult: Double
var bbNet: Double
var hasBigBlind: Int
var isPositive: Int
var ratedBuyin: Double

@ -55,7 +55,7 @@ enum class SessionFilterable(private var fieldName:String? = null, private var s
SMALL_BLIND("cgSmallBlind"),
COMMENT("comment"),
TOURNAMENT_FEATURES("tournamentFeatures.id"),
NET_RESULT("computableResult.ratedNet"),
NET_RESULT("computableResults.ratedNet"),
BUY_IN("result.buyin"),
CASH_OUT("result.cashout"),
TIPS("result.tips"),

@ -7,7 +7,7 @@ open class ComputableResult : RealmObject(), Computable {
override var ratedNet: Double = 0.0
override var bbNetResult: Double = 0.0
override var bbNet: Double = 0.0
override var hasBigBlind: Int = 0
@ -21,14 +21,12 @@ open class ComputableResult : RealmObject(), Computable {
override var sessionSet: SessionSet? = null
// @LinkingObjects("computableResult")
// private val sessions: RealmResults<Session>? = null
// @Ignore
var session: Session? = null
fun updateWith(session: Session) {
this.sessionSet = session.sessionSet
val rate = session.bankroll?.currency?.rate ?: 1.0
session.result?.let { result ->
@ -36,18 +34,17 @@ open class ComputableResult : RealmObject(), Computable {
this.isPositive = result.isPositive
this.ratedBuyin = (result.buyin ?: 0.0) * rate
}
this.bbNetResult = session.bbNetResult
this.hasBigBlind = session.hasBigBlind
this.estimatedHands = session.estimatedHands
this.bbPer100Hands = session.bbPer100Hands
this.sessionSet = session.sessionSet
this.bbNet = session.bbNet
this.hasBigBlind = if (session.cgBigBlind != null) 1 else 0
this.estimatedHands = session.estimatedHands
this.bbPer100Hands = session.bbNet / (session.numberOfHandsPerHour * session.hourlyDuration) * 100
}
enum class Field(val identifier: String) {
RATED_NET("ratedNet"),
BB_NET("bbNetResult"),
BB_NET("bbNet"),
HAS_BIG_BLIND("hasBigBlind"),
IS_POSITIVE("isPositive"),
RATED_BUYIN("ratedBuyin"),

@ -42,18 +42,6 @@ import kotlin.collections.ArrayList
open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource, RowRepresentable, Timed,
TimeFilterable {
// @Ignore
// var rate: Double = 0.0
// get() = this.bankroll?.currency?.rate ?: 0.0
//
// @Ignore
// override var ratedNet: Double = 0.0
// get() = this.result!!.net * this.rate
//
// @Ignore
// override var isPositive: Int = 0
// get() = this.result!!.isPositive
enum class Type {
CASH_GAME,
TOURNAMENT
@ -64,9 +52,6 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
val session = Session()
session.result = Result()
val computableResult = ComputableResult()
computableResult.session = session
if (bankroll != null) {
session.bankroll = bankroll
} else {
@ -89,11 +74,6 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
// The result of the main user
var result: Result? = null
/**
* Optimized result for faster stats
*/
// var computableResult: ComputableResult? = null
@LinkingObjects("session")
private val computableResults: RealmResults<ComputableResult>? = null
@ -102,9 +82,6 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
// Timed interface
override var dayOfWeek : Int? = null
override var month: Int? = null
override var year: Int? = null
/**
* The start date of the session
@ -123,6 +100,10 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
this.computeStats()
}
override var dayOfWeek : Int? = null
override var month: Int? = null
override var year: Int? = null
/**
* the end date of the session
*/
@ -159,7 +140,7 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
this.updateRowRepresentation()
}
// The time frame sessionGroup, which can contain multiple endedSessions
// The session set containing the sessions, which can contain multiple endedSessions
var sessionSet: SessionSet? = null
// the date of creation of the app
@ -172,7 +153,6 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
this.updateRowRepresentation()
}
// The limit type: NL, PL...
var limit: Int? = null
@ -205,9 +185,8 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
// The big blind value
var cgBigBlind: Double? = null
set(value) {
this.hasBigBlind = if (value != null) 1 else 0
field = value
this.updateComputableResult()
this.computeStats()
}
// Tournament
@ -277,30 +256,41 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
val LIVE_PLAYER_HANDS_PER_HOUR = 250.0
/**
* The estimation of hands played during the session
* The net result in big blinds
*/
var estimatedHands: Double = 0.0
private set
/**
* The result in big blinds
*/
var bbNetResult: Double = 0.0
private set
val bbNet: Double
get() {
val bb = this.cgBigBlind; val result = this.result
if (bb != null && result != null) {
return result.net / bb
} else {
return 0.0
}
}
/**
* The number of big blinds won per 100 hands
* The estimation of the number of hands played
*/
var bbPer100Hands: Double = 0.0
private set
@Ignore
var estimatedHands: Double = 0.0
get() {
val noh = this.numberOfHandsPerHour
val hd = this.hourlyDuration
return noh * hd
}
/**
* Pre-compute various stats
*/
private fun computeStats() {
this.computeEstimatedHands()
this.computeBBNetResult()
this.computeBBPer100Hands()
if (this.startDate != null && this.endDate != null && this.computableResult == null) {
val computableResult = realm.createObject(ComputableResult::class.java)
computableResult.session = this
} else {
this.computableResult?.deleteFromRealm()
}
this.updateComputableResult()
}
@ -324,36 +314,12 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
return playerHandsPerHour / tableSize.toDouble()
}
private fun computeEstimatedHands() {
this.estimatedHands = this.numberOfHandsPerHour * this.hourlyDuration
}
private fun computeBBNetResult() {
val bb = this.cgBigBlind; val result = this.result
if (bb != null && result != null) {
this.bbNetResult = result.net / bb
} else {
this.bbNetResult = 0.0
}
}
private fun computeBBPer100Hands() {
this.bbPer100Hands = this.bbNetResult / this.estimatedHands * 100
}
/**
* Returns 1 if the session has big blinds, otherwise 0
*/
var hasBigBlind: Int = 0
private set
@Ignore
var ratedBuyin: Double = 0.0
get() {
this.result?.let { result ->
result.buyin?.let {
return it
}
val rate = this.bankroll?.currency?.rate ?: 1.0
this.result?.buyin?.let { buyin ->
return buyin * rate
}
return 0.0
}
@ -366,9 +332,6 @@ open class Session : RealmObject(), Manageable, StaticRowRepresentableDataSource
throw ModelException("Session should have an existing Result relationship")
}
// @Ignore
// val ratedNet: Double = this.result?.ratedNet ?: 0.0
// States
/**

@ -59,7 +59,7 @@ open class SessionSet : RealmObject(), Timed {
fun computeStats() {
this.ratedNet = this.sessions?.sumByDouble { it.computableResult?.ratedNet ?: 0.0 } ?: 0.0
this.estimatedHands = this.sessions?.sumByDouble { it.estimatedHands } ?: 0.0
this.bbNetResult = this.sessions?.sumByDouble { it.bbNetResult } ?: 0.0
this.bbNet = this.sessions?.sumByDouble { it.bbNet } ?: 0.0
}
/**
@ -68,22 +68,19 @@ open class SessionSet : RealmObject(), Timed {
@LinkingObjects("sessionSet")
val sessions: RealmResults<Session>? = null
// @Ignore
var ratedNet: Double = 0.0
@Ignore
val hourlyRate: Double = this.ratedNet / this.hourlyDuration
// @Ignore
var estimatedHands: Double = 0.0
// @Ignore
var bbNetResult: Double = 0.0
var bbNet: Double = 0.0
enum class Field(val identifier: String) {
RATED_NET("ratedNet"),
HOURLY_RATE("hourlyRate"),
BB_NET("bbNetResult"),
BB_NET("bbNet"),
ESTIMATED_HANDS("estimatedHands"),
NET_DURATION("netDuration")
}

@ -161,12 +161,9 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc
private fun createSessionGroupsAndStartCompute(realm: Realm) : List<ComputedResults> {
// val cgSessions = mutableListOf<Computable>()
// val tSessions = mutableListOf<Computable>()
val s = Date()
val allSessions = realm.where(ComputableResult::class.java).isNotNull("session.endDate").findAll()
val allSessions = realm.where(ComputableResult::class.java).findAll()
val allSessionSets = realm.where(SessionSet::class.java).findAll()
Timber.d(">>>>> number of computables to compute = ${allSessions.size}")

@ -10,7 +10,7 @@ open class SessionObserverFragment : PokerAnalyticsFragment() {
init {
val realm = Realm.getDefaultInstance()
this.endedSessions = realm.where(ComputableResult::class.java).isNotNull("session.endDate").findAll()
this.endedSessions = realm.where(ComputableResult::class.java).findAll() // ComputableResult are existing only if sessions are ended
this.endedSessions.addChangeListener { _, _ ->
this.sessionsChanged()
}

@ -25,7 +25,7 @@ class ExampleUnitTest : RealmUnitTest() {
//
// override var sessionSet: SessionSet? = SessionSet()
// override var estimatedHands: Double = 0.0
// override var bbNetResult: Double = 0.0
// override var bbNet: Double = 0.0
// override var bigBlindSessionCount: Int = 0 // 0 or 1
// override var ratedBuyin: Double = 0.0
//

Loading…
Cancel
Save