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

feature/top10
Aurelien Hubert 7 years ago
commit ad28a8a0d9
  1. 6
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/calculus/Computable.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/Bankroll.kt
  4. 100
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  5. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt
  6. 28
      app/src/main/java/net/pokeranalytics/android/model/realm/TimeFrame.kt
  7. 4
      app/src/main/java/net/pokeranalytics/android/model/utils/SessionSetManager.kt
  8. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/HistoryFragment.kt
  9. 2
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  10. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/StatsFragment.kt
  11. 6
      app/src/main/java/net/pokeranalytics/android/ui/fragment/components/SessionObserverFragment.kt
  12. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/rowrepresentable/SessionRow.kt
  13. 1
      app/src/main/res/layout/row_session_view.xml

@ -46,7 +46,7 @@ class PokerAnalyticsApplication : Application() {
val realm: Realm = Realm.getDefaultInstance() val realm: Realm = Realm.getDefaultInstance()
// Add observer on session time frame changes // Add observer on session time frame changes
this.sessions = realm.where(Session::class.java).findAll() // monitor session deletions this.sessions = realm.where(Session::class.java).findAll() // monitor session deletions
// this.sessions?.addChangeListener { _, changeSet -> // this.endedSessions?.addChangeListener { _, changeSet ->
/* /*
val deletedSessions = val deletedSessions =
realm.where(Session::class.java).`in`("id", changeSet.deletions.toTypedArray()).findAll() realm.where(Session::class.java).`in`("id", changeSet.deletions.toTypedArray()).findAll()
@ -63,7 +63,7 @@ class PokerAnalyticsApplication : Application() {
this.createDefaultData() this.createDefaultData()
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
// this.createFakeSessions() // debug this.createFakeSessions() // debug
} }
} }
@ -133,7 +133,7 @@ class PokerAnalyticsApplication : Application() {
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
// Test sessions // Test endedSessions
val sessions = realm.where<Session>().findAll() val sessions = realm.where<Session>().findAll()
if (sessions.size < 10) { if (sessions.size < 10) {
for (index in 0..50) { for (index in 0..50) {

@ -33,7 +33,7 @@ class SessionGroup(name: String, sessions: List<SessionInterface>, stats: List<S
var name: String = name var name: String = name
/** /**
* The list of sessions to compute * The list of endedSessions to compute
*/ */
var sessions: List<SessionInterface> = sessions var sessions: List<SessionInterface> = sessions

@ -37,8 +37,6 @@ open class Bankroll(name: String = "") : RealmObject(), Savable,
// The currency of the bankroll // The currency of the bankroll
var currency: Currency? = null var currency: Currency? = null
// @todo rate management
override fun getDisplayName(): String { override fun getDisplayName(): String {
return this.name return this.name
} }

@ -65,16 +65,23 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
// Timed interface // Timed interface
/**
* The start date of the session
*/
override var startDate: Date = Date() override var startDate: Date = Date()
set(value) { set(value) {
field = value field = value
this.computeNetDuration() this.computeNetDuration()
// nullifies endate when setting the start date after the end date
if (this.endDate != null && this.startDate.after(this.endDate)) { if (this.endDate != null && this.startDate.after(this.endDate)) {
this.endDate = null this.endDate = null
} }
this.dateChanged() this.dateChanged()
} }
/**
* the end date of the session
*/
var endDate: Date? = null var endDate: Date? = null
set(value) { set(value) {
field = value field = value
@ -82,26 +89,23 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
this.dateChanged() this.dateChanged()
} }
private fun dateChanged() { /**
if (this.endDate != null) { * The break duration of the session
SessionSetManager.updateTimeline(this) */
} else if (this.sessionSet != null) {
SessionSetManager.removeFromTimeline(this)
}
}
override fun endDate(): Date {
return this.endDate ?: Date()
}
override var breakDuration: Long = 0L override var breakDuration: Long = 0L
set(value) { set(value) {
field = value field = value
this.computeNetDuration() this.computeNetDuration()
} }
/**
* the net duration of the session, automatically calculated
*/
override var netDuration: Long = 0L override var netDuration: Long = 0L
/**
* The start date of the break
*/
var pauseDate: Date? = null 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
@ -111,7 +115,7 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
// value?.let { it.notifySessionDateChange(this) } // value?.let { it.notifySessionDateChange(this) }
// } // }
// The time frame sessionGroup, which can contain multiple sessions // The time frame sessionGroup, which can contain multiple endedSessions
override var sessionSet: SessionSet? = null override var sessionSet: SessionSet? = null
// the date of creation of the app // the date of creation of the app
@ -169,6 +173,25 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
// The features of the tournament, like Knockout, Shootout, Turbo... // The features of the tournament, like Knockout, Shootout, Turbo...
var tournamentFeatures: RealmList<TournamentFeature> = RealmList() var tournamentFeatures: RealmList<TournamentFeature> = RealmList()
/**
* Manages impacts on SessionSets
* Should be called when the start / end date are changed
*/
private fun dateChanged() {
if (this.endDate != null) {
SessionSetManager.updateTimeline(this)
} else if (this.sessionSet != null) {
SessionSetManager.removeFromTimeline(this)
}
}
/**
* Returns a non-null date for the session
*/
override fun endDate(): Date {
return this.endDate ?: Date()
}
/** /**
* Return if this session is a tournament * Return if this session is a tournament
*/ */
@ -183,7 +206,6 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
return this.type == Type.CASH_GAME.ordinal return this.type == Type.CASH_GAME.ordinal
} }
// Stats // Stats
@Ignore // SessionInterface value @Ignore // SessionInterface value
@ -256,6 +278,9 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
when (getState()) { when (getState()) {
SessionState.PENDING, SessionState.PLANNED -> { SessionState.PENDING, SessionState.PLANNED -> {
this.startDate = Date() this.startDate = Date()
if (this.tournamentEntryFee != null) {
this.result?.buyin = this.tournamentEntryFee
}
// val sessionTimeFrame = this.timeFrame ?: realm.createObject(TimeFrame::class.java) // val sessionTimeFrame = this.timeFrame ?: realm.createObject(TimeFrame::class.java)
// sessionTimeFrame.setStart(Date()) // sessionTimeFrame.setStart(Date())
@ -318,6 +343,9 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
} }
} }
/**
* Utility method to cleanly end a session
*/
private fun end() { private fun end() {
this.pauseDate = null this.pauseDate = null
if (this.endDate == null) { if (this.endDate == null) {
@ -378,21 +406,13 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
this.sessionSet?.let { set -> this.sessionSet?.let { set ->
// get all sessions part of the deleted session set
val sessionsFromSet = set.sessions
// cleanup unnecessary related objects // cleanup unnecessary related objects
set.deleteFromRealm() set.deleteFromRealm()
// this.timeFrame?.deleteFromRealm()
this.result?.deleteFromRealm() this.result?.deleteFromRealm()
// make sessions recreate/find their session set // Updates the timeline
sessionsFromSet?.let { sessions -> SessionSetManager.removeFromTimeline(this)
sessions.forEach { session ->
// @todo
// session.timeFrame?.notifySessionDateChange(session)
}
}
} }
} }
@ -480,10 +500,10 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
return when (row) { return when (row) {
SessionRow.BANKROLL -> bankroll?.name ?: NULL_TEXT SessionRow.BANKROLL -> bankroll?.name ?: NULL_TEXT
SessionRow.BLINDS -> getBlinds() SessionRow.BLINDS -> getBlinds()
SessionRow.BREAK_TIME -> this.breakDuration.toMinutes() SessionRow.BREAK_TIME -> if (this.breakDuration > 0.0) this.breakDuration.toMinutes() else NULL_TEXT
SessionRow.BUY_IN -> buyin.toCurrency() SessionRow.BUY_IN -> this.result?.buyin?.toCurrency() ?: NULL_TEXT
SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> result?.cashout?.toCurrency() ?: NULL_TEXT SessionRow.CASHED_OUT, SessionRow.PRIZE, SessionRow.NET_RESULT -> this.result?.cashout?.toCurrency() ?: NULL_TEXT
SessionRow.COMMENT -> if (comment.isNotEmpty()) comment else NULL_TEXT SessionRow.COMMENT -> if (this.comment.isNotEmpty()) this.comment else NULL_TEXT
SessionRow.END_DATE -> this.endDate?.shortDateTime() ?: NULL_TEXT SessionRow.END_DATE -> this.endDate?.shortDateTime() ?: NULL_TEXT
SessionRow.GAME -> getGameTitle() SessionRow.GAME -> getGameTitle()
SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: NULL_TEXT SessionRow.INITIAL_BUY_IN -> tournamentEntryFee?.toCurrency() ?: NULL_TEXT
@ -657,10 +677,7 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
cgBigBlind = null cgBigBlind = null
} }
SessionRow.BREAK_TIME -> { SessionRow.BREAK_TIME -> {
// val timeFrameToUpdate =
// if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
this.breakDuration = if (value != null) (value as String).toLong() * 60 * 1000 else 0 this.breakDuration = if (value != null) (value as String).toLong() * 60 * 1000 else 0
// timeFrame = timeFrameToUpdate
} }
SessionRow.BUY_IN -> { SessionRow.BUY_IN -> {
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)
@ -675,11 +692,6 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
} else { } else {
localResult.cashout = (value as String).toDouble() localResult.cashout = (value as String).toDouble()
this.end() this.end()
// val timeFrameToUpdate =
// if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
// timeFrameToUpdate.setEnd(Date())
// timeFrame = timeFrameToUpdate
} }
result = localResult result = localResult
@ -689,11 +701,6 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
SessionRow.END_DATE -> if (value is Date?) { SessionRow.END_DATE -> if (value is Date?) {
this.endDate = value this.endDate = value
// val timeFrameToUpdate =
// if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
//// timeFrameToUpdate.setDate(null, value)
// timeFrameToUpdate.setEnd(value)
// timeFrame = timeFrameToUpdate
} }
SessionRow.GAME -> { SessionRow.GAME -> {
if (value is ArrayList<*>) { if (value is ArrayList<*>) {
@ -722,15 +729,6 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
} }
SessionRow.START_DATE -> if (value is Date) { SessionRow.START_DATE -> if (value is Date) {
this.startDate = value this.startDate = value
// if (value == null) {
// timeFrame = null
// } else {
// val timeFrameToUpdate =
// if (timeFrame != null) timeFrame as TimeFrame else realm.createObject(TimeFrame::class.java)
// timeFrameToUpdate.setStart(value)
//// timeFrameToUpdate.setDate(value, null)
// timeFrame = timeFrameToUpdate
// }
} }
SessionRow.TABLE_SIZE -> tableSize = value as Int? SessionRow.TABLE_SIZE -> tableSize = value as Int?
SessionRow.TIPS -> { SessionRow.TIPS -> {

@ -51,7 +51,7 @@ open class SessionSet : RealmObject(), Timed {
// var timeFrame: TimeFrame? = null // var timeFrame: TimeFrame? = null
/** /**
* The list of sessions associated with this set * The list of endedSessions associated with this set
*/ */
@LinkingObjects("sessionSet") @LinkingObjects("sessionSet")
val sessions: RealmResults<Session>? = null val sessions: RealmResults<Session>? = null

@ -55,11 +55,11 @@
// //
// // Session // // Session
// @LinkingObjects("timeFrame") // @LinkingObjects("timeFrame")
// private val sessions: RealmResults<Session>? = null // we should have only one session // private val endedSessions: RealmResults<Session>? = null // we should have only one session
// //
// @Ignore // @Ignore
// var session: Session? = null // var session: Session? = null
// get() = if (this.sessions != null && this.sessions.isEmpty()) null else this.sessions?.first() // get() = if (this.endedSessions != null && this.endedSessions.isEmpty()) null else this.endedSessions?.first()
// //
// // Group // // Group
// @LinkingObjects("timeFrame") // @LinkingObjects("timeFrame")
@ -195,21 +195,21 @@
// var timeFrame: TimeFrame = sessionSet.timeFrame!! // tested in the query // var timeFrame: TimeFrame = sessionSet.timeFrame!! // tested in the query
//// timeFrame.setDate(this.startDate, this.endDate) //// timeFrame.setDate(this.startDate, this.endDate)
// //
// val sisterSessions = sessionSet.sessions!! // shouldn't crash ever // val sisterSessions = sessionSet.endedSessions!! // shouldn't crash ever
// //
// // if we have only one session in the set and that it corresponds to the set // // if we have only one session in the set and that it corresponds to the set
// if (sessionSet.sessions?.size == 1 && sessionSet.sessions?.first() == owner) { // if (sessionSet.endedSessions?.size == 1 && sessionSet.endedSessions?.first() == owner) {
// timeFrame.setDate(this.startDate, this.endDate) // timeFrame.setDate(this.startDate, this.endDate)
// } else { // there are 2+ sessions to manage and possible splits // } else { // there are 2+ endedSessions to manage and possible splits
// //
// val endDate = this.endDate // val endDate = this.endDate
// //
// // case where all sessions are over but the set is not, we might have a split, so we delete the set and save everything again // // case where all endedSessions are over but the set is not, we might have a split, so we delete the set and save everything again
// if (endDate != null && sisterSessions.all { it.timeFrame?.endDate != null } && timeFrame.endDate == null) { // if (endDate != null && sisterSessions.all { it.timeFrame?.endDate != null } && timeFrame.endDate == null) {
// var sessions = mutableListOf<Session>(owner) // var endedSessions = mutableListOf<Session>(owner)
// sessionSet.sessions?.forEach { sessions.add(it) } // sessionSet.endedSessions?.forEach { endedSessions.add(it) }
// sessionSet.deleteFromRealm() // sessionSet.deleteFromRealm()
// sessions.forEach { it.timeFrame?.notifySessionDateChange(it) } // endedSessions.forEach { it.timeFrame?.notifySessionDateChange(it) }
// } else { // } else {
// //
// if (this.startDate.before(timeFrame.startDate)) { // if (this.startDate.before(timeFrame.startDate)) {
@ -259,10 +259,10 @@
// //
// } // }
// //
// // get all sessions from sets // // get all endedSessions from sets
// var sessions = mutableSetOf<Session>() // var endedSessions = mutableSetOf<Session>()
// sessionSets.forEach { set -> // sessionSets.forEach { set ->
// set.sessions?.asIterable()?.let { sessions.addAll(it) } // set.endedSessions?.asIterable()?.let { endedSessions.addAll(it) }
// } // }
// //
// // delete all sets // // delete all sets
@ -279,8 +279,8 @@
// // Add the session linked to this timeframe to the new sessionGroup // // Add the session linked to this timeframe to the new sessionGroup
// owner.sessionSet = set // owner.sessionSet = set
// //
// // Add all orphan sessions // // Add all orphan endedSessions
// sessions.forEach { it.sessionSet = set } // endedSessions.forEach { it.sessionSet = set }
// Timber.d("netDuration 3 = : ${set.timeFrame?.netDuration}") // Timber.d("netDuration 3 = : ${set.timeFrame?.netDuration}")
// //
// } // }

@ -91,7 +91,7 @@ class SessionSetManager {
} }
} }
// get all sessions from sets // get all endedSessions from sets
val sessions = mutableSetOf<Session>() val sessions = mutableSetOf<Session>()
sessionSets.forEach { set -> sessionSets.forEach { set ->
set.sessions?.asIterable()?.let { sessions.addAll(it) } set.sessions?.asIterable()?.let { sessions.addAll(it) }
@ -108,7 +108,7 @@ class SessionSetManager {
// Add the session linked to this timeframe to the new sessionGroup // Add the session linked to this timeframe to the new sessionGroup
session.sessionSet = set session.sessionSet = set
// Add all orphan sessions // Add all orphan endedSessions
sessions.forEach { it.sessionSet = set } sessions.forEach { it.sessionSet = set }
// Timber.d("netDuration 3 = : ${set.timeFrame?.netDuration}") // Timber.d("netDuration 3 = : ${set.timeFrame?.netDuration}")

@ -67,7 +67,7 @@ class HistoryFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSource
super.onResume() super.onResume()
//rows.clear() //rows.clear()
//sessions.addAll(getRealm().copyFromRealm(realmSessions)) //endedSessions.addAll(getRealm().copyFromRealm(realmSessions))
createSessionsHeaders() createSessionsHeaders()
} }
@ -105,7 +105,7 @@ class HistoryFragment : PokerAnalyticsFragment(), LiveRowRepresentableDataSource
} }
/** /**
* Create the sessions headers * Create the endedSessions headers
*/ */
private fun createSessionsHeaders() { private fun createSessionsHeaders() {

@ -112,7 +112,7 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate, Bott
sessionAdapter.refreshRow(row) sessionAdapter.refreshRow(row)
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 -> updateSessionUI() SessionRow.START_DATE, SessionRow.END_DATE, SessionRow.BANKROLL -> updateSessionUI()
} }
} }

@ -107,7 +107,7 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc
val cgSessions = mutableListOf<Session>() val cgSessions = mutableListOf<Session>()
val tSessions = mutableListOf<Session>() val tSessions = mutableListOf<Session>()
super.sessions.forEach { session -> super.endedSessions.forEach { session ->
if (session.isCashGame()) { if (session.isCashGame()) {
cgSessions.add(session) cgSessions.add(session)
} else { } else {
@ -116,7 +116,7 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc
} }
val allStats: List<Stat> = listOf(Stat.NETRESULT, Stat.HOURLY_RATE, Stat.AVERAGE, Stat.NUMBER_OF_SETS, Stat.AVERAGE_DURATION, Stat.DURATION) val allStats: List<Stat> = listOf(Stat.NETRESULT, Stat.HOURLY_RATE, Stat.AVERAGE, Stat.NUMBER_OF_SETS, Stat.AVERAGE_DURATION, Stat.DURATION)
val allSessionGroup = SessionGroup(getString(R.string.all), super.sessions, allStats) val allSessionGroup = SessionGroup(getString(R.string.all), super.endedSessions, allStats)
val cgStats: List<Stat> = listOf(Stat.NETRESULT, Stat.HOURLY_RATE, Stat.NET_BB_PER_100_HANDS, Stat.HOURLY_RATE_BB, Stat.AVERAGE, Stat.STANDARD_DEVIATION_HOURLY, Stat.WIN_RATIO, Stat.NUMBER_OF_GAMES, Stat.AVERAGE_BUYIN) val cgStats: List<Stat> = listOf(Stat.NETRESULT, Stat.HOURLY_RATE, Stat.NET_BB_PER_100_HANDS, Stat.HOURLY_RATE_BB, Stat.AVERAGE, Stat.STANDARD_DEVIATION_HOURLY, Stat.WIN_RATIO, Stat.NUMBER_OF_GAMES, Stat.AVERAGE_BUYIN)
val cgSessionGroup = SessionGroup(getString(R.string.cash_game), cgSessions, cgStats) val cgSessionGroup = SessionGroup(getString(R.string.cash_game), cgSessions, cgStats)
val tStats: List<Stat> = listOf(Stat.NETRESULT, Stat.HOURLY_RATE, Stat.ROI, Stat.WIN_RATIO, Stat.NUMBER_OF_GAMES, Stat.AVERAGE_BUYIN) val tStats: List<Stat> = listOf(Stat.NETRESULT, Stat.HOURLY_RATE, Stat.ROI, Stat.WIN_RATIO, Stat.NUMBER_OF_GAMES, Stat.AVERAGE_BUYIN)

@ -6,12 +6,12 @@ import net.pokeranalytics.android.model.realm.Session
open class SessionObserverFragment : PokerAnalyticsFragment() { open class SessionObserverFragment : PokerAnalyticsFragment() {
val sessions: RealmResults<Session> val endedSessions: RealmResults<Session>
init { init {
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
this.sessions = realm.where(Session::class.java).isNotNull("endDate").findAll() this.endedSessions = realm.where(Session::class.java).isNotNull("endDate").findAll()
this.sessions.addChangeListener { _, _ -> this.endedSessions.addChangeListener { _, _ ->
this.sessionsChanged() this.sessionsChanged()
} }
} }

@ -73,7 +73,7 @@ enum class SessionRow : RowRepresentable {
) )
} else { } else {
arrayListOf( arrayListOf(
NET_RESULT, BUY_IN, TIPS, NET_RESULT,
SeparatorRowRepresentable(), SeparatorRowRepresentable(),
GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, START_DATE, END_DATE, BREAK_TIME, COMMENT GAME, BLINDS, LOCATION, BANKROLL, TABLE_SIZE, START_DATE, END_DATE, BREAK_TIME, COMMENT
) )

@ -86,7 +86,6 @@
android:textAllCaps="true" android:textAllCaps="true"
android:textColor="@color/kaki_lighter" android:textColor="@color/kaki_lighter"
android:textSize="12sp" android:textSize="12sp"
android:visibility="gone"
tools:text="4:21" tools:text="4:21"
tools:visibility="visible" /> tools:visibility="visible" />

Loading…
Cancel
Save