|
|
|
|
@ -10,7 +10,7 @@ import kotlinx.android.synthetic.main.fragment_stats.* |
|
|
|
|
import kotlinx.coroutines.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.calculus.* |
|
|
|
|
import net.pokeranalytics.android.model.StatRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.StatRow |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
import net.pokeranalytics.android.ui.activity.StatisticDetailsActivity |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.DisplayDescriptor |
|
|
|
|
@ -28,10 +28,10 @@ import kotlin.coroutines.CoroutineContext |
|
|
|
|
class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSource, CoroutineScope, |
|
|
|
|
RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
|
get() = Dispatchers.Main |
|
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
|
get() = Dispatchers.Main |
|
|
|
|
|
|
|
|
|
private var rowRepresentables: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
|
private var rowRepresentables: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
|
private var stringAll = "" |
|
|
|
|
private var stringCashGame = "" |
|
|
|
|
private var stringTournament = "" |
|
|
|
|
@ -74,7 +74,7 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
override fun contentDescriptorForRow(row: RowRepresentable): DisplayDescriptor? { |
|
|
|
|
val dc = DisplayDescriptor() |
|
|
|
|
dc.textFormat = TextFormat(NULL_TEXT) |
|
|
|
|
if (row is StatRepresentable) { |
|
|
|
|
if (row is StatRow) { |
|
|
|
|
context?.let { context -> |
|
|
|
|
row.computedStat?.let { |
|
|
|
|
dc.textFormat = it.format(context) |
|
|
|
|
@ -85,7 +85,7 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun statFormatForRow(row: RowRepresentable): TextFormat { |
|
|
|
|
if (row is StatRepresentable) { |
|
|
|
|
if (row is StatRow) { |
|
|
|
|
context?.let { context -> |
|
|
|
|
row.computedStat?.let { return it.format(context) } |
|
|
|
|
} |
|
|
|
|
@ -133,73 +133,95 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun launchStatComputation() { |
|
|
|
|
private fun launchStatComputation() { |
|
|
|
|
|
|
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
|
|
|
|
|
|
var r = Report() |
|
|
|
|
val test = GlobalScope.async { |
|
|
|
|
val s = Date() |
|
|
|
|
Timber.d(">>> start...") |
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
r = createSessionGroupsAndStartCompute(realm) |
|
|
|
|
report = r |
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
val e = Date() |
|
|
|
|
val duration = (e.time - s.time) / 1000.0 |
|
|
|
|
Timber.d(">>> ended in $duration seconds") |
|
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
test.await() |
|
|
|
|
var r = Report() |
|
|
|
|
val test = GlobalScope.async { |
|
|
|
|
val s = Date() |
|
|
|
|
Timber.d(">>> start...") |
|
|
|
|
|
|
|
|
|
if (!isDetached) { |
|
|
|
|
showResults(r) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
r = createSessionGroupsAndStartCompute(realm) |
|
|
|
|
report = r |
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
val e = Date() |
|
|
|
|
val duration = (e.time - s.time) / 1000.0 |
|
|
|
|
Timber.d(">>> ended in $duration seconds") |
|
|
|
|
|
|
|
|
|
private fun createSessionGroupsAndStartCompute(realm: Realm) : Report { |
|
|
|
|
} |
|
|
|
|
test.await() |
|
|
|
|
|
|
|
|
|
val allStats: List<Stat> = listOf(Stat.NETRESULT, Stat.HOURLY_RATE, Stat.AVERAGE, Stat.NUMBER_OF_SETS, Stat.AVERAGE_DURATION, Stat.DURATION) |
|
|
|
|
val allSessionGroup = ComputableGroup(stringAll, listOf(), allStats) |
|
|
|
|
val cgStats: List<Stat> = listOf(Stat.NETRESULT, Stat.HOURLY_RATE, Stat.NET_BB_PER_100_HANDS, Stat.HOURLY_RATE_BB, Stat.AVERAGE, Stat.STANDARD_DEVIATION_HOURLY, Stat.WIN_RATIO, Stat.NUMBER_OF_GAMES, Stat.AVERAGE_BUYIN) |
|
|
|
|
val cgSessionGroup = ComputableGroup(stringCashGame, listOf(QueryCondition.CASH), cgStats) |
|
|
|
|
val tStats: List<Stat> = listOf(Stat.NETRESULT, Stat.HOURLY_RATE, Stat.ROI, Stat.WIN_RATIO, Stat.NUMBER_OF_GAMES, Stat.AVERAGE_BUYIN) |
|
|
|
|
val tSessionGroup = ComputableGroup(stringTournament, listOf(QueryCondition.TOURNAMENT), tStats) |
|
|
|
|
if (!isDetached) { |
|
|
|
|
showResults(r) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Timber.d(">>>>> Start computations...") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Calculator.computeGroups(realm, listOf(allSessionGroup, cgSessionGroup, tSessionGroup), Calculator.Options()) |
|
|
|
|
private fun createSessionGroupsAndStartCompute(realm: Realm): Report { |
|
|
|
|
|
|
|
|
|
val allStats: List<Stat> = listOf( |
|
|
|
|
Stat.NETRESULT, |
|
|
|
|
Stat.HOURLY_RATE, |
|
|
|
|
Stat.AVERAGE, |
|
|
|
|
Stat.NUMBER_OF_SETS, |
|
|
|
|
Stat.AVERAGE_DURATION, |
|
|
|
|
Stat.DURATION |
|
|
|
|
) |
|
|
|
|
val allSessionGroup = ComputableGroup(stringAll, listOf(), allStats) |
|
|
|
|
val cgStats: List<Stat> = listOf( |
|
|
|
|
Stat.NETRESULT, |
|
|
|
|
Stat.HOURLY_RATE, |
|
|
|
|
Stat.NET_BB_PER_100_HANDS, |
|
|
|
|
Stat.HOURLY_RATE_BB, |
|
|
|
|
Stat.AVERAGE, |
|
|
|
|
Stat.STANDARD_DEVIATION_HOURLY, |
|
|
|
|
Stat.WIN_RATIO, |
|
|
|
|
Stat.NUMBER_OF_GAMES, |
|
|
|
|
Stat.AVERAGE_BUYIN |
|
|
|
|
) |
|
|
|
|
val cgSessionGroup = ComputableGroup(stringCashGame, listOf(QueryCondition.CASH), cgStats) |
|
|
|
|
val tStats: List<Stat> = |
|
|
|
|
listOf(Stat.NETRESULT, Stat.HOURLY_RATE, Stat.ROI, Stat.WIN_RATIO, Stat.NUMBER_OF_GAMES, Stat.AVERAGE_BUYIN) |
|
|
|
|
val tSessionGroup = ComputableGroup(stringTournament, listOf(QueryCondition.TOURNAMENT), tStats) |
|
|
|
|
|
|
|
|
|
Timber.d(">>>>> Start computations...") |
|
|
|
|
|
|
|
|
|
return Calculator.computeGroups( |
|
|
|
|
realm, |
|
|
|
|
listOf(allSessionGroup, cgSessionGroup, tSessionGroup), |
|
|
|
|
Calculator.Options() |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun showResults(report: Report) { |
|
|
|
|
this.rowRepresentables = this.convertReportIntoRepresentables(report) |
|
|
|
|
private fun showResults(report: Report) { |
|
|
|
|
this.rowRepresentables = this.convertReportIntoRepresentables(report) |
|
|
|
|
statsAdapter.notifyDataSetChanged() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun convertReportIntoRepresentables(report: Report) : ArrayList<RowRepresentable> { |
|
|
|
|
private fun convertReportIntoRepresentables(report: Report): ArrayList<RowRepresentable> { |
|
|
|
|
|
|
|
|
|
val rows: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
|
val rows: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
|
|
|
|
|
|
report.results.forEach { result -> |
|
|
|
|
rows.add(CustomizableRowRepresentable(title = result.group.name)) |
|
|
|
|
result.group.stats?.forEach { stat -> |
|
|
|
|
rows.add(StatRepresentable(stat, result.computedStat(stat), result.group.name)) |
|
|
|
|
rows.add(StatRow(stat, result.computedStat(stat), result.group.name)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return rows |
|
|
|
|
} |
|
|
|
|
return rows |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// RowRepresentableDelegate |
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
|
|
|
|
|
if (row is StatRepresentable && row.stat.hasEvolutionGraph) { |
|
|
|
|
if (row is StatRow && row.stat.hasEvolutionGraph) { |
|
|
|
|
|
|
|
|
|
// filter groups |
|
|
|
|
val groupResults = this.report?.results?.filter { |
|
|
|
|
@ -223,10 +245,14 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc |
|
|
|
|
Timber.d(">>> start...") |
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
val options = Calculator.Options() |
|
|
|
|
options.evolutionValues = Calculator.Options.EvolutionValues.STANDARD |
|
|
|
|
options.displayedStats = listOf(stat) |
|
|
|
|
report = Calculator.computeGroups(realm, listOf(computableGroup), options) |
|
|
|
|
// val options = Calculator.Options() |
|
|
|
|
// options.evolutionValues = Calculator.Options.EvolutionValues.STANDARD |
|
|
|
|
// options.displayedStats = listOf(stat) |
|
|
|
|
|
|
|
|
|
val aggregationType = stat.aggregationTypes.first() |
|
|
|
|
report = Calculator.computeStatsWithEvolutionByAggregationType(realm, computableGroup, aggregationType) |
|
|
|
|
|
|
|
|
|
// report = Calculator.computeGroups(realm, listOf(computableGroup), options) |
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
val e = Date() |
|
|
|
|
|