|
|
|
|
@ -12,6 +12,7 @@ import net.pokeranalytics.android.calculus.optimalduration.CashGameOptimalDurati |
|
|
|
|
import net.pokeranalytics.android.model.LiveOnline |
|
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
|
import net.pokeranalytics.android.ui.view.rows.StaticReport |
|
|
|
|
import net.pokeranalytics.android.util.CrashLogging |
|
|
|
|
import net.pokeranalytics.android.util.extensions.formattedHourlyDuration |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
@ -32,7 +33,7 @@ class ReportWhistleBlower(var context: Context) { |
|
|
|
|
|
|
|
|
|
private val listeners: MutableList<NewPerformanceListener> = mutableListOf() |
|
|
|
|
|
|
|
|
|
private var paused: Boolean = false |
|
|
|
|
var paused: Boolean = false |
|
|
|
|
|
|
|
|
|
private var timer: CountDownTimer? = null |
|
|
|
|
|
|
|
|
|
@ -65,6 +66,7 @@ class ReportWhistleBlower(var context: Context) { |
|
|
|
|
// Timber.d(">>> Launch report") |
|
|
|
|
|
|
|
|
|
if (paused) { |
|
|
|
|
CrashLogging.log("can't start reports comparisons because of paused state") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -131,10 +133,13 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
|
|
|
|
|
private var cancelled = false |
|
|
|
|
|
|
|
|
|
var handler: (() -> Unit)? = null |
|
|
|
|
|
|
|
|
|
private val coroutineContext: CoroutineContext |
|
|
|
|
get() = Dispatchers.Default |
|
|
|
|
|
|
|
|
|
fun start() { |
|
|
|
|
messages.add("Starting task...") |
|
|
|
|
launchReports() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -142,6 +147,8 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
this.cancelled = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var messages: MutableList<String> = mutableListOf() |
|
|
|
|
|
|
|
|
|
private fun launchReports() { |
|
|
|
|
CoroutineScope(coroutineContext).launch { |
|
|
|
|
|
|
|
|
|
@ -190,14 +197,18 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun launchOptimalDuration(realm: Realm, report: StaticReport) { |
|
|
|
|
LiveOnline.values().forEach { key -> |
|
|
|
|
LiveOnline.entries.forEach { key -> |
|
|
|
|
val duration = CashGameOptimalDurationCalculator.start(key.isLive) |
|
|
|
|
analyseOptimalDuration(realm, report, key, duration) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.handler?.let { it() } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun analyseDefaultReport(realm: Realm, staticReport: StaticReport, result: Report) { |
|
|
|
|
|
|
|
|
|
messages.add("Analyse report $staticReport...") |
|
|
|
|
|
|
|
|
|
val nameSeparator = " " |
|
|
|
|
|
|
|
|
|
for (stat in result.options.stats) { |
|
|
|
|
@ -217,6 +228,7 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
// Store if necessary, delete if necessary |
|
|
|
|
val bestComputedResults = result.max(stat) |
|
|
|
|
bestComputedResults?.let { computedResults -> |
|
|
|
|
messages.add("found new perf...") |
|
|
|
|
|
|
|
|
|
val performanceQuery = computedResults.group.query |
|
|
|
|
val performanceName = performanceQuery.getName(this.context, nameSeparator) |
|
|
|
|
@ -225,6 +237,8 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
|
|
|
|
|
var storePerf = true |
|
|
|
|
currentPerf?.let { |
|
|
|
|
messages.add("has current perf...") |
|
|
|
|
|
|
|
|
|
currentPerf.name?.let { name -> |
|
|
|
|
if (computedResults.group.query.getName(this.context, nameSeparator) == name) { |
|
|
|
|
storePerf = false |
|
|
|
|
@ -246,6 +260,7 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
messages.add("storePerf = $storePerf...") |
|
|
|
|
|
|
|
|
|
if (currentPerf == null && storePerf) { |
|
|
|
|
val performance = Performance( |
|
|
|
|
@ -261,6 +276,9 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} ?: run { // if there is no max but a now irrelevant Performance, we delete it |
|
|
|
|
|
|
|
|
|
messages.add("deletes current perf if necessary: $currentPerf...") |
|
|
|
|
|
|
|
|
|
// Timber.d("NO best computed value, current perf = $currentPerf ") |
|
|
|
|
currentPerf?.let { perf -> |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
|