Added Poker Analytics CSV source

od
Laurent 6 years ago
parent 8d896f6b51
commit d7c33db581
  1. 1
      app/src/main/java/net/pokeranalytics/android/util/csv/CSVDescriptor.kt
  2. 24
      app/src/main/java/net/pokeranalytics/android/util/csv/CSVField.kt
  3. 57
      app/src/main/java/net/pokeranalytics/android/util/csv/ProductCSVDescriptors.kt
  4. 8
      app/src/main/java/net/pokeranalytics/android/util/csv/SessionCSVDescriptor.kt
  5. 17
      app/src/main/java/net/pokeranalytics/android/util/csv/SessionField.kt

@ -13,6 +13,7 @@ import timber.log.Timber
* The various sources of CSV
*/
enum class DataSource {
POKER_ANALYTICS,
POKER_INCOME,
POKER_BANKROLL_TRACKER,
RUNGOOD,

@ -31,6 +31,24 @@ interface NumberCSVField: TypedCSVField<Double> {
}
}
interface IntCSVField: TypedCSVField<Int> {
override fun parse(value: String) : Int? {
if (value.isEmpty()) {
return null
}
return try {
NumberFormat.getInstance().parse(value).toInt()
} catch (e: ParseException) {
Timber.d("Field ${header} > Unparseable number: $value")
null
}
}
}
interface DataCSVField<T> : TypedCSVField<T> {
override fun parse(value: String): T? {
@ -82,6 +100,12 @@ interface BlindCSVField : TypedCSVField<Pair<Double, Double>> {
}
interface BooleanCSVField : TypedCSVField<Boolean> {
override fun parse(value: String): Boolean? {
return value == "1"
}
}
interface TypedCSVField<T> : CSVField {
fun parse(value: String) : T?
var callback: ((String) -> T?)?

@ -120,6 +120,63 @@ class ProductCSVDescriptors {
})
)
/*
headers.append("\"Start Date\"")
headers.append("\"End Date\"")
headers.append("\"Break\"")
headers.append("\"Type\"")
headers.append("\"Live\"")
headers.append("\"Tables\"")
headers.append("\"Buyin\"")
headers.append("\"Cashed Out\"")
headers.append("\"Online Net\"")
headers.append("\"Tips\"")
headers.append("\"Limit\"")
headers.append("\"Game\"")
headers.append("\"Table Size\"")
headers.append("\"Location\"")
headers.append("\"Bankroll\"")
headers.append("\"Currency Code\"")
headers.append("\"Currency Rate\"")
headers.append("\"Small Blind\"")
headers.append("\"Big Blind\"")
headers.append("\"Tournament Type\"")
headers.append("\"Entry fee\"")
headers.append("\"Number of players\"")
headers.append("\"Prize Pool\"")
headers.append("\"Position\"")
headers.append("\"Comment\"")
*/
val pokerAnalyticsiOS: CSVDescriptor = SessionCSVDescriptor(
DataSource.POKER_ANALYTICS,
null,
SessionField.Start("Start Date"),
SessionField.End("End Date"),
SessionField.Break("Break"),
SessionField.SessionType("Type"),
SessionField.Live("Live"),
SessionField.NumberOfTables("Tables"),
SessionField.Buyin("Buy In"),
SessionField.CashedOut("Cashed Out"),
SessionField.NetResult("Online Net"),
SessionField.Tips("Tips"),
SessionField.LimitType("Limit"),
SessionField.Game("Game"),
SessionField.TableSize("Table Size"),
SessionField.Location("Location"),
SessionField.Bankroll("Bankroll"),
SessionField.CurrencyCode("Currency Code"),
SessionField.CurrencyRate("Currency Rate"),
SessionField.SmallBlind("Small Blind"),
SessionField.BigBlind("Big Blind"),
SessionField.TournamentType("Tournament Type"),
SessionField.TournamentEntryFee("Entry fee"),
SessionField.TournamentNumberOfPlayers("Number of players"),
SessionField.TournamentPosition("Position"),
SessionField.Comment("Note")
)
}

@ -20,7 +20,7 @@ import java.util.*
/**
* A SessionCSVDescriptor is a CSVDescriptor specialized in parsing Session objects
*/
class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean, vararg elements: CSVField) :
class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean?, vararg elements: CSVField) :
DataCSVDescriptor<Identifiable>(source, *elements) {
private enum class DataType {
@ -128,7 +128,8 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
private fun parseSession(realm: Realm, record: CSVRecord): Session? {
val session = Session.newInstance(realm, this.isTournament, managed = false)
val isTournament = isTournament ?: false
val session = Session.newInstance(realm, isTournament, managed = false)
var startDate: Date? = null
var endDate: Date? = null
@ -215,6 +216,8 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
session.type = type.ordinal
}
}
is SessionField.Live -> isLive = field.parse(value) ?: false
is SessionField.NumberOfTables -> session.numberOfTables = field.parse(value) ?: 1
is SessionField.Addon -> additionalBuyins += field.parse(value) ?: 0.0
is SessionField.Rebuy -> additionalBuyins += field.parse(value) ?: 0.0
is SessionField.Tips -> session.result?.tips = field.parse(value)
@ -284,6 +287,7 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
TournamentType.getValueForLabel(value)?.ordinal
is SessionField.TournamentNumberOfPlayers -> session.tournamentNumberOfPlayers =
field.parse(value)?.toInt()
is SessionField.TournamentEntryFee -> session.tournamentEntryFee = field.parse(value)
is SessionField.CurrencyCode -> currencyCode = value
is SessionField.CurrencyRate -> currencyRate = field.parse(value)
is SessionField.StackingIn -> {

@ -116,6 +116,11 @@ sealed class SessionField {
data class Blind(override var header: String, override var callback: ((String) -> Pair<Double, Double>?)? = null) :
BlindCSVField
data class Live(
override var header: String,
override var callback: ((String) -> Boolean?)? = null
) : BooleanCSVField
data class Game(override var header: String) : CSVField
data class LimitAndGame(override var header: String) : CSVField
data class Location(override var header: String) : CSVField
@ -146,4 +151,16 @@ sealed class SessionField {
override var callback: ((String) -> Double?)? = null,
override val numberFormat: String? = null
) : NumberCSVField
data class TournamentEntryFee(
override var header: String,
override var callback: ((String) -> Double?)? = null,
override val numberFormat: String? = null
) : NumberCSVField
data class NumberOfTables(
override var header: String,
override var callback: ((String) -> Int?)? = null
) : IntCSVField
}

Loading…
Cancel
Save