Bankroll fixes and improvements

dev
Laurent 7 years ago
parent 5953e6908b
commit 0fb1276e69
  1. 2
      app/src/androidTest/java/net/pokeranalytics/android/performanceTests/PerfsInstrumentedUnitTest.kt
  2. 6
      app/src/androidTest/java/net/pokeranalytics/android/unitTests/BankrollInstrumentedUnitTest.kt
  3. 12
      app/src/androidTest/java/net/pokeranalytics/android/unitTests/StatsInstrumentedUnitTest.kt
  4. 2
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  5. 12
      app/src/main/java/net/pokeranalytics/android/calculus/bankroll/BankrollCalculator.kt
  6. 64
      app/src/main/java/net/pokeranalytics/android/calculus/bankroll/BankrollReport.kt
  7. 42
      app/src/main/java/net/pokeranalytics/android/model/migrations/PokerAnalyticsMigration.kt
  8. 12
      app/src/main/java/net/pokeranalytics/android/model/realm/Bankroll.kt

@ -58,7 +58,7 @@ class PerfsInstrumentedUnitTest : RealmInstrumentedUnitTest() {
val group = ComputableGroup(Query(), stats)
val options = Calculator.Options()
options.displayedStats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION)
options.stats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION)
val results: ComputedResults = Calculator.compute(realm, group, options)
Timber.d("*** ended in ${System.currentTimeMillis() - start} milliseconds")

@ -54,12 +54,12 @@ class BankrollInstrumentedUnitTest : SessionInstrumentedUnitTest() {
val t1 = realm.createObject(Transaction::class.java, UUID.randomUUID().toString())
t1.amount = 100.0
t1.type = TransactionType.getByValue(TransactionType.Value.BONUS, realm)
br1.transactions.add(t1)
t1.bankroll = br1
val t2 = realm.createObject(Transaction::class.java, UUID.randomUUID().toString())
t2.amount = 500.0
t2.type = TransactionType.getByValue(TransactionType.Value.BONUS, realm)
br2.transactions.add(t2)
t2.bankroll = br2
val s1 = newSessionInstance(realm)
s1.bankroll = br1
@ -108,7 +108,7 @@ class BankrollInstrumentedUnitTest : SessionInstrumentedUnitTest() {
val t1 = realm.createObject(Transaction::class.java, UUID.randomUUID().toString())
t1.amount = 100.0
t1.type = TransactionType.getByValue(TransactionType.Value.BONUS, realm)
br1?.transactions?.add(t1)
t1.bankroll = br1
val s1 = newSessionInstance(realm)
s1.bankroll = br1

@ -76,7 +76,7 @@ class StatsInstrumentedUnitTest : SessionInstrumentedUnitTest() {
val group = ComputableGroup(Query())
val options = Calculator.Options()
options.displayedStats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION,
options.stats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION,
Stat.LONGEST_STREAKS, Stat.LOCATIONS_PLAYED, Stat.DAYS_PLAYED)
val results: ComputedResults = Calculator.compute(realm, group, options)
@ -255,7 +255,7 @@ class StatsInstrumentedUnitTest : SessionInstrumentedUnitTest() {
val group = ComputableGroup(Query(), stats)
val options = Calculator.Options()
options.displayedStats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION)
options.stats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION)
val results: ComputedResults = Calculator.compute(realm, group, options)
val delta = 0.01
@ -322,7 +322,7 @@ class StatsInstrumentedUnitTest : SessionInstrumentedUnitTest() {
val group = ComputableGroup(Query(), stats)
val options = Calculator.Options()
options.displayedStats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION)
options.stats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION)
val results: ComputedResults = Calculator.compute(realm, group, options)
val delta = 0.01
@ -405,7 +405,7 @@ class StatsInstrumentedUnitTest : SessionInstrumentedUnitTest() {
val group = ComputableGroup(Query(), stats)
val options = Calculator.Options()
options.displayedStats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION)
options.stats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION)
val results: ComputedResults = Calculator.compute(realm, group, options)
val delta = 0.01
@ -728,7 +728,7 @@ class StatsInstrumentedUnitTest : SessionInstrumentedUnitTest() {
val group = ComputableGroup(Query(QueryCondition.IsCash))
val options = Calculator.Options()
options.displayedStats = listOf(Stat.HOURLY_DURATION)
options.stats = listOf(Stat.HOURLY_DURATION)
val results: ComputedResults = Calculator.compute(realm, group, options)
val delta = 0.01
@ -773,7 +773,7 @@ class StatsInstrumentedUnitTest : SessionInstrumentedUnitTest() {
val group = ComputableGroup(Query(QueryCondition.IsCash))
val options = Calculator.Options()
options.displayedStats = listOf(Stat.HOURLY_DURATION)
options.stats = listOf(Stat.HOURLY_DURATION)
val results: ComputedResults = Calculator.compute(realm, group, options)
val delta = 0.01

@ -30,7 +30,7 @@ class PokerAnalyticsApplication : Application() {
Realm.init(this)
val realmConfiguration = RealmConfiguration.Builder()
.name(Realm.DEFAULT_REALM_NAME)
.schemaVersion(4)
.schemaVersion(5)
.migration(PokerAnalyticsMigration())
.initialData(Seed(this))
.build()

@ -16,7 +16,10 @@ class BankrollCalculator {
val realm = Realm.getDefaultInstance()
val report = BankrollReport(setup)
val bankrolls: List<Bankroll> = if (setup.bankroll != null) listOf(setup.bankroll) else realm.where(Bankroll::class.java).findAll()
val bankrolls: List<Bankroll> =
if (setup.bankroll != null) listOf(setup.bankroll)
else realm.where(Bankroll::class.java).findAll()
var initialValue = 0.0
var transactionNet = 0.0
@ -25,8 +28,13 @@ class BankrollCalculator {
val rate = if (setup.virtualBankroll) bankroll.rate else 1.0
if (setup.shouldAddInitialValue) {
initialValue += bankroll.initialValue * rate
transactionNet += bankroll.transactions.sumByDouble { it.amount } * rate
}
bankroll.transactions?.let { transactions ->
transactionNet += transactions.sumByDouble { it.amount } * rate
}
}
report.transactionsNet = transactionNet

@ -12,13 +12,11 @@ import net.pokeranalytics.android.ui.graph.DataSetFactory
import java.util.*
import kotlin.collections.HashMap
class BankrollReport(setup: BankrollReportSetup) {
/**
* The setup used to compute the report
* This class holds the results from the BankrollCalculator computations
* It has all the information required for the Bankroll various displays
*/
var setup: BankrollReportSetup = setup
class BankrollReport(var setup: BankrollReportSetup) {
/**
* The value of the bankroll
@ -49,6 +47,9 @@ class BankrollReport(setup: BankrollReportSetup) {
this.computeBankrollTotal()
}
/**
* Computes the bankroll total
*/
fun computeBankrollTotal() {
this.total = this.initial + this.netResult + this.transactionsNet
}
@ -82,20 +83,39 @@ class BankrollReport(setup: BankrollReportSetup) {
*/
var riskOfRuin: Double? = null
/**
* The list of transactions held by the bankroll
*/
var transactions: List<Transaction> = mutableListOf()
private set
/**
* A map containing TransactionBuckets by transaction types
*/
var transactionBuckets: HashMap<String, TransactionBucket> = HashMap()
private set
/**
* The list of bankroll graph points
*/
var evolutionPoints: MutableList<BRGraphPoint> = mutableListOf()
/**
* The list of dated items used for the graph
*/
var evolutionItems: MutableList<DatedValue> = mutableListOf()
private set
/**
* Adds a list of dated items to the evolution items used to get the bankroll graph
*/
fun addDatedItems(items: Collection<DatedValue>) {
this.evolutionItems.addAll(items)
}
/**
* Adds a transaction to its type bucket
*/
fun addTransaction(transaction: Transaction) {
transaction.type?.let { type ->
@ -116,6 +136,9 @@ class BankrollReport(setup: BankrollReportSetup) {
}
/**
* Generates the graph points used for the virtual bankroll
*/
fun generateGraphPointsIfNecessary() {
if (!this.setup.virtualBankroll) {
@ -131,6 +154,9 @@ class BankrollReport(setup: BankrollReportSetup) {
}
/**
* Returns a data set used for the bankroll graph
*/
fun lineDataSet(context: Context): LineDataSet {
val entries = mutableListOf<Entry>()
@ -149,11 +175,18 @@ class BankrollReport(setup: BankrollReportSetup) {
*/
class BankrollReportSetup(val bankroll: Bankroll? = null, val from: Date? = null, val to: Date? = null) {
/**
* Returns whether the setup concerns the virtual bankroll,
* i.e. the bankroll summing all concrete bankrolls
*/
val virtualBankroll: Boolean
get() {
return this.bankroll == null
}
/**
* the query used to get bankroll transactions
*/
val query: Query
get() {
val query = Query()
@ -175,14 +208,35 @@ class BankrollReportSetup(val bankroll: Bankroll? = null, val from: Date? = null
return query
}
/**
* Returns whether or not the initial value should be added for the bankroll total
*/
val shouldAddInitialValue: Boolean
get() {
return this.from == null
}
}
/**
* A TransactionBucket holds a list of transactions and computes its amount sum
*/
class TransactionBucket(useRate: Boolean = false) {
/**
* A list of transactions
*/
var transactions: MutableList<Transaction> = mutableListOf()
private set
/**
* The sum of all transactions
*/
var total: Double = 0.0
private set
/**
* Whether the bankroll rate should be used
*/
var useRate: Boolean = useRate
private set

@ -3,8 +3,6 @@ package net.pokeranalytics.android.model.migrations
import io.realm.DynamicRealm
import io.realm.RealmMigration
import timber.log.Timber
import java.util.*
import io.realm.RealmObjectSchema
@ -23,16 +21,12 @@ class PokerAnalyticsMigration : RealmMigration {
if (currentVersion == 0) {
Timber.d("*** Running migration 1")
schema.get("Filter")?.let {
it.addField("entityType", Int::class.java).setNullable("entityType", true)
}
schema.get("Filter")?.addField("entityType", Int::class.java)?.setNullable("entityType", true)
schema.get("FilterElement")?.let {
it.setNullable("filterName", true)
it.setNullable("sectionName", true)
}
schema.get("FilterElementBlind")?.let {
it.renameField("code", "currencyCode")
}
schema.get("FilterElementBlind")?.renameField("code", "currencyCode")
currentVersion++
}
@ -40,9 +34,9 @@ class PokerAnalyticsMigration : RealmMigration {
if (currentVersion == 1) {
Timber.d("*** Running migration ${currentVersion + 1}")
schema.rename("FilterElement", "FilterCondition")
schema.get("Filter")?.let {
it.renameField("filterElements", "filterConditions")
}
schema.get("Filter")?.renameField("filterElements", "filterConditions")
schema.get("SessionSet")?.let {
it.addField("id", String::class.java).setRequired("id", true)
it.addPrimaryKey("id")
@ -50,14 +44,12 @@ class PokerAnalyticsMigration : RealmMigration {
currentVersion++
}
// Migrate to version 2
// Migrate to version 3
if (currentVersion == 2) {
Timber.d("*** Running migration ${currentVersion + 1}")
schema.rename("Report", "ReportSetup")
schema.get("Filter")?.let {
it.removeField("entityType")
}
schema.get("Filter")?.removeField("entityType")
schema.get("Session")?.let {
it.addField("blinds", String::class.java).transform {
@ -80,26 +72,28 @@ class PokerAnalyticsMigration : RealmMigration {
it.addField("stringValue", String::class.java)
}
schema.get("ComputableResult")?.let {
it.removeField("sessionSet")
}
schema.get("ComputableResult")?.removeField("sessionSet")
schema.get("Bankroll")?.let {
it.addField("initialValue", Double::class.java)
}
schema.get("Bankroll")?.addField("initialValue", Double::class.java)
currentVersion++
}
// Migrate to version 3
// Migrate to version 4
if (currentVersion == 3) {
Timber.d("*** Running migration ${currentVersion + 1}")
schema.get("Result")?.let {
it.addField("numberOfRebuy", Double::class.java).setNullable("numberOfRebuy", true)
schema.get("Result")?.addField("numberOfRebuy", Double::class.java)?.setNullable("numberOfRebuy", true)
currentVersion++
}
// Migrate to version 5
if (currentVersion == 4) {
Timber.d("*** Running migration ${currentVersion + 1}")
schema.get("Bankroll")?.removeField("transactions")
currentVersion++
}
}
override fun equals(other: Any?): Boolean {

@ -1,8 +1,9 @@
package net.pokeranalytics.android.model.realm
import io.realm.Realm
import io.realm.RealmList
import io.realm.RealmObject
import io.realm.RealmResults
import io.realm.annotations.LinkingObjects
import io.realm.annotations.PrimaryKey
import io.realm.kotlin.where
import net.pokeranalytics.android.R
@ -13,7 +14,7 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.BankrollRow
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
import java.util.*
open class Bankroll() : RealmObject(), NameManageable, RowRepresentable {
open class Bankroll : RealmObject(), NameManageable, RowRepresentable {
@PrimaryKey
override var id = UUID.randomUUID().toString()
@ -23,8 +24,11 @@ open class Bankroll() : RealmObject(), NameManageable, RowRepresentable {
// Indicates whether the bankroll is live or online
var live: Boolean = true
// The list of transactions of the bankroll
var transactions: RealmList<Transaction> = RealmList()
/**
* The list of transactions of the bankroll
*/
@LinkingObjects("bankroll")
val transactions: RealmResults<Transaction>? = null
// The currency of the bankroll
var currency: Currency? = null

Loading…
Cancel
Save