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

feature/top10
Aurelien Hubert 7 years ago
commit a3bf175813
  1. 12
      app/src/androidTest/java/net/pokeranalytics/android/StatsInstrumentedUnitTest.kt
  2. 6
      app/src/main/java/net/pokeranalytics/android/model/interfaces/Timed.kt
  3. 55
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  4. 11
      app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt
  5. 25
      app/src/main/java/net/pokeranalytics/android/model/utils/SessionSetManager.kt
  6. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt

@ -51,6 +51,8 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() {
s1.cgBigBlind = 0.5 // bb net result = -200bb s1.cgBigBlind = 0.5 // bb net result = -200bb
s2.cgBigBlind = 2.0 // bb net result = 150bb s2.cgBigBlind = 2.0 // bb net result = 150bb
s2.tableSize = 5
realm.insert(s1) realm.insert(s1)
realm.insert(s2) realm.insert(s2)
realm.commitTransaction() realm.commitTransaction()
@ -58,9 +60,9 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() {
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm") val sdf = SimpleDateFormat("dd/M/yyyy hh:mm")
val sd1 = sdf.parse("01/1/2019 10:00") val sd1 = sdf.parse("01/1/2019 10:00")
val ed1 = sdf.parse("01/1/2019 11:00") val ed1 = sdf.parse("01/1/2019 11:00") // 1 hour
val sd2 = sdf.parse("02/1/2019 08:00") val sd2 = sdf.parse("02/1/2019 08:00")
val ed2 = sdf.parse("02/1/2019 11:00") val ed2 = sdf.parse("02/1/2019 11:00") // 3 hours
realm.beginTransaction() realm.beginTransaction()
@ -112,7 +114,7 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() {
} }
val handsPlayed = results.computedStat(Stat.HANDS_PLAYED) val handsPlayed = results.computedStat(Stat.HANDS_PLAYED)
if (handsPlayed != null) { if (handsPlayed != null) {
assertEquals(100.0, handsPlayed.value, delta) assertEquals(177.77, handsPlayed.value, delta)
} else { } else {
Assert.fail("No hands played stat") Assert.fail("No hands played stat")
} }
@ -161,7 +163,7 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() {
} }
val netbbPer100Hands = results.computedStat(Stat.NET_BB_PER_100_HANDS) val netbbPer100Hands = results.computedStat(Stat.NET_BB_PER_100_HANDS)
if (netbbPer100Hands != null) { if (netbbPer100Hands != null) {
assertEquals(-50.0, netbbPer100Hands.value, delta) assertEquals(-28.12, netbbPer100Hands.value, delta)
} else { } else {
Assert.fail("No netbbPer100Hands stat") Assert.fail("No netbbPer100Hands stat")
} }
@ -182,7 +184,7 @@ class StatsInstrumentedUnitTest : RealmInstrumentedUnitTest() {
val std100 = results.computedStat(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS) val std100 = results.computedStat(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS)
if (std100 != null) { if (std100 != null) {
assertEquals(559.01, std100.value, delta) assertEquals(497.54, std100.value, delta)
} else { } else {
Assert.fail("No std100 stat") Assert.fail("No std100 stat")
} }

@ -10,8 +10,11 @@ interface Timed {
var breakDuration: Long var breakDuration: Long
var pauseDate: Date?
var netDuration: Long var netDuration: Long
/** /**
* Computes the net netDuration of the session * Computes the net netDuration of the session
*/ */
@ -23,8 +26,7 @@ interface Timed {
} }
} }
var hourlyDuration: Double val hourlyDuration: Double
get() = this.netDuration / 3600000.0 get() = this.netDuration / 3600000.0
set(value) = TODO()
} }

@ -106,7 +106,7 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
/** /**
* The start date of the break * The start date of the break
*/ */
var pauseDate: Date? = null override var pauseDate: Date? = null
// The time frame of the Session, i.e. the start & end date // The time frame of the Session, i.e. the start & end date
// var timeFrame: TimeFrame? = null // var timeFrame: TimeFrame? = null
@ -221,8 +221,40 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
return this.result?.net ?: 0.0 return this.result?.net ?: 0.0
} }
/*
public var numberOfHandsPerHour: Double {
var playersHandsPerHour: Int = Session.livePlayersHandsPerHour // default is live
if let bankroll = self.bankroll {
playersHandsPerHour = bankroll.isLive() ? Session.livePlayersHandsPerHour : Session.onlinePlayersHandsPerHour
}
var numberOfPlayers: Int = 9 // default is 9 players
if let playersAtTable = self.tableSize?.intValue {
numberOfPlayers = playersAtTable
}
return Double(playersHandsPerHour) / Double(numberOfPlayers)
}
*/
@Ignore
val ONLINE_PLAYER_HANDS_PER_HOUR = 400.0
@Ignore @Ignore
override var estimatedHands: Double = 25.0 * this.hourlyDuration val LIVE_PLAYER_HANDS_PER_HOUR = 250.0
/**
* Approximates the number of hands played per hour at the table
*/
val numberOfHandsPerHour: Double
get() {
val tableSize = this.tableSize ?: 9
val isLive = this.bankroll?.live ?: true
val playerHandsPerHour = if (isLive) LIVE_PLAYER_HANDS_PER_HOUR else ONLINE_PLAYER_HANDS_PER_HOUR
return playerHandsPerHour / tableSize.toDouble()
}
@Ignore
override var estimatedHands: Double = this.numberOfHandsPerHour * this.hourlyDuration
@Ignore @Ignore
override var bbNetResult: Double = 0.0 override var bbNetResult: Double = 0.0
@ -288,14 +320,14 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
if (this.tournamentEntryFee != null) { if (this.tournamentEntryFee != null) {
this.result?.buyin = this.tournamentEntryFee this.result?.buyin = this.tournamentEntryFee
} }
// val sessionTimeFrame = this.timeFrame ?: realm.createObject(TimeFrame::class.java)
// sessionTimeFrame.setStart(Date())
// sessionTimeFrame.setDate(Date(), null)
// this.timeFrame = sessionTimeFrame
} }
SessionState.PAUSED -> { SessionState.PAUSED -> {
// this.timeFrame?.paused = false val pauseDate = this.pauseDate
if (pauseDate != null) {
this.breakDuration += Date().time - pauseDate.time
} else {
throw IllegalStateException("When resuming, the pause date must be set")
}
this.pauseDate = null this.pauseDate = null
} }
else -> { else -> {
@ -312,10 +344,9 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
realm.executeTransaction { realm.executeTransaction {
when (getState()) { when (getState()) {
SessionState.STARTED -> { SessionState.STARTED -> {
// this.?.paused = true
this.pauseDate = Date() this.pauseDate = Date()
} }
else -> throw IllegalStateException("unmanaged state") else -> throw IllegalStateException("Pausing a session in an unmanaged state")
} }
} }
} }
@ -328,10 +359,6 @@ open class Session : RealmObject(), SessionInterface, Manageable, StaticRowRepre
when (getState()) { when (getState()) {
SessionState.STARTED, SessionState.PAUSED -> { SessionState.STARTED, SessionState.PAUSED -> {
this.end() this.end()
// this.timeFrame?.paused = false
// this.pauseDate = null
// this.endDate = Date()
// this.timeFrame?.setDate(null, Date())
} }
else -> throw Exception("Stopping session in unmanaged state") else -> throw Exception("Stopping session in unmanaged state")
} }

@ -37,13 +37,20 @@ open class SessionSet : RealmObject(), Timed {
this.computeNetDuration() this.computeNetDuration()
} }
/**
* The start date of the break
*/
override var pauseDate: Date? = null
/**
* the net duration of the set
*/
override var netDuration: Long = 0L override var netDuration: Long = 0L
companion object { companion object {
fun newInstance(realm: Realm) : SessionSet { fun newInstance(realm: Realm) : SessionSet {
val sessionSet: SessionSet = realm.createObject(SessionSet::class.java) val sessionSet: SessionSet = realm.createObject(SessionSet::class.java)
// sessionSet.timeFrame = realm.createObject(TimeFrame::class.java)
return realm.copyToRealm(sessionSet) return realm.copyToRealm(sessionSet)
} }
@ -67,7 +74,7 @@ open class SessionSet : RealmObject(), Timed {
val hourlyRate: Double = this.ratedNet / this.hourlyDuration val hourlyRate: Double = this.ratedNet / this.hourlyDuration
@Ignore @Ignore
val estimatedHands: Double = 25.0 * this.hourlyDuration val estimatedHands: Double = this.sessions?.sumByDouble { it.estimatedHands } ?: 0.0
@Ignore @Ignore
var bbNetResult: Double = this.sessions?.sumByDouble { it.bbNetResult } ?: 0.0 var bbNetResult: Double = this.sessions?.sumByDouble { it.bbNetResult } ?: 0.0

@ -4,11 +4,19 @@ import io.realm.RealmQuery
import io.realm.RealmResults import io.realm.RealmResults
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.SessionSet import net.pokeranalytics.android.model.realm.SessionSet
import kotlin.math.max
/**
* The manager is in charge of updating the abstract concept of timeline,
* representing the sequenced time frames where the user plays.
*/
class SessionSetManager { class SessionSetManager {
companion object { companion object {
/**
* Updates the global timeline using the updated [session]
*/
fun updateTimeline(session: Session) { fun updateTimeline(session: Session) {
if (!session.realm.isInTransaction) { if (!session.realm.isInTransaction) {
@ -42,7 +50,7 @@ class SessionSetManager {
} }
/** /**
* Update Time frames from sets * Update the global timeline using the impacted [sessionSets] and the updated [session]
*/ */
private fun updateTimeFrames(sessionSets: RealmResults<SessionSet>, session: Session) { private fun updateTimeFrames(sessionSets: RealmResults<SessionSet>, session: Session) {
@ -53,6 +61,9 @@ class SessionSetManager {
} }
/**
* Creates or update the session set for the [session]
*/
private fun createOrUpdateSessionSet(session: Session) { private fun createOrUpdateSessionSet(session: Session) {
val set = session.sessionSet val set = session.sessionSet
@ -65,10 +76,14 @@ class SessionSetManager {
} }
/**
* Create a set and affect it to the [session]
*/
private fun createSessionSet(session: Session) { private fun createSessionSet(session: Session) {
val set: SessionSet = SessionSet.newInstance(session.realm) val set: SessionSet = SessionSet.newInstance(session.realm)
set.startDate = session.startDate!! set.startDate = session.startDate!!
set.endDate = session.endDate!! set.endDate = session.endDate!!
set.breakDuration = session.breakDuration
session.sessionSet = set session.sessionSet = set
} }
@ -109,11 +124,17 @@ class SessionSetManager {
session.sessionSet = set session.sessionSet = set
// Add all orphan endedSessions // Add all orphan endedSessions
sessions.forEach { it.sessionSet = set } sessions.forEach { session ->
session.sessionSet = set
set.breakDuration = max(set.breakDuration, session.breakDuration)
}
// Timber.d("netDuration 3 = : ${set.timeFrame?.netDuration}") // Timber.d("netDuration 3 = : ${set.timeFrame?.netDuration}")
} }
/**
* Removes the [session] from the timeline
*/
fun removeFromTimeline(session: Session) { fun removeFromTimeline(session: Session) {
if (!session.realm.isInTransaction) { if (!session.realm.isInTransaction) {

@ -113,6 +113,7 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott
when (row) { when (row) {
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT, SessionRow.BUY_IN, SessionRow.TIPS, SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT, SessionRow.BUY_IN, SessionRow.TIPS,
SessionRow.START_DATE, SessionRow.END_DATE, SessionRow.BANKROLL -> updateSessionUI() SessionRow.START_DATE, SessionRow.END_DATE, SessionRow.BANKROLL -> updateSessionUI()
SessionRow.BREAK_TIME -> this.sessionAdapter.notifyDataSetChanged()
} }
} }
@ -183,8 +184,6 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott
floatingActionButton.animate().scaleX(0f).scaleY(0f).alpha(0f) floatingActionButton.animate().scaleX(0f).scaleY(0f).alpha(0f)
.setInterpolator(FastOutSlowInInterpolator()).start() .setInterpolator(FastOutSlowInInterpolator()).start()
} }
else -> {
}
} }
updateMenuUI() updateMenuUI()

Loading…
Cancel
Save