Fixing crash when selecting Stats > Number of sessions

feature/top10
Laurent 7 years ago
parent c20b63e752
commit e361fab41c
  1. 2
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  2. 86
      app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt

@ -193,6 +193,8 @@ enum class Stat : RowRepresentable {
val resId = when (this) {
AVERAGE, AVERAGE_DURATION, NET_BB_PER_100_HANDS,
HOURLY_RATE_BB, AVERAGE_NET_BB, ROI, WIN_RATIO, HOURLY_RATE -> R.string.average
NUMBER_OF_SETS -> R.string.number_of_sessions
NUMBER_OF_GAMES -> R.string.number_of_records
NETRESULT, DURATION -> R.string.total
STANDARD_DEVIATION -> R.string.net_result
STANDARD_DEVIATION_HOURLY -> R.string.hour_rate_without_pauses

@ -72,35 +72,20 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
initUI()
}
// OnChartValueSelectedListener
override fun onNothingSelected() {
// nothing to do
}
override fun onValueSelected(e: Entry?, h: Highlight?) {
e?.let { entry ->
val statEntry = when (entry.data) {
is ObjectIdentifier -> {
val identifier = entry.data as ObjectIdentifier
getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull()
}
is StatEntry -> entry.data as StatEntry?
else -> null
}
statEntry?.let {
/**
* Set data
*/
fun setData(stat: Stat, group: ComputableGroup, report: Report, displayAggregationChoices: Boolean = true) {
this.stat = stat
this.computableGroup = group
val formattedDate = it.entryTitle
val entryValue = it.formattedValue(this.stat, requireContext())
val totalStatValue = this.stat.format(e.y.toDouble(), currency = null, context = requireContext())
this.aggregationTypes = stat.aggregationTypes
this.reports[this.aggregationTypes.first()] = report
this.selectedReport = report
this.displayAggregationChoices = displayAggregationChoices
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue)
}
}
}
/**
* Init UI
*/
@ -122,9 +107,9 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
this.loadGraph(this.aggregationTypes.first(), this.selectedReport)
this.aggregationTypes.forEach { type ->
this.aggregationTypes.forEachIndexed { index, type ->
val chip = Chip(requireContext())
chip.id = type.ordinal
chip.id = index
chip.text = requireContext().getString(type.resId)
chip.chipStartPadding = 8f.px
chip.chipEndPadding = 8f.px
@ -132,7 +117,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
}
this.chipGroup.isVisible = displayAggregationChoices
this.chipGroup.check(this.stat.aggregationTypes.first().ordinal)
this.chipGroup.check(0)
this.chipGroup.setOnCheckedChangeListener(object : ChipGroupExtension.SingleSelectionOnCheckedListener() {
override fun onCheckedChanged(group: ChipGroup, checkedId: Int) {
@ -161,7 +146,8 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
val realm = Realm.getDefaultInstance()
val report = Calculator.computeStatsWithEvolutionByAggregationType(realm, computableGroup, aggregationType)
val report =
Calculator.computeStatsWithEvolutionByAggregationType(realm, computableGroup, aggregationType)
reports[aggregationType] = report
r = report
@ -188,7 +174,12 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
val graphEntries = when (aggregationType) {
AggregationType.SESSION, AggregationType.DURATION -> report.results.firstOrNull()?.defaultStatEntries(stat)
AggregationType.MONTH, AggregationType.YEAR -> report.lineEntries(this.stat)
AggregationType.MONTH, AggregationType.YEAR -> {
when (this.stat) {
Stat.NUMBER_OF_GAMES, Stat.NUMBER_OF_SETS -> report.barEntries(this.stat)
else -> report.lineEntries(this.stat)
}
}
}
graphEntries?.let { entries ->
@ -225,18 +216,33 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
}
/**
* Set data
*/
fun setData(stat: Stat, group: ComputableGroup, report: Report, displayAggregationChoices: Boolean = true) {
this.stat = stat
this.computableGroup = group
// OnChartValueSelectedListener
this.aggregationTypes = stat.aggregationTypes
this.reports[this.aggregationTypes.first()] = report
this.selectedReport = report
this.displayAggregationChoices = displayAggregationChoices
override fun onNothingSelected() {
// nothing to do
}
override fun onValueSelected(e: Entry?, h: Highlight?) {
e?.let { entry ->
val statEntry = when (entry.data) {
is ObjectIdentifier -> {
val identifier = entry.data as ObjectIdentifier
getRealm().where(identifier.clazz).equalTo("id", identifier.id).findAll().firstOrNull()
}
is StatEntry -> entry.data as StatEntry?
else -> null
}
statEntry?.let {
val formattedDate = it.entryTitle
val entryValue = it.formattedValue(this.stat, requireContext())
val totalStatValue = this.stat.format(e.y.toDouble(), currency = null, context = requireContext())
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue)
}
}
}
}
Loading…
Cancel
Save