|
|
|
@ -14,8 +14,10 @@ import net.pokeranalytics.android.model.StatRepresentable |
|
|
|
import net.pokeranalytics.android.model.realm.ComputableResult |
|
|
|
import net.pokeranalytics.android.model.realm.ComputableResult |
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
import net.pokeranalytics.android.model.realm.SessionSet |
|
|
|
import net.pokeranalytics.android.model.realm.SessionSet |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.activity.GraphActivity |
|
|
|
import net.pokeranalytics.android.ui.adapter.DisplayDescriptor |
|
|
|
import net.pokeranalytics.android.ui.adapter.DisplayDescriptor |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.SessionObserverFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.SessionObserverFragment |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
@ -25,7 +27,8 @@ import timber.log.Timber |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
|
|
class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSource, CoroutineScope { |
|
|
|
class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSource, CoroutineScope, |
|
|
|
|
|
|
|
RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
get() = Dispatchers.Main |
|
|
|
get() = Dispatchers.Main |
|
|
|
@ -36,6 +39,7 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc |
|
|
|
private var stringTournament = "" |
|
|
|
private var stringTournament = "" |
|
|
|
|
|
|
|
|
|
|
|
private lateinit var statsAdapter: RowRepresentableAdapter |
|
|
|
private lateinit var statsAdapter: RowRepresentableAdapter |
|
|
|
|
|
|
|
private var computedResults : List<ComputedResults>? = null |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
|
|
@ -114,7 +118,7 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc |
|
|
|
this.stringCashGame = getString(R.string.cash_game) |
|
|
|
this.stringCashGame = getString(R.string.cash_game) |
|
|
|
this.stringTournament = getString(R.string.tournament) |
|
|
|
this.stringTournament = getString(R.string.tournament) |
|
|
|
|
|
|
|
|
|
|
|
this.statsAdapter = RowRepresentableAdapter(this) |
|
|
|
this.statsAdapter = RowRepresentableAdapter(this, this) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -131,7 +135,6 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun launchStatComputation() { |
|
|
|
private fun launchStatComputation() { |
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
@ -143,6 +146,7 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
results = createSessionGroupsAndStartCompute(realm) |
|
|
|
results = createSessionGroupsAndStartCompute(realm) |
|
|
|
|
|
|
|
computedResults = results |
|
|
|
realm.close() |
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
|
|
val e = Date() |
|
|
|
val e = Date() |
|
|
|
@ -202,11 +206,62 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc |
|
|
|
results.forEach { result -> |
|
|
|
results.forEach { result -> |
|
|
|
rows.add(CustomizableRowRepresentable(title = result.group.name)) |
|
|
|
rows.add(CustomizableRowRepresentable(title = result.group.name)) |
|
|
|
result.group.stats?.forEach { stat -> |
|
|
|
result.group.stats?.forEach { stat -> |
|
|
|
rows.add(StatRepresentable(stat, result.computedStat(stat))) |
|
|
|
rows.add(StatRepresentable(stat, result.computedStat(stat), result.group.name)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return rows |
|
|
|
return rows |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RowRepresentableDelegate |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (row is StatRepresentable) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// filter groups |
|
|
|
|
|
|
|
val groupResults = this.computedResults?.filter { |
|
|
|
|
|
|
|
it.group.name == row.groupName |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
groupResults?.firstOrNull()?.let { |
|
|
|
|
|
|
|
this.launchStatComputationWithEvolution(row.stat, it.group) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun launchStatComputationWithEvolution(stat: Stat, computableGroup: ComputableGroup) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var results = listOf<ComputedResults>() |
|
|
|
|
|
|
|
val test = GlobalScope.async { |
|
|
|
|
|
|
|
val s = Date() |
|
|
|
|
|
|
|
Timber.d(">>> start...") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
|
|
|
val options = Calculator.Options() |
|
|
|
|
|
|
|
options.evolutionValues = Calculator.Options.EvolutionValues.STANDARD |
|
|
|
|
|
|
|
results = Calculator.computeGroups(listOf(computableGroup), options) |
|
|
|
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val e = Date() |
|
|
|
|
|
|
|
val duration = (e.time - s.time) / 1000.0 |
|
|
|
|
|
|
|
Timber.d(">>> ended in ${duration} seconds") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
test.await() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isDetached) { |
|
|
|
|
|
|
|
results.firstOrNull()?.defaultStatEntries(stat)?.let { entries -> |
|
|
|
|
|
|
|
GraphActivity.newInstance(requireContext(), stat, entries) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |