Merge remote-tracking branch 'origin/dev' into dev

feature/top10
Razmig Sarkissian 7 years ago
commit 6b8d263417
  1. 2
      app/src/main/java/net/pokeranalytics/android/calculus/Report.kt
  2. 25
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  4. 12
      app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt
  5. 13
      app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt
  6. 4
      app/src/main/java/net/pokeranalytics/android/ui/fragment/StatsFragment.kt
  7. 31
      app/src/main/java/net/pokeranalytics/android/ui/graph/GraphExtensions.kt
  8. 32
      app/src/main/java/net/pokeranalytics/android/ui/graph/LargeNumberFormatter.kt
  9. 9
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  10. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt
  11. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/TransactionRowView.kt
  12. 22
      app/src/main/java/net/pokeranalytics/android/util/extensions/NumbersExtension.kt
  13. 34
      app/src/test/java/net/pokeranalytics/android/BasicUnitTest.kt
  14. 59
      app/src/test/java/net/pokeranalytics/android/ExampleUnitTest.kt

@ -391,7 +391,7 @@ class ComputedResults(group: ComputableGroup, shouldManageMultiGroupProgressValu
override fun formattedValue(stat: Stat, context: Context): TextFormat { override fun formattedValue(stat: Stat, context: Context): TextFormat {
this.computedStat(stat)?.let { this.computedStat(stat)?.let {
return it.format(context) return it.format()
} ?: run { } ?: run {
throw IllegalStateException("Missing stat in results") throw IllegalStateException("Missing stat in results")
} }

@ -4,6 +4,7 @@ import android.content.Context
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.FormattingException import net.pokeranalytics.android.exceptions.FormattingException
import net.pokeranalytics.android.model.interfaces.Timed import net.pokeranalytics.android.model.interfaces.Timed
import net.pokeranalytics.android.ui.graph.AxisFormatting
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.NULL_TEXT import net.pokeranalytics.android.util.NULL_TEXT
@ -48,6 +49,15 @@ enum class AggregationType {
DURATION -> R.string.duration DURATION -> R.string.duration
} }
} }
val axisFormatting: AxisFormatting
get() {
return when (this) {
DURATION -> AxisFormatting.X_DURATION
else -> AxisFormatting.DEFAULT
}
}
} }
/** /**
@ -147,7 +157,7 @@ enum class Stat : RowRepresentable {
/** /**
* Formats the value of the stat to be suitable for display * Formats the value of the stat to be suitable for display
*/ */
fun format(value: Double, secondValue: Double? = null, currency: Currency? = null, context: Context): TextFormat { fun format(value: Double, secondValue: Double? = null, currency: Currency? = null): TextFormat {
if (value.isNaN()) { if (value.isNaN()) {
return TextFormat(NULL_TEXT, R.color.white) return TextFormat(NULL_TEXT, R.color.white)
@ -195,7 +205,7 @@ enum class Stat : RowRepresentable {
} }
fun cumulativeLabelResId(context: Context) : String { fun cumulativeLabelResId(context: Context): String {
val resId = when (this) { val resId = when (this) {
AVERAGE, AVERAGE_DURATION, NET_BB_PER_100_HANDS, AVERAGE, AVERAGE_DURATION, NET_BB_PER_100_HANDS,
HOURLY_RATE_BB, AVERAGE_NET_BB, ROI, WIN_RATIO, HOURLY_RATE -> R.string.average HOURLY_RATE_BB, AVERAGE_NET_BB, ROI, WIN_RATIO, HOURLY_RATE -> R.string.average
@ -225,7 +235,12 @@ enum class Stat : RowRepresentable {
val aggregationTypes: List<AggregationType> val aggregationTypes: List<AggregationType>
get() { get() {
return when (this) { return when (this) {
NET_RESULT -> listOf(AggregationType.SESSION, AggregationType.MONTH, AggregationType.YEAR, AggregationType.DURATION) NET_RESULT -> listOf(
AggregationType.SESSION,
AggregationType.MONTH,
AggregationType.YEAR,
AggregationType.DURATION
)
NUMBER_OF_GAMES, NUMBER_OF_SETS -> listOf(AggregationType.MONTH, AggregationType.YEAR) NUMBER_OF_GAMES, NUMBER_OF_SETS -> listOf(AggregationType.MONTH, AggregationType.YEAR)
else -> listOf(AggregationType.SESSION, AggregationType.MONTH, AggregationType.YEAR) else -> listOf(AggregationType.SESSION, AggregationType.MONTH, AggregationType.YEAR)
} }
@ -282,8 +297,8 @@ class ComputedStat(var stat: Stat, var value: Double, var secondValue: Double? =
/** /**
* Formats the value of the stat to be suitable for display * Formats the value of the stat to be suitable for display
*/ */
fun format(context: Context): TextFormat { fun format(): TextFormat {
return this.stat.format(this.value, this.secondValue, this.currency, context) return this.stat.format(this.value, this.secondValue, this.currency)
} }
} }

@ -950,7 +950,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
} }
value?.let { value?.let {
return stat.format(it, currency = currency, context = context) return stat.format(it, currency = currency)
} ?: run { } ?: run {
return TextFormat(NULL_TEXT) return TextFormat(NULL_TEXT)
} }

@ -120,15 +120,15 @@ open class SessionSet() : RealmObject(), Timed, Filterable {
override fun formattedValue(stat: Stat, context: Context) : TextFormat { override fun formattedValue(stat: Stat, context: Context) : TextFormat {
return when (stat) { return when (stat) {
Stat.NET_RESULT, Stat.AVERAGE -> stat.format(this.ratedNet, currency = null, context = context) Stat.NET_RESULT, Stat.AVERAGE -> stat.format(this.ratedNet, currency = null)
Stat.DURATION, Stat.AVERAGE_DURATION -> stat.format(this.netDuration.toDouble(), currency = null, context = context) Stat.DURATION, Stat.AVERAGE_DURATION -> stat.format(this.netDuration.toDouble(), currency = null)
Stat.HOURLY_RATE -> stat.format(this.hourlyRate, currency = null, context = context) Stat.HOURLY_RATE -> stat.format(this.hourlyRate, currency = null)
Stat.HANDS_PLAYED -> stat.format(this.estimatedHands, currency = null, context = context) Stat.HANDS_PLAYED -> stat.format(this.estimatedHands, currency = null)
Stat.HOURLY_RATE_BB -> stat.format(this.bbHourlyRate, currency = null, context = context) Stat.HOURLY_RATE_BB -> stat.format(this.bbHourlyRate, currency = null)
Stat.NET_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION_BB_PER_100_HANDS -> { Stat.NET_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION_BB_PER_100_HANDS -> {
val netBBPer100Hands = Stat.netBBPer100Hands(this.bbNet, this.estimatedHands) val netBBPer100Hands = Stat.netBBPer100Hands(this.bbNet, this.estimatedHands)
if (netBBPer100Hands != null) { if (netBBPer100Hands != null) {
return stat.format(this.estimatedHands, currency = null, context = context) return stat.format(this.estimatedHands, currency = null)
} else { } else {
return TextFormat(NULL_TEXT) return TextFormat(NULL_TEXT)
} }

@ -84,7 +84,7 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
val formattedDate = it.entryTitle val formattedDate = it.entryTitle
val entryValue = it.formattedValue(this.stat, requireContext()) val entryValue = it.formattedValue(this.stat, requireContext())
val totalStatValue = this.stat.format(entry.y.toDouble(), currency = null, context = requireContext()) val totalStatValue = this.stat.format(entry.y.toDouble(), currency = null)
this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue) this.legendView.setItemData(this.stat, formattedDate, entryValue, totalStatValue)
} }
@ -108,7 +108,8 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
GraphType.BAR -> BarChart(context) GraphType.BAR -> BarChart(context)
} }
this.chartView.setStyle(false, requireContext()) val axisFormatting = aggregationType.axisFormatting
this.chartView.setStyle(false, axisFormatting, requireContext())
this.chartContainer.addView(this.chartView) this.chartContainer.addView(this.chartView)
} }
@ -118,7 +119,10 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
private fun loadGraph() { private fun loadGraph() {
val graphEntries = when (aggregationType) { val graphEntries = when (aggregationType) {
AggregationType.SESSION, AggregationType.DURATION -> selectedReport.results.firstOrNull()?.defaultStatEntries(stat) AggregationType.SESSION -> selectedReport.results.firstOrNull()?.defaultStatEntries(stat)
AggregationType.DURATION -> {
selectedReport.results.firstOrNull()?.durationEntries(stat)
}
AggregationType.MONTH, AggregationType.YEAR -> { AggregationType.MONTH, AggregationType.YEAR -> {
when (this.stat) { when (this.stat) {
Stat.NUMBER_OF_GAMES, Stat.NUMBER_OF_SETS -> selectedReport.barEntries(this.stat) Stat.NUMBER_OF_GAMES, Stat.NUMBER_OF_SETS -> selectedReport.barEntries(this.stat)
@ -153,7 +157,8 @@ class GraphFragment : PokerAnalyticsFragment(), OnChartValueSelectedListener, Co
} }
} }
this.chartView.setStyle(false, requireContext()) val axisFormatting = aggregationType.axisFormatting
this.chartView.setStyle(false, axisFormatting, requireContext())
this.chartView.setOnChartValueSelectedListener(this) this.chartView.setOnChartValueSelectedListener(this)
this.chartView.highlightValue((entries.size - 1).toFloat(), 0) this.chartView.highlightValue((entries.size - 1).toFloat(), 0)

@ -77,7 +77,7 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc
if (row is StatRow) { if (row is StatRow) {
context?.let { context -> context?.let { context ->
row.computedStat?.let { row.computedStat?.let {
dc.textFormat = it.format(context) dc.textFormat = it.format()
} }
} }
} }
@ -87,7 +87,7 @@ class StatsFragment : SessionObserverFragment(), StaticRowRepresentableDataSourc
override fun statFormatForRow(row: RowRepresentable): TextFormat { override fun statFormatForRow(row: RowRepresentable): TextFormat {
if (row is StatRow) { if (row is StatRow) {
context?.let { context -> context?.let { context ->
row.computedStat?.let { return it.format(context) } row.computedStat?.let { return it.format() }
} }
} }
return TextFormat(NULL_TEXT) return TextFormat(NULL_TEXT)

@ -8,9 +8,16 @@ import com.github.mikephil.charting.components.XAxis
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.extensions.px import net.pokeranalytics.android.ui.extensions.px
enum class AxisFormatting {
DEFAULT,
X_DURATION,
Y_DURATION,
}
fun BarLineChartBase<*>.setStyle(small: Boolean, axisFormatting: AxisFormatting = AxisFormatting.DEFAULT, context: Context) {
fun BarLineChartBase<*>.setStyle(small: Boolean, context: Context) { this.legend.isEnabled = false
this.description.isEnabled = false
// X Axis // X Axis
this.xAxis.axisLineColor = ContextCompat.getColor(context, R.color.chart_default) this.xAxis.axisLineColor = ContextCompat.getColor(context, R.color.chart_default)
@ -42,20 +49,22 @@ fun BarLineChartBase<*>.setStyle(small: Boolean, context: Context) {
this.axisLeft.typeface = ResourcesCompat.getFont(context, R.font.roboto_medium) this.axisLeft.typeface = ResourcesCompat.getFont(context, R.font.roboto_medium)
this.axisLeft.labelCount = if (small) 1 else 7 // @todo not great if interval is [0..2] for number of records as we get decimals this.axisLeft.labelCount = if (small) 1 else 7 // @todo not great if interval is [0..2] for number of records as we get decimals
this.axisLeft.textSize = 12f this.axisLeft.textSize = 12f
this.axisLeft.valueFormatter = LargeNumberFormatter()
this.axisRight.isEnabled = false this.axisRight.isEnabled = false
this.legend.isEnabled = false
this.description.isEnabled = false
this.data?.isHighlightEnabled = !small this.data?.isHighlightEnabled = !small
// @todo when (axisFormatting) {
// if timeYAxis { AxisFormatting.DEFAULT -> {
// this.axisLeft.valueFormatter = HourValueFormatter() this.axisLeft.valueFormatter = LargeNumberFormatter()
// } else { }
// this.axisLeft.valueFormatter = LargeNumberFormatter() AxisFormatting.X_DURATION -> {
// } this.xAxis.valueFormatter = HourFormatter()
// }
AxisFormatting.Y_DURATION -> {
this.axisLeft.valueFormatter = HourFormatter()
}
}
} }

@ -0,0 +1,32 @@
package net.pokeranalytics.android.ui.graph
import com.github.mikephil.charting.components.AxisBase
import com.github.mikephil.charting.formatter.ValueFormatter
import net.pokeranalytics.android.util.extensions.kmbFormatted
class LargeNumberFormatter : ValueFormatter() {
override fun getFormattedValue(value: Float): String {
return value.kmbFormatted
}
override fun getAxisLabel(value: Float, axis: AxisBase?): String {
val test = value.kmbFormatted
return test
}
}
class HourFormatter : ValueFormatter() {
override fun getFormattedValue(value: Float): String {
return value.kmbFormatted + "H"
}
override fun getAxisLabel(value: Float, axis: AxisBase?): String {
val test = value.kmbFormatted + "H"
return test
}
}

@ -22,6 +22,7 @@ import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.Transaction import net.pokeranalytics.android.model.realm.Transaction
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter
import net.pokeranalytics.android.ui.extensions.setTextFormat import net.pokeranalytics.android.ui.extensions.setTextFormat
import net.pokeranalytics.android.ui.graph.AxisFormatting
import net.pokeranalytics.android.ui.graph.PALineDataSet import net.pokeranalytics.android.ui.graph.PALineDataSet
import net.pokeranalytics.android.ui.graph.setStyle import net.pokeranalytics.android.ui.graph.setStyle
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable
@ -135,7 +136,7 @@ enum class RowViewType(private var layoutRes: Int) {
// Value // Value
itemView.findViewById<AppCompatTextView?>(R.id.value)?.let { itemView.findViewById<AppCompatTextView?>(R.id.value)?.let {
if (row.computedStat != null) { if (row.computedStat != null) {
val format = row.computedStat!!.format(itemView.context) val format = row.computedStat!!.format()
it.setTextFormat(format, itemView.context) it.setTextFormat(format, itemView.context)
} else if (row.value != null) { } else if (row.value != null) {
it.text = row.value it.text = row.value
@ -278,7 +279,7 @@ enum class RowViewType(private var layoutRes: Int) {
itemView.findViewById<AppCompatTextView?>(R.id.stat1Value)?.let { view -> itemView.findViewById<AppCompatTextView?>(R.id.stat1Value)?.let { view ->
view.text = "" view.text = ""
row.computedStat1?.format(view.context)?.let { row.computedStat1?.format()?.let {
view.setTextFormat(it, itemView.context) view.setTextFormat(it, itemView.context)
} }
} }
@ -293,7 +294,7 @@ enum class RowViewType(private var layoutRes: Int) {
itemView.findViewById<AppCompatTextView?>(R.id.stat2Value)?.let { view -> itemView.findViewById<AppCompatTextView?>(R.id.stat2Value)?.let { view ->
view.text = "" view.text = ""
row.computedStat2?.format(view.context)?.let { row.computedStat2?.format()?.let {
view.setTextFormat(it, itemView.context) view.setTextFormat(it, itemView.context)
} }
} }
@ -349,7 +350,7 @@ enum class RowViewType(private var layoutRes: Int) {
it.addView(chartView) it.addView(chartView)
} }
chartView.setStyle(true, context) chartView.setStyle(true, AxisFormatting.DEFAULT, context)
chartView.setTouchEnabled(false) chartView.setTouchEnabled(false)
chartView.highlightValue((entries.size - 1).toFloat(), 0) chartView.highlightValue((entries.size - 1).toFloat(), 0)
} }

@ -149,7 +149,7 @@ class SessionRowView : FrameLayout {
rowHistorySession.infoTitle.isVisible = false rowHistorySession.infoTitle.isVisible = false
val result = session.result?.net ?: 0.0 val result = session.result?.net ?: 0.0
val formattedStat = ComputedStat(Stat.NET_RESULT, result, currency = session.currency).format(context) val formattedStat = ComputedStat(Stat.NET_RESULT, result, currency = session.currency).format()
rowHistorySession.gameResult.setTextFormat(formattedStat, context) rowHistorySession.gameResult.setTextFormat(formattedStat, context)
} }

@ -63,7 +63,7 @@ class TransactionRowView : FrameLayout {
rowTransaction.transactionSubtitle.text = subtitle rowTransaction.transactionSubtitle.text = subtitle
// Amount // Amount
val formattedStat = ComputedStat(Stat.NET_RESULT, transaction.amount).format(context) val formattedStat = ComputedStat(Stat.NET_RESULT, transaction.amount).format()
rowTransaction.transactionAmount.setTextFormat(formattedStat, context) rowTransaction.transactionAmount.setTextFormat(formattedStat, context)
} }

@ -2,11 +2,31 @@ package net.pokeranalytics.android.util.extensions
import android.content.Context import android.content.Context
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.util.UserDefaults import java.lang.Math.abs
import java.text.DecimalFormat import java.text.DecimalFormat
import java.text.NumberFormat import java.text.NumberFormat
import java.util.* import java.util.*
val Number.kmbFormatted: String
get() {
var thousandsExponent = 0
var v = this.toDouble()
while (abs(v) >= 10000 && thousandsExponent < 3) {
v /= 1000
thousandsExponent++
}
val unit = when(thousandsExponent) {
0 -> ""
1 -> "K"
2 -> "M"
3 -> "B"
else -> "B+" // shouldn't happen
}
val formatter = NumberFormat.getInstance()
return formatter.format(v) + unit
}
// Double // Double

@ -0,0 +1,34 @@
package net.pokeranalytics.android
import net.pokeranalytics.android.util.extensions.kmbFormatted
import org.junit.Assert
import org.junit.Test
class BasicUnitTest : RealmUnitTest() {
@Test
fun testStats() {
Assert.assertEquals(0, 0)
}
@Test
fun testFormatting() {
val n1 = 100.0
val n2 = 1000.0
val n3 = n2 * n2 // 1M
val n4 = n3 * n2 // 1B
val s1 = n1.kmbFormatted
val s2 = n2.kmbFormatted
val s3 = n3.kmbFormatted
val s4 = n4.kmbFormatted
Assert.assertEquals("100", s1)
Assert.assertEquals("1K", s2)
Assert.assertEquals("1M", s3)
Assert.assertEquals("1B", s4)
}
}

@ -1,59 +0,0 @@
package net.pokeranalytics.android
import org.junit.Assert
import org.junit.Test
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest : RealmUnitTest() {
@Test
fun testStats() {
Assert.assertEquals(0, 0)
}
// class Grade(someValue: Double) : SessionInterface {
//
// override var bbPer100Hands: Double = 0.0
// override var ratedNet: Double = 0.0
// override var value: Double = someValue
//
// override var sessionSet: SessionSet? = SessionSet()
// override var estimatedHands: Double = 0.0
// override var bbNet: Double = 0.0
// override var bigBlindSessionCount: Int = 0 // 0 or 1
// override var ratedBuyin: Double = 0.0
//
// }
//
// @Test
// fun testStats() {
//
// val grades: List<Grade> = listOf(Grade(10.0), Grade(20.0))
// val group = ComputableGroup(name = "test", computables = grades)
//
// val results: ComputedResults = Calculator.compute(group, Calculator.Options())
//
// val sum = results.computedStat(Stat.NET_RESULT)
// if (sum != null) {
// assert(sum.value == 0.0) { "sum is ${sum.value}" }
// } else {
// fail("No Net result stat")
// }
//
// val average = results.computedStat(Stat.AVERAGE)
// if (average != null) {
// assert(average.value == 0.0) { "average is ${average.value}" }
// } else {
// fail("No AVERAGE stat")
// }
//
// }
}
Loading…
Cancel
Save