|
|
|
|
@ -8,6 +8,7 @@ import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import org.apache.commons.math3.fitting.PolynomialCurveFitter |
|
|
|
|
import org.apache.commons.math3.fitting.WeightedObservedPoints |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.math.pow |
|
|
|
|
import kotlin.math.round |
|
|
|
|
@ -44,13 +45,18 @@ class CashGameOptimalDurationCalculator { |
|
|
|
|
|
|
|
|
|
val sessions = query.queryWith(realm.where(Session::class.java)).findAll() |
|
|
|
|
val sessionsByDuration = sessions.groupBy { |
|
|
|
|
round((it.netDuration / bucket).toDouble()) * bucket |
|
|
|
|
val dur = round((it.netDuration / bucket).toDouble()) * bucket |
|
|
|
|
Timber.d("Stop notif > key: $dur") |
|
|
|
|
dur |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// define validity interval |
|
|
|
|
var start: Double? = null |
|
|
|
|
var end: Double? = null |
|
|
|
|
var validBuckets = 0 |
|
|
|
|
|
|
|
|
|
val hkeys = sessionsByDuration.keys.map { it / 3600 / 1000.0 }.sorted() |
|
|
|
|
Timber.d("Stop notif > keys: $hkeys ") |
|
|
|
|
for (key in sessionsByDuration.keys.sorted()) { |
|
|
|
|
val sessionCount = sessionsByDuration[key]?.size ?: 0 |
|
|
|
|
if (start == null && sessionCount >= minimumValidityCount) { |
|
|
|
|
@ -61,12 +67,15 @@ class CashGameOptimalDurationCalculator { |
|
|
|
|
validBuckets++ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Timber.d("Stop notif > validBuckets: $validBuckets ") |
|
|
|
|
if (!(start != null && end != null && (end - start) >= intervalValidity)) { |
|
|
|
|
Timber.d("Stop notif > invalid setup: $start / $end ") |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// define if we have enough sessions |
|
|
|
|
if (sessions.size < 50) { |
|
|
|
|
Timber.d("Stop notif > not enough sessions: ${sessions.size} ") |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -115,6 +124,7 @@ class CashGameOptimalDurationCalculator { |
|
|
|
|
return bestDuration |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Timber.d("Stop notif > not found, best duration: $bestDuration") |
|
|
|
|
realm.close() |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
|