|
|
|
|
@ -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(entry.y.toDouble(), currency = null, context = requireContext()) |
|
|
|
|
|
|
|
|
|
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |