|
|
|
|
@ -1,9 +1,13 @@ |
|
|
|
|
package net.pokeranalytics.android.calculus.bankroll |
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
|
import com.github.mikephil.charting.data.Entry |
|
|
|
|
import com.github.mikephil.charting.data.LineDataSet |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.DatedValue |
|
|
|
|
import net.pokeranalytics.android.model.realm.Bankroll |
|
|
|
|
import net.pokeranalytics.android.model.realm.Transaction |
|
|
|
|
import net.pokeranalytics.android.ui.graph.PALineDataSet |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.collections.HashMap |
|
|
|
|
|
|
|
|
|
@ -89,7 +93,7 @@ class BankrollReport(setup: BankrollReportSetup) { |
|
|
|
|
var bucket = this.transactionBuckets[type.id] |
|
|
|
|
|
|
|
|
|
if (bucket == null) { |
|
|
|
|
val b = TransactionBucket(this.setup.bankroll == null) |
|
|
|
|
val b = TransactionBucket(this.setup.virtualBankroll) |
|
|
|
|
this.transactionBuckets[type.id] = b |
|
|
|
|
bucket = b |
|
|
|
|
} |
|
|
|
|
@ -102,6 +106,31 @@ class BankrollReport(setup: BankrollReportSetup) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun generateGraphPointsIfNecessary() { |
|
|
|
|
|
|
|
|
|
if (!this.setup.virtualBankroll) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.evolutionItems.sortBy { it.date } |
|
|
|
|
|
|
|
|
|
this.evolutionItems.forEach { |
|
|
|
|
val point = BRGraphPoint(it.amount, it.date, it) |
|
|
|
|
this.evolutionPoints.add(point) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun lineDataSet(context: Context): LineDataSet { |
|
|
|
|
|
|
|
|
|
val entries = mutableListOf<Entry>() |
|
|
|
|
this.evolutionPoints.forEach { |
|
|
|
|
val entry = Entry(it.date.time.toFloat(), it.value.toFloat(), it.data) |
|
|
|
|
entries.add(entry) |
|
|
|
|
} |
|
|
|
|
return PALineDataSet(entries, "", context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -110,6 +139,11 @@ class BankrollReport(setup: BankrollReportSetup) { |
|
|
|
|
*/ |
|
|
|
|
class BankrollReportSetup(val bankroll: Bankroll?, val from: Date? = null, val to: Date? = null) { |
|
|
|
|
|
|
|
|
|
val virtualBankroll: Boolean |
|
|
|
|
get() { |
|
|
|
|
return this.bankroll == null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val queryConditions: List<QueryCondition> |
|
|
|
|
get() { |
|
|
|
|
val conditions = mutableListOf<QueryCondition>() |
|
|
|
|
@ -157,7 +191,7 @@ class TransactionBucket(useRate: Boolean = false) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
data class BRGraphPoint(var value: Double = 0.0, var date: Date? = null, var data: Any? = null) { |
|
|
|
|
data class BRGraphPoint(var value: Double, var date: Date, var data: Any? = null) { |
|
|
|
|
|
|
|
|
|
var variation: Double = 0.0 |
|
|
|
|
|
|
|
|
|
|