|
|
|
|
@ -13,7 +13,9 @@ import com.github.mikephil.charting.highlight.Highlight |
|
|
|
|
import com.github.mikephil.charting.listener.OnChartValueSelectedListener |
|
|
|
|
import com.google.android.material.chip.Chip |
|
|
|
|
import com.google.android.material.chip.ChipGroup |
|
|
|
|
import io.realm.Realm |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_evograph.* |
|
|
|
|
import kotlinx.coroutines.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.calculus.* |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
|
@ -23,25 +25,32 @@ import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
|
import net.pokeranalytics.android.ui.graph.PALineDataSet |
|
|
|
|
import net.pokeranalytics.android.ui.graph.setStyle |
|
|
|
|
import net.pokeranalytics.android.ui.view.LegendView |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.text.DateFormat |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
class GraphParameters(var stat: Stat, var report: Report) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
|
class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, CoroutineScope { |
|
|
|
|
|
|
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
|
|
|
|
|
|
private var stat: Stat = Stat.NETRESULT |
|
|
|
|
private var reports: Map<AggregationType, Report> = hashMapOf() |
|
|
|
|
private var entries: List<Entry> = ArrayList() |
|
|
|
|
private var reports: MutableMap<AggregationType, Report> = hashMapOf() |
|
|
|
|
|
|
|
|
|
private var selectedReport: Report? = null |
|
|
|
|
|
|
|
|
|
lateinit var legendView: LegendView |
|
|
|
|
lateinit var chartView: BarLineChartBase<*> |
|
|
|
|
|
|
|
|
|
private var aggregationTypes: List<AggregationType> = listOf() |
|
|
|
|
|
|
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
|
get() = Dispatchers.Main |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -50,10 +59,8 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
|
this.stat = stat |
|
|
|
|
|
|
|
|
|
this.aggregationTypes = stat.aggregationTypes |
|
|
|
|
// this.report = report |
|
|
|
|
report.results.firstOrNull()?.defaultStatEntries(stat)?.let { |
|
|
|
|
this.entries = it |
|
|
|
|
} |
|
|
|
|
this.reports[this.aggregationTypes.first()] = report |
|
|
|
|
this.selectedReport = report |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -76,9 +83,78 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
|
|
|
|
|
|
this.legendView = LegendView(requireContext()) |
|
|
|
|
this.legendContainer.addView(this.legendView) |
|
|
|
|
this.legendView.prepareWithStat(this.stat, this.entries.size) |
|
|
|
|
|
|
|
|
|
val dataSet = PALineDataSet(this.entries, this.stat.name, requireContext()) |
|
|
|
|
this.selectedReport?.let { |
|
|
|
|
this.loadGraph(it) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.aggregationTypes.forEach { type -> |
|
|
|
|
val chip = Chip(requireContext()) |
|
|
|
|
chip.id = type.ordinal |
|
|
|
|
chip.text = requireContext().getString(type.resId) |
|
|
|
|
chip.chipStartPadding = 8f.px |
|
|
|
|
chip.chipEndPadding = 8f.px |
|
|
|
|
this.chipGroup.addView(chip) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.chipGroup.check(this.stat.aggregationTypes.first().ordinal) |
|
|
|
|
|
|
|
|
|
this.chipGroup.setOnCheckedChangeListener(object : ChipGroupExtension.SingleSelectionOnCheckedListener() { |
|
|
|
|
override fun onCheckedChanged(group: ChipGroup, checkedId: Int) { |
|
|
|
|
super.onCheckedChanged(group, checkedId) |
|
|
|
|
val aggregationType = aggregationTypes[checkedId] |
|
|
|
|
|
|
|
|
|
reports[aggregationType]?.let { |
|
|
|
|
loadGraph(it) |
|
|
|
|
} ?: run { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun launchStatComputation() { |
|
|
|
|
|
|
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
|
|
|
|
|
|
var r: Report? = null |
|
|
|
|
val test = GlobalScope.async { |
|
|
|
|
val s = Date() |
|
|
|
|
Timber.d(">>> start...") |
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
|
|
|
|
|
val aggregationType = stat.aggregationTypes.first() |
|
|
|
|
// r = Calculator.computeStatsWithEvolutionByAggregationType(realm, computableGroup, aggregationType) |
|
|
|
|
|
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
val e = Date() |
|
|
|
|
val duration = (e.time - s.time) / 1000.0 |
|
|
|
|
Timber.d(">>> ended in $duration seconds") |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
test.await() |
|
|
|
|
|
|
|
|
|
if (!isDetached) { |
|
|
|
|
r?.let { |
|
|
|
|
loadGraph(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun loadGraph(report: Report) { |
|
|
|
|
|
|
|
|
|
report.results.firstOrNull()?.defaultStatEntries(stat)?.let { entries -> |
|
|
|
|
|
|
|
|
|
this.legendView.prepareWithStat(this.stat, entries.size) |
|
|
|
|
|
|
|
|
|
val dataSet = PALineDataSet(entries, this.stat.name, requireContext()) |
|
|
|
|
val colors = arrayOf(R.color.green_light).toIntArray() |
|
|
|
|
dataSet.setColors(colors, context) |
|
|
|
|
dataSet.setDrawCircles(false) |
|
|
|
|
@ -101,26 +177,8 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
|
this.chartView.setStyle(false, requireContext()) |
|
|
|
|
this.chartView.setOnChartValueSelectedListener(this) |
|
|
|
|
|
|
|
|
|
this.chartView.highlightValue((this.entries.size - 1).toFloat(), 0) |
|
|
|
|
|
|
|
|
|
this.aggregationTypes.forEach { type -> |
|
|
|
|
val chip = Chip(requireContext()) |
|
|
|
|
chip.id = type.ordinal |
|
|
|
|
chip.text = requireContext().getString(type.resId) |
|
|
|
|
chip.chipStartPadding = 8f.px |
|
|
|
|
chip.chipEndPadding = 8f.px |
|
|
|
|
this.chipGroup.addView(chip) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.chipGroup.check(this.stat.aggregationTypes.first().ordinal) |
|
|
|
|
|
|
|
|
|
this.chipGroup.setOnCheckedChangeListener(object : ChipGroupExtension.SingleSelectionOnCheckedListener() { |
|
|
|
|
override fun onCheckedChanged(group: ChipGroup, checkedId: Int) { |
|
|
|
|
super.onCheckedChanged(group, checkedId) |
|
|
|
|
val aggregationType = aggregationTypes[checkedId] |
|
|
|
|
// toast("Show: ${this.aggregationTypes[group.getChildAt(checkedId).id].name}") |
|
|
|
|
this.chartView.highlightValue((entries.size - 1).toFloat(), 0) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -133,7 +191,6 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
|
override fun onValueSelected(e: Entry?, h: Highlight?) { |
|
|
|
|
|
|
|
|
|
e?.let { entry -> |
|
|
|
|
h?.let { highlight -> |
|
|
|
|
|
|
|
|
|
val identifier = entry.data as ObjectIdentifier |
|
|
|
|
val item = getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull() |
|
|
|
|
@ -145,7 +202,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener { |
|
|
|
|
|
|
|
|
|
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|