|
|
|
|
@ -1,15 +1,17 @@ |
|
|
|
|
package net.pokeranalytics.android.calculus |
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
|
import com.github.mikephil.charting.data.BarEntry |
|
|
|
|
import com.github.mikephil.charting.data.Entry |
|
|
|
|
import com.github.mikephil.charting.data.* |
|
|
|
|
import io.realm.Realm |
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Timed |
|
|
|
|
import net.pokeranalytics.android.model.realm.ComputableResult |
|
|
|
|
import net.pokeranalytics.android.model.realm.Filter |
|
|
|
|
import net.pokeranalytics.android.model.realm.SessionSet |
|
|
|
|
import net.pokeranalytics.android.ui.graph.PALineDataSet |
|
|
|
|
import kotlin.math.abs |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The class returned after performing calculation in the Calculator object |
|
|
|
|
@ -34,7 +36,7 @@ class Report(var options: Calculator.Options) { |
|
|
|
|
* Returns the list of entries corresponding to the provided [stat] |
|
|
|
|
* One value will be returned by result |
|
|
|
|
*/ |
|
|
|
|
fun lineEntries(stat: Stat): List<Entry> { |
|
|
|
|
fun lineEntries(stat: Stat, context: Context): LineDataSet { |
|
|
|
|
val entries = mutableListOf<Entry>() |
|
|
|
|
|
|
|
|
|
this._results.forEachIndexed { index, results -> |
|
|
|
|
@ -42,11 +44,11 @@ class Report(var options: Calculator.Options) { |
|
|
|
|
entries.add(Entry(index.toFloat(), progressValue.toFloat(), results)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return entries |
|
|
|
|
return PALineDataSet(entries, stat.name, context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun barEntries(stat: Stat? = null): List<Entry> { |
|
|
|
|
val entries = mutableListOf<Entry>() |
|
|
|
|
fun barEntries(stat: Stat? = null): BarDataSet { |
|
|
|
|
val entries = mutableListOf<BarEntry>() |
|
|
|
|
val statToUse = stat ?: options.displayedStats.firstOrNull() |
|
|
|
|
|
|
|
|
|
statToUse?.let { |
|
|
|
|
@ -59,16 +61,16 @@ class Report(var options: Calculator.Options) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return entries |
|
|
|
|
return BarDataSet(entries, stat?.name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun multiLineEntries(): List<List<Entry>> { |
|
|
|
|
fun multiLineEntries(context: Context): List<List<Entry>> { |
|
|
|
|
val entries = mutableListOf<List<Entry>>() |
|
|
|
|
|
|
|
|
|
options.displayedStats.forEach { stat -> |
|
|
|
|
this._results.forEach { result -> |
|
|
|
|
val entryList = result.singleLineEntries(stat) |
|
|
|
|
entries.add(entryList) |
|
|
|
|
val dataSet = result.singleLineEntries(stat, context) |
|
|
|
|
// entries.add(entryList) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -328,48 +330,55 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu |
|
|
|
|
|
|
|
|
|
this.consolidateProgressStats() |
|
|
|
|
|
|
|
|
|
if (options.evolutionValues != Calculator.Options.EvolutionValues.NONE) { |
|
|
|
|
|
|
|
|
|
// Sort points as a distribution |
|
|
|
|
this._computedStats.keys.filter { it.hasDistributionSorting() }.forEach { _ -> |
|
|
|
|
// @todo sort |
|
|
|
|
// var evolutionValues = this._evolutionValues[stat] |
|
|
|
|
// evolutionValues.so |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
// if (options.evolutionValues != Calculator.Options.EvolutionValues.NONE) { |
|
|
|
|
// |
|
|
|
|
// // Sort points as a distribution |
|
|
|
|
// this._computedStats.keys.filter { it.hasDistributionSorting() }.forEach { stat -> |
|
|
|
|
// // @todo sort |
|
|
|
|
// this._evolutionValues[stat]?.let { pointList -> |
|
|
|
|
// |
|
|
|
|
// pointList.sortBy { point -> |
|
|
|
|
// return@sortBy true |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// MPAndroidChart |
|
|
|
|
|
|
|
|
|
fun defaultStatEntries(stat: Stat): List<Entry> { |
|
|
|
|
fun defaultStatEntries(stat: Stat, context: Context): DataSet<out Entry> { |
|
|
|
|
return when (stat) { |
|
|
|
|
Stat.NUMBER_OF_SETS, Stat.NUMBER_OF_GAMES -> this.barEntries(stat) |
|
|
|
|
else -> this.singleLineEntries(stat) |
|
|
|
|
Stat.STANDARD_DEVIATION -> this.distributionEntries(stat, context) |
|
|
|
|
else -> this.singleLineEntries(stat, context) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun singleLineEntries(stat: Stat): List<Entry> { |
|
|
|
|
fun singleLineEntries(stat: Stat, context: Context): LineDataSet { |
|
|
|
|
val entries = mutableListOf<Entry>() |
|
|
|
|
this._evolutionValues[stat]?.let { points -> |
|
|
|
|
points.forEachIndexed { index, p -> |
|
|
|
|
entries.add(Entry(index.toFloat(), p.y.toFloat(), p.data)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return entries |
|
|
|
|
return PALineDataSet(entries, stat.name, context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun durationEntries(stat: Stat): List<Entry> { |
|
|
|
|
fun durationEntries(stat: Stat, context: Context): LineDataSet { |
|
|
|
|
val entries = mutableListOf<Entry>() |
|
|
|
|
this._evolutionValues[stat]?.let { points -> |
|
|
|
|
points.forEach { p -> |
|
|
|
|
entries.add(Entry(p.x.toFloat(), p.y.toFloat(), p.data)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return entries |
|
|
|
|
return PALineDataSet(entries, stat.name, context) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun barEntries(stat: Stat): List<BarEntry> { |
|
|
|
|
fun barEntries(stat: Stat): BarDataSet { |
|
|
|
|
|
|
|
|
|
val entries = mutableListOf<BarEntry>() |
|
|
|
|
this._evolutionValues[stat]?.let { points -> |
|
|
|
|
@ -377,7 +386,42 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu |
|
|
|
|
entries.add(BarEntry(p.x.toFloat(), p.y.toFloat(), p.data)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return entries |
|
|
|
|
return BarDataSet(entries, stat.name) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun distributionEntries(stat: Stat, context: Context): BarDataSet { |
|
|
|
|
|
|
|
|
|
val colors = mutableListOf<Int>() |
|
|
|
|
val entries = mutableListOf<BarEntry>() |
|
|
|
|
this._evolutionValues[stat]?.let { points -> |
|
|
|
|
|
|
|
|
|
val negative = mutableListOf<Point>() |
|
|
|
|
val positive = mutableListOf<Point>() |
|
|
|
|
points.forEach { |
|
|
|
|
if (it.y < 0) { |
|
|
|
|
negative.add(it) |
|
|
|
|
} else { |
|
|
|
|
positive.add(it) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
negative.sortBy { it.y } |
|
|
|
|
positive.sortByDescending { it.y } |
|
|
|
|
|
|
|
|
|
negative.forEachIndexed { index, p -> |
|
|
|
|
entries.add(BarEntry(index.toFloat(), abs(p.y.toFloat()), p.data)) |
|
|
|
|
colors.add(context.getColor(R.color.red)) |
|
|
|
|
} |
|
|
|
|
positive.forEachIndexed { index, p -> |
|
|
|
|
val x = negative.size + index.toFloat() |
|
|
|
|
entries.add(BarEntry(x, p.y.toFloat(), p.data)) |
|
|
|
|
colors.add(context.getColor(R.color.green)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
val dataSet = BarDataSet(entries, stat.name) |
|
|
|
|
dataSet.colors = colors |
|
|
|
|
return dataSet |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val isEmpty: Boolean |
|
|
|
|
|