|
|
|
@ -7,24 +7,32 @@ import android.view.LayoutInflater |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import com.github.mikephil.charting.data.Entry |
|
|
|
|
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
|
|
|
|
import io.realm.Realm |
|
|
|
import kotlinx.android.synthetic.main.fragment_calendar_details.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_calendar_details.* |
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
|
|
|
import kotlinx.coroutines.GlobalScope |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
|
|
|
import net.pokeranalytics.android.calculus.Calculator |
|
|
|
|
|
|
|
import net.pokeranalytics.android.calculus.ComputedResults |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.comparison.Comparator |
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
import net.pokeranalytics.android.ui.activity.CalendarDetailsActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.CalendarDetailsActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
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.RowRepresentableDelegate |
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.extensions.toast |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.GraphRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.GraphRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.StatDoubleRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.StatDoubleRow |
|
|
|
|
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
|
|
class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
|
|
@ -38,6 +46,8 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
private lateinit var statsAdapter: RowRepresentableAdapter |
|
|
|
private lateinit var statsAdapter: RowRepresentableAdapter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var computedResults: ComputedResults? = null |
|
|
|
|
|
|
|
private var sessionTypeCondition: QueryCondition? = null |
|
|
|
private var rowRepresentables: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
private var rowRepresentables: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
|
|
|
|
|
|
|
|
//private var stat: Stat = Stat.NETRESULT |
|
|
|
//private var stat: Stat = Stat.NETRESULT |
|
|
|
@ -49,13 +59,34 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
|
|
|
|
initData() |
|
|
|
initUI() |
|
|
|
initUI() |
|
|
|
|
|
|
|
launchStatComputation() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
return rowRepresentables |
|
|
|
return rowRepresentables |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
|
|
|
when(row) { |
|
|
|
|
|
|
|
is GraphRow -> { |
|
|
|
|
|
|
|
//TODO: Open graph details |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Init data |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private fun initData() { |
|
|
|
|
|
|
|
Timber.d("initData") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.computedResults = CalendarDetailsActivity.computedResults |
|
|
|
|
|
|
|
this.sessionTypeCondition = CalendarDetailsActivity.sessionTypeCondition |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Init UI |
|
|
|
* Init UI |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -74,9 +105,12 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
|
|
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
toast("Tab: ${tab.position}") |
|
|
|
when(tab.position) { |
|
|
|
|
|
|
|
0 -> sessionTypeCondition = null |
|
|
|
|
|
|
|
1 -> sessionTypeCondition = QueryCondition.CASH |
|
|
|
|
|
|
|
2 -> sessionTypeCondition = QueryCondition.TOURNAMENT |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
launchStatComputation() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onTabUnselected(tab: TabLayout.Tab) { |
|
|
|
override fun onTabUnselected(tab: TabLayout.Tab) { |
|
|
|
@ -86,7 +120,7 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
CalendarDetailsActivity.sessionTypeCondition?.let { |
|
|
|
sessionTypeCondition?.let { |
|
|
|
when(it) { |
|
|
|
when(it) { |
|
|
|
QueryCondition.CASH -> tabs.getTabAt(1)?.select() |
|
|
|
QueryCondition.CASH -> tabs.getTabAt(1)?.select() |
|
|
|
QueryCondition.TOURNAMENT -> tabs.getTabAt(2)?.select() |
|
|
|
QueryCondition.TOURNAMENT -> tabs.getTabAt(2)?.select() |
|
|
|
@ -94,28 +128,9 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CalendarDetailsActivity.computedResults?.let { computedResults -> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.net_result)) |
|
|
|
|
|
|
|
rowRepresentables.add(GraphRow(Stat.NETRESULT, null, "")) |
|
|
|
|
|
|
|
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.NETRESULT), computedResults.computedStat(Stat.HOURLY_RATE))) |
|
|
|
|
|
|
|
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.LOCATIONS_PLAYED), computedResults.computedStat(Stat.LONGEST_STREAKS))) |
|
|
|
|
|
|
|
rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.distribution)) |
|
|
|
|
|
|
|
rowRepresentables.add(GraphRow(Stat.NETRESULT, null, "")) |
|
|
|
|
|
|
|
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.WIN_RATIO))) |
|
|
|
|
|
|
|
rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.volume)) |
|
|
|
|
|
|
|
rowRepresentables.add(GraphRow(Stat.NETRESULT, null, "")) |
|
|
|
|
|
|
|
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.DURATION), computedResults.computedStat(Stat.AVERAGE_DURATION))) |
|
|
|
|
|
|
|
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.DAYS_PLAYED))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//computedResults.group.conditions |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
statsAdapter = RowRepresentableAdapter(this, this) |
|
|
|
statsAdapter = RowRepresentableAdapter(this, this) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
recyclerView.apply { |
|
|
|
recyclerView.apply { |
|
|
|
@ -124,29 +139,60 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
adapter = statsAdapter |
|
|
|
adapter = statsAdapter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
} |
|
|
|
toolbar.title = stat.localizedTitle(requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val fragmentManager = parentActivity.supportFragmentManager |
|
|
|
|
|
|
|
val fragmentTransaction = fragmentManager.beginTransaction() |
|
|
|
|
|
|
|
val fragment = GraphFragment() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fragmentTransaction.add(R.id.container, fragment) |
|
|
|
/** |
|
|
|
fragmentTransaction.commit() |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private fun launchStatComputation() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
computedResults?.let { computedResults -> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val startDate = Date() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
|
|
|
val conditions = ArrayList<QueryCondition>().apply { |
|
|
|
|
|
|
|
addAll(computedResults.group.conditions) |
|
|
|
|
|
|
|
when (sessionTypeCondition) { |
|
|
|
|
|
|
|
QueryCondition.CASH -> addAll(Comparator.CASH.queryConditions) |
|
|
|
|
|
|
|
QueryCondition.TOURNAMENT -> addAll(Comparator.TOURNAMENT.queryConditions) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val options = Calculator.Options(evolutionValues = Calculator.Options.EvolutionValues.STANDARD) |
|
|
|
|
|
|
|
val report = Calculator.computeStatsWithComparators(realm, conditions = conditions, options = options) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timber.d("Report take: ${System.currentTimeMillis() - startDate.time}ms") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rowRepresentables.clear() |
|
|
|
|
|
|
|
rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.net_result)) |
|
|
|
|
|
|
|
rowRepresentables.add(GraphRow(report, Stat.NETRESULT)) |
|
|
|
|
|
|
|
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.NETRESULT), computedResults.computedStat(Stat.HOURLY_RATE))) |
|
|
|
|
|
|
|
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.LOCATIONS_PLAYED), computedResults.computedStat(Stat.LONGEST_STREAKS))) |
|
|
|
|
|
|
|
rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.distribution)) |
|
|
|
|
|
|
|
rowRepresentables.add(GraphRow(report, Stat.NETRESULT)) |
|
|
|
|
|
|
|
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.WIN_RATIO))) |
|
|
|
|
|
|
|
rowRepresentables.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.volume)) |
|
|
|
|
|
|
|
rowRepresentables.add(GraphRow(report, Stat.NETRESULT)) |
|
|
|
|
|
|
|
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.DURATION), computedResults.computedStat(Stat.AVERAGE_DURATION))) |
|
|
|
|
|
|
|
rowRepresentables.add(StatDoubleRow(computedResults.computedStat(Stat.DAYS_PLAYED))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
launch(Dispatchers.Main) { |
|
|
|
|
|
|
|
statsAdapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
StatisticDetailsActivity.parameters?.let { |
|
|
|
|
|
|
|
fragment.setData(it.stat, it.report) |
|
|
|
|
|
|
|
StatisticDetailsActivity.parameters = null |
|
|
|
|
|
|
|
} ?: run { |
|
|
|
|
|
|
|
throw Exception("Missing graph parameters") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set data |
|
|
|
* Set data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun setData(stat: Stat, entries: List<Entry>) { |
|
|
|
fun setData(computedResults: ComputedResults?, sessionTypeCondition: QueryCondition?) { |
|
|
|
|
|
|
|
Timber.d("Set data") |
|
|
|
//this.stat = stat |
|
|
|
//this.stat = stat |
|
|
|
//this.entries = entries |
|
|
|
//this.entries = entries |
|
|
|
} |
|
|
|
} |
|
|
|
|