|
|
|
|
@ -7,11 +7,15 @@ import io.realm.RealmResults |
|
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
import net.pokeranalytics.android.calculus.optimalduration.CashGameOptimalDurationCalculator |
|
|
|
|
import net.pokeranalytics.android.model.LiveOnline |
|
|
|
|
import net.pokeranalytics.android.model.realm.CustomField |
|
|
|
|
import net.pokeranalytics.android.model.realm.Performance |
|
|
|
|
import net.pokeranalytics.android.model.realm.Result |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.PerformanceKey |
|
|
|
|
import net.pokeranalytics.android.ui.view.rows.StaticReport |
|
|
|
|
import net.pokeranalytics.android.util.extensions.formattedHourlyDuration |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
@ -137,21 +141,28 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
|
|
|
|
|
Timber.d(">>> launch report = $report") |
|
|
|
|
|
|
|
|
|
when (report) { |
|
|
|
|
StaticReport.OptimalDuration -> launchOptimalDuration(realm, report) |
|
|
|
|
else -> launchDefaultReport(realm, report) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun launchDefaultReport(realm: Realm, report: StaticReport) { |
|
|
|
|
val options = Calculator.Options( |
|
|
|
|
stats = report.stats, |
|
|
|
|
criterias = report.criteria |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
val result = Calculator.computeStats(realm, options = options) |
|
|
|
|
analyseReport(realm, report, result) |
|
|
|
|
|
|
|
|
|
analyseDefaultReport(realm, report, result) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun analyseReport(realm: Realm, staticReport: StaticReport, result: Report) { |
|
|
|
|
|
|
|
|
|
when (staticReport.uniqueIdentifier) { |
|
|
|
|
StaticReport.OptimalDuration.uniqueIdentifier -> analyseOptimalDuration(staticReport, result) |
|
|
|
|
else -> analyseDefaultReport(realm, staticReport, result) |
|
|
|
|
private fun launchOptimalDuration(realm: Realm, report: StaticReport) { |
|
|
|
|
LiveOnline.values().forEach { key -> |
|
|
|
|
val duration = CashGameOptimalDurationCalculator.start(key.isLive) |
|
|
|
|
duration?.let { |
|
|
|
|
analyseOptimalDuration(realm, report, key, it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -166,7 +177,7 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
val customField: CustomField? = |
|
|
|
|
(staticReport as? StaticReport.CustomFieldList)?.customField |
|
|
|
|
var query = realm.where(Performance::class.java) |
|
|
|
|
.equalTo("statId", stat.uniqueIdentifier) |
|
|
|
|
.equalTo("key", stat.uniqueIdentifier) |
|
|
|
|
.equalTo("reportId", staticReport.uniqueIdentifier) |
|
|
|
|
|
|
|
|
|
customField?.let { |
|
|
|
|
@ -174,15 +185,16 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
} |
|
|
|
|
val currentPerf = query.findFirst() |
|
|
|
|
|
|
|
|
|
val performanceQuery = computedResults.group.query |
|
|
|
|
val performanceName = performanceQuery.getName(this.context, " ") |
|
|
|
|
|
|
|
|
|
var storePerf = true |
|
|
|
|
currentPerf?.let { |
|
|
|
|
Timber.d("cr name = ${computedResults.group.query.getName(this.context)}") |
|
|
|
|
currentPerf.name?.let { |
|
|
|
|
if (computedResults.group.query.defaultName == it) { |
|
|
|
|
storePerf = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Timber.d("cr objectId = ${computedResults.group.query.objectId}") |
|
|
|
|
currentPerf.objectId?.let { |
|
|
|
|
if (computedResults.group.query.objectId == it) { |
|
|
|
|
storePerf = false |
|
|
|
|
@ -191,8 +203,8 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
|
|
|
|
|
if (storePerf) { |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
currentPerf.name = computedResults.group.query.getName(this.context) |
|
|
|
|
currentPerf.objectId = computedResults.group.query.objectId |
|
|
|
|
currentPerf.name = performanceName |
|
|
|
|
currentPerf.objectId = performanceQuery.objectId |
|
|
|
|
currentPerf.customFieldId = customField?.id |
|
|
|
|
} |
|
|
|
|
this.whistleBlower.notify(currentPerf) |
|
|
|
|
@ -204,8 +216,8 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
val performance = Performance( |
|
|
|
|
staticReport, |
|
|
|
|
stat, |
|
|
|
|
computedResults.group.query.getName(this.context), |
|
|
|
|
computedResults.group.query.objectId, |
|
|
|
|
performanceName, |
|
|
|
|
performanceQuery.objectId, |
|
|
|
|
customField?.id, |
|
|
|
|
null |
|
|
|
|
) |
|
|
|
|
@ -219,7 +231,34 @@ class ReportTask(private var whistleBlower: ReportWhistleBlower, var context: Co |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun analyseOptimalDuration(staticReport: StaticReport, result: Report) { |
|
|
|
|
private fun analyseOptimalDuration(realm: Realm, staticReport: StaticReport, key: PerformanceKey, duration: Double) { |
|
|
|
|
|
|
|
|
|
var storePerf: Boolean = true |
|
|
|
|
|
|
|
|
|
val performance = realm.where(Performance::class.java) |
|
|
|
|
.equalTo("reportId", staticReport.uniqueIdentifier) |
|
|
|
|
.equalTo("key", key.value) |
|
|
|
|
.findFirst() |
|
|
|
|
|
|
|
|
|
val formattedDuration = (duration / 3600 / 1000).formattedHourlyDuration() |
|
|
|
|
performance?.let { perf -> |
|
|
|
|
if (perf.value == duration) { |
|
|
|
|
storePerf = false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (storePerf) { |
|
|
|
|
realm.executeTransaction { |
|
|
|
|
perf.name = formattedDuration |
|
|
|
|
perf.value = duration |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (storePerf) { |
|
|
|
|
val perf = Performance(staticReport, key, name = formattedDuration, value = duration) |
|
|
|
|
realm.executeTransaction { it.copyToRealm(perf) } |
|
|
|
|
this.whistleBlower.notify(perf) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|