Manage rates + tests

feature/top10
Laurent 7 years ago
parent c70dcfbc8f
commit aecf621aee
  1. 82
      app/src/androidTest/java/net/pokeranalytics/android/BankrollInstrumentedUnitTest.kt
  2. 6
      app/src/main/java/net/pokeranalytics/android/calculus/Calculator.kt
  3. 1
      app/src/main/java/net/pokeranalytics/android/calculus/Computable.kt
  4. 6
      app/src/main/java/net/pokeranalytics/android/model/interfaces/Timed.kt
  5. 18
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  6. 12
      app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt
  7. 10
      app/src/main/java/net/pokeranalytics/android/model/realm/TimeFrame.kt

@ -0,0 +1,82 @@
package net.pokeranalytics.android
import androidx.test.ext.junit.runners.AndroidJUnit4
import net.pokeranalytics.android.calculus.Calculator
import net.pokeranalytics.android.calculus.ComputedResults
import net.pokeranalytics.android.calculus.SessionGroup
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.realm.Bankroll
import net.pokeranalytics.android.model.realm.Currency
import net.pokeranalytics.android.model.realm.Session
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import java.util.*
@RunWith(AndroidJUnit4::class)
class BankrollInstrumentedUnitTest : RealmInstrumentedUnitTest() {
// convenience extension
fun Session.Companion.testInstance(netResult: Double, startDate: Date, endDate: Date?): Session {
val session: Session = Session.newInstance(super.mockRealm, false)
session.result?.netResult = netResult
session.startDate = startDate
session.endDate = endDate
return session
}
@Test
fun testSessionStats() {
val realm = this.mockRealm
realm.beginTransaction()
val s1 = realm.createObject(Session::class.java, "1")
val s2 = realm.createObject(Session::class.java, "2")
val br1 = realm.createObject(Bankroll::class.java, "1")
val br2 = realm.createObject(Bankroll::class.java, "2")
val c1 = realm.createObject(Currency::class.java, "1")
val c2 = realm.createObject(Currency::class.java, "2")
c1.rate = 0.1
c2.rate = 2.0
br1.currency = c1
br2.currency = c2
s1.bankroll = br1
s2.bankroll = br2
s1.result = realm.createObject(net.pokeranalytics.android.model.realm.Result::class.java)
s2.result = realm.createObject(net.pokeranalytics.android.model.realm.Result::class.java)
s1.result?.netResult = 100.0
s2.result?.netResult = 200.0
realm.commitTransaction()
val sessions = realm.where(Session::class.java).findAll()
val group = SessionGroup(name = "test", sessions = sessions)
val options = Calculator.Options()
val results: ComputedResults = Calculator.compute(group, options)
val delta = 0.01
val sum = results.computedStat(Stat.NETRESULT)
if (sum != null) {
Assert.assertEquals(410.0, sum.value, delta)
} else {
Assert.fail("No Net result stat")
}
val average = results.computedStat(Stat.AVERAGE)
if (average != null) {
Assert.assertEquals(205.0, average.value, delta)
} else {
Assert.fail("No AVERAGE stat")
}
}
}

@ -106,7 +106,7 @@ class Calculator {
sessions.forEach { s -> sessions.forEach { s ->
index++; index++;
sum += s.value sum += s.ratedNet
bbSum += s.bbNetResult bbSum += s.bbNetResult
bbSessionCount += s.bigBlindSessionCount bbSessionCount += s.bigBlindSessionCount
if (s.value >= 0) { if (s.value >= 0) {
@ -147,7 +147,7 @@ class Calculator {
sessionSets.forEach { sessionSet -> sessionSets.forEach { sessionSet ->
gIndex++ gIndex++
duration += sessionSet.hourlyDuration duration += sessionSet.hourlyDuration
gSum += sessionSet.netResult gSum += sessionSet.ratedNet
gTotalHands += sessionSet.estimatedHands gTotalHands += sessionSet.estimatedHands
gBBSum += sessionSet.bbNetResult gBBSum += sessionSet.bbNetResult
@ -224,7 +224,7 @@ class Calculator {
var stdSum: Double = 0.0 var stdSum: Double = 0.0
var stdBBper100HandsSum: Double = 0.0 var stdBBper100HandsSum: Double = 0.0
sessions.forEach { session -> sessions.forEach { session ->
stdSum += Math.pow(session.value - average, 2.0) stdSum += Math.pow(session.ratedNet - average, 2.0)
stdBBper100HandsSum += Math.pow(session.bbPer100Hands - bbPer100Hands, 2.0) stdBBper100HandsSum += Math.pow(session.bbPer100Hands - bbPer100Hands, 2.0)
} }
val standardDeviation: Double = Math.sqrt(stdSum / sessions.size) val standardDeviation: Double = Math.sqrt(stdSum / sessions.size)

@ -19,6 +19,7 @@ interface SessionInterface : Summable {
var bigBlindSessionCount: Int // 0 or 1 var bigBlindSessionCount: Int // 0 or 1
var buyin: Double var buyin: Double
var bbPer100Hands: Double var bbPer100Hands: Double
var ratedNet: Double
} }
/** /**

@ -15,14 +15,10 @@ interface Timed {
/** /**
* Computes the net netDuration of the session * Computes the net netDuration of the session
*/ */
fun computeDuration() { fun computeNetDuration() {
this.netDuration = this.endDate().time - this.startDate.time - this.breakDuration this.netDuration = this.endDate().time - this.startDate.time - this.breakDuration
} }
// fun hourlyDuration() : Double {
// return this.netDuration / 3600000.0 // 3.6 millions of milliseconds
// }
var hourlyDuration: Double var hourlyDuration: Double
get() = this.netDuration / 3600000.0 get() = this.netDuration / 3600000.0
set(value) = TODO() set(value) = TODO()

@ -67,7 +67,7 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
override var startDate: Date = Date() override var startDate: Date = Date()
set(value) { set(value) {
field = value field = value
this.computeDuration() this.computeNetDuration()
if (this.endDate != null && this.startDate.after(this.endDate)) { if (this.endDate != null && this.startDate.after(this.endDate)) {
this.endDate = null this.endDate = null
} }
@ -77,7 +77,7 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
var endDate: Date? = null var endDate: Date? = null
set(value) { set(value) {
field = value field = value
this.computeDuration() this.computeNetDuration()
this.dateChanged() this.dateChanged()
} }
@ -96,7 +96,7 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
override var breakDuration: Long = 0L override var breakDuration: Long = 0L
set(value) { set(value) {
field = value field = value
this.computeDuration() this.computeNetDuration()
} }
override var netDuration: Long = 0L override var netDuration: Long = 0L
@ -233,6 +233,18 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen
throw ModelException("Session should have an existing Result relationship") throw ModelException("Session should have an existing Result relationship")
} }
override var ratedNet: Double = 0.0
get() {
this.result?.net?.let { net ->
this.bankroll?.currency?.rate?.let { rate ->
return net * rate
} ?: run {
return net
}
}
return 0.0
}
// States // States
/** /**

@ -14,13 +14,13 @@ open class SessionSet : RealmObject(), Timed {
override var startDate: Date = Date() override var startDate: Date = Date()
set(value) { set(value) {
field = value field = value
this.computeDuration() this.computeNetDuration()
} }
var endDate: Date = Date() var endDate: Date = Date()
set(value) { set(value) {
field = value field = value
this.computeDuration() this.computeNetDuration()
} }
override fun endDate(): Date { override fun endDate(): Date {
@ -30,7 +30,7 @@ open class SessionSet : RealmObject(), Timed {
override var breakDuration: Long = 0L override var breakDuration: Long = 0L
set(value) { set(value) {
field = value field = value
this.computeDuration() this.computeNetDuration()
} }
override var netDuration: Long = 0L override var netDuration: Long = 0L
@ -57,16 +57,16 @@ open class SessionSet : RealmObject(), Timed {
val sessions: RealmResults<Session>? = null val sessions: RealmResults<Session>? = null
@Ignore @Ignore
val netResult: Double = this.sessions?.sumByDouble { it.value } ?: 0.0 val ratedNet: Double = this.sessions?.sumByDouble { it.ratedNet } ?: 0.0
@Ignore @Ignore
val hourlyRate: Double = this.netResult / this.hourlyDuration val hourlyRate: Double = this.ratedNet / this.hourlyDuration
@Ignore @Ignore
val estimatedHands: Double = 25.0 * this.hourlyDuration val estimatedHands: Double = 25.0 * this.hourlyDuration
@Ignore @Ignore
var bbNetResult: Double = 0.0 var bbNetResult: Double = this.sessions?.sumByDouble { it.bbNetResult } ?: 0.0
} }

@ -15,14 +15,14 @@
// var startDate: Date = Date() // var startDate: Date = Date()
// private set(value) { // private set(value) {
// field = value // field = value
// this.computeDuration() // this.computeNetDuration()
// } // }
// //
// // An end date // // An end date
// var endDate: Date? = null // var endDate: Date? = null
// private set(value) { // private set(value) {
// field = value // field = value
// this.computeDuration() // this.computeNetDuration()
// } // }
// //
// // The latest pause date // // The latest pause date
@ -34,14 +34,14 @@
// } // }
// } // }
// field = value // field = value
// this.computeDuration() // this.computeNetDuration()
// } // }
// //
// // The break netDuration // // The break netDuration
// var breakDuration: Long = 0L // var breakDuration: Long = 0L
// set(value) { // set(value) {
// field = value // field = value
// this.computeDuration() // this.computeNetDuration()
// } // }
// //
// // the total netDuration // // the total netDuration
@ -95,7 +95,7 @@
// /** // /**
// * Computes the net netDuration of the session // * Computes the net netDuration of the session
// */ // */
// private fun computeDuration() { // private fun computeNetDuration() {
// var endDate: Date = this.endDate ?: Date() // var endDate: Date = this.endDate ?: Date()
// this.netDuration = endDate.time - this.startDate.time - this.breakDuration // this.netDuration = endDate.time - this.startDate.time - this.breakDuration
// } // }

Loading…
Cancel
Save