You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.6 KiB
84 lines
2.6 KiB
package net.pokeranalytics.android.calcul
|
|
|
|
import android.content.Context
|
|
import com.github.mikephil.charting.data.*
|
|
import net.pokeranalytics.android.R
|
|
import net.pokeranalytics.android.calculus.ComputedResults
|
|
import net.pokeranalytics.android.calculus.Point
|
|
import net.pokeranalytics.android.calculus.Stat
|
|
import net.pokeranalytics.android.ui.graph.DataSetFactory
|
|
import kotlin.math.abs
|
|
|
|
|
|
// MPAndroidChart
|
|
|
|
fun ComputedResults.defaultStatEntries(stat: Stat, context: Context): DataSet<out Entry> {
|
|
return when (stat) {
|
|
Stat.NUMBER_OF_SETS, Stat.NUMBER_OF_GAMES, Stat.HOURLY_DURATION -> this.barEntries(stat, context = context)
|
|
Stat.STANDARD_DEVIATION -> this.distributionEntries(stat, context)
|
|
else -> this.singleLineEntries(stat, context)
|
|
}
|
|
}
|
|
|
|
fun ComputedResults.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 DataSetFactory.lineDataSetInstance(entries, this.group.query.getName(context), context)
|
|
}
|
|
|
|
fun ComputedResults.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 DataSetFactory.lineDataSetInstance(entries, stat.name, context)
|
|
}
|
|
|
|
private fun ComputedResults.barEntries(stat: Stat, context: Context): BarDataSet {
|
|
|
|
val entries = mutableListOf<BarEntry>()
|
|
this.evolutionValues[stat]?.let { points ->
|
|
points.forEach { p ->
|
|
entries.add(BarEntry(p.x.toFloat(), p.y.toFloat(), p.data))
|
|
}
|
|
}
|
|
return DataSetFactory.barDataSetInstance(entries, stat.name, context)
|
|
}
|
|
|
|
private fun ComputedResults.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.sortByDescending { it.y }
|
|
points.forEach {
|
|
if (it.y < 0) {
|
|
negative.add(it)
|
|
} else {
|
|
positive.add(it)
|
|
}
|
|
}
|
|
|
|
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))
|
|
}
|
|
|
|
}
|
|
return DataSetFactory.barDataSetInstance(entries, stat.name, context, colors)
|
|
}
|
|
|