Net result computation + test

dev_raz_wip
Laurent 7 years ago
parent 27203dcf40
commit a8ddc0c67d
  1. 2
      app/src/main/java/net/pokeranalytics/android/calculus/Computable.kt
  2. 12
      app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt
  3. 27
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  4. 30
      app/src/test/java/net/pokeranalytics/android/ExampleUnitTest.kt

@ -13,7 +13,7 @@ interface Summable {
* An interface describing some class that can be computed
*/
interface SessionInterface : Summable {
var serie: SessionSet
var sessionSet: SessionSet?
var estimatedHands: Double
var bbNetResult: Double
var bigBlindSessionCount: Int // 0 or 1

@ -37,6 +37,7 @@ open class Result : RealmObject() {
// The net (readonly)
var net: Double = 0.0
private set
// The transactions associated with the Result, impacting the result
var transactions: RealmList<Transaction> = RealmList()
@ -50,7 +51,16 @@ open class Result : RealmObject() {
// Computes the Net
fun computeNet() {
// this.net = ...
val transactionsSum = transactions.sumByDouble { it.amount }
this.netResult?.let {
this.net = it + transactionsSum
} ?: run {
val buyin = this.buyin ?: 0.0
val cashOut = this.cashout ?: 0.0
this.net = cashOut - buyin + transactionsSum
}
}
// @todo tips?

@ -3,6 +3,7 @@ package net.pokeranalytics.android.model.realm
import io.realm.*
import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.calculus.SessionInterface
import net.pokeranalytics.android.ui.adapter.components.DisplayableDataSource
import net.pokeranalytics.android.ui.adapter.components.DynamicRowDelegate
import net.pokeranalytics.android.ui.adapter.components.DynamicRowInterface
@ -12,7 +13,7 @@ import java.util.*
import kotlin.collections.ArrayList
open class Session(comment: String = "") : RealmObject(), DynamicRowDelegate, DisplayableDataSource {
open class Session : RealmObject(), SessionInterface, DynamicRowDelegate, DisplayableDataSource {
@PrimaryKey
var id = UUID.randomUUID().toString()
@ -24,7 +25,7 @@ open class Session(comment: String = "") : RealmObject(), DynamicRowDelegate, Di
var timeFrame: TimeFrame? = null
// The time frame sessionGroup, which can contain multiple sessions
var sessionSet: SessionSet? = null
override var sessionSet: SessionSet? = null
// the date of creation of the app
var creationDate: Date = Date()
@ -83,20 +84,32 @@ open class Session(comment: String = "") : RealmObject(), DynamicRowDelegate, Di
companion object {
fun newInstance() : Session {
fun newInstance(): Session {
var session: Session = Session()
session.result = Result()
session.timeFrame = TimeFrame()
return session
}
fun testInstance(netResult: Double): Session {
var session: Session = Session.newInstance()
session.result?.netResult = netResult
return session
}
}
@Ignore // SessionInterface value
override var value: Double = 0.0
get() {
return this.result?.net ?: 0.0
}
@Ignore
var estimatedHands: Double = 0.0
override var estimatedHands: Double = 0.0
@Ignore
var bbNetResult: Double = 0.0
override var bbNetResult: Double = 0.0
get() {
this.cgBigBlind?.let { bb ->
this.result?.let { result ->
@ -107,10 +120,10 @@ open class Session(comment: String = "") : RealmObject(), DynamicRowDelegate, Di
}
@Ignore
var bigBlindSessionCount: Int = if (this.cgBigBlind != null) 1 else 0
override var bigBlindSessionCount: Int = if (this.cgBigBlind != null) 1 else 0
@Ignore
var buyin: Double = 0.0
override var buyin: Double = 0.0
get() {
this.result?.let {
it.buyin?.let {

@ -1,6 +1,7 @@
package net.pokeranalytics.android
import net.pokeranalytics.android.calculus.*
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.SessionSet
import org.junit.Assert.fail
import org.junit.Test
@ -14,10 +15,10 @@ import org.junit.Test
class ExampleUnitTest {
class Grade(someValue: Double) : SessionInterface {
// override var serie: Serie = Serie(TimeFrame())
override var value: Double = someValue
override var serie: SessionSet = SessionSet()
override var sessionSet: SessionSet? = SessionSet()
override var estimatedHands: Double = 0.0
override var bbNetResult: Double = 0.0
override var bigBlindSessionCount: Int = 0 // 0 or 1
@ -49,4 +50,29 @@ class ExampleUnitTest {
}
@Test
fun testSessionStats() {
val sessions: List<Session> = listOf(Session.testInstance(-10.0), Session.testInstance(20.0))
val group = SessionGroup(name = "test", sessions = sessions)
val results: ComputedResults = Calculator.compute(group, Calculator.Options())
val sum = results.computedStat(Stat.NETRESULT)
if (sum != null) {
assert(sum.value == 10.0) { "sum is ${sum.value}" }
} else {
fail("No Net result stat")
}
val average = results.computedStat(Stat.AVERAGE)
if (average != null) {
assert(average.value == 5.0) { "average is ${average.value}" }
} else {
fail("No AVERAGE stat")
}
}
}

Loading…
Cancel
Save