Integrating poker analytics iOS CSV import

od
Laurent 6 years ago
parent b969039597
commit 320f56c652
  1. 12
      app/src/main/java/net/pokeranalytics/android/util/csv/CSVDescriptor.kt
  2. 19
      app/src/main/java/net/pokeranalytics/android/util/csv/CSVField.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/util/csv/CSVImporter.kt
  4. 125
      app/src/main/java/net/pokeranalytics/android/util/csv/ProductCSVDescriptors.kt
  5. 12
      app/src/main/java/net/pokeranalytics/android/util/csv/SessionField.kt

@ -97,18 +97,6 @@ abstract class CSVDescriptor(var source: DataSource, vararg elements: CSVField)
} }
} }
companion object {
/**
* The list of all managed CSVDescriptors
*/
val all: List<CSVDescriptor> =
listOf(ProductCSVDescriptors.pokerIncomeCash,
ProductCSVDescriptors.pokerBankrollTracker,
ProductCSVDescriptors.runGoodCashGames,
ProductCSVDescriptors.runGoodTournaments,
ProductCSVDescriptors.pokerAgent)
}
/** /**
* Method called when iterating on a CSVRecord * Method called when iterating on a CSVRecord
*/ */

@ -14,6 +14,25 @@ interface NumberCSVField: TypedCSVField<Double> {
val numberFormat: String? val numberFormat: String?
companion object {
fun defaultParse(value: String) : Double? {
if (value.isEmpty()) {
return null
}
val formatter = NumberFormat.getInstance()
return try {
formatter.parse(value).toDouble()
} catch (e: ParseException) {
Timber.d("Field > Unparseable number: $value")
null
}
}
}
override fun parse(value: String) : Double? { override fun parse(value: String) : Double? {
if (value.isEmpty()) { if (value.isEmpty()) {

@ -176,7 +176,7 @@ open class CSVImporter(istream: InputStream) {
*/ */
private fun findDescriptor(record: CSVRecord): CSVDescriptor? { private fun findDescriptor(record: CSVRecord): CSVDescriptor? {
CSVDescriptor.all.forEach { descriptor -> ProductCSVDescriptors.all.forEach { descriptor ->
if (descriptor.matches(record)) { if (descriptor.matches(record)) {
this.currentDescriptor = descriptor this.currentDescriptor = descriptor
Timber.d("Identified source: ${descriptor.source}") Timber.d("Identified source: ${descriptor.source}")

@ -4,7 +4,22 @@ class ProductCSVDescriptors {
companion object { companion object {
val pokerAgent: CSVDescriptor = SessionCSVDescriptor( /**
* The list of all managed CSVDescriptors
*/
val all: List<CSVDescriptor> =
listOf(
pokerAgent,
pokerIncomeCash,
pokerBankrollTracker,
runGoodCashGames,
runGoodTournaments,
iOSPokerAnalytics
)
private val pokerAgent: CSVDescriptor
get() {
return SessionCSVDescriptor(
DataSource.POKER_AGENT, DataSource.POKER_AGENT,
false, false,
SessionField.Start("Date ", dateFormat = "MM-dd-yyyy"), SessionField.Start("Date ", dateFormat = "MM-dd-yyyy"),
@ -15,8 +30,11 @@ class ProductCSVDescriptors {
SessionField.Duration("Hrs", randomTime = true), SessionField.Duration("Hrs", randomTime = true),
SessionField.LimitAndGame("Type") SessionField.LimitAndGame("Type")
) )
}
val pokerIncomeCash: CSVDescriptor = SessionCSVDescriptor( private val pokerIncomeCash: CSVDescriptor
get() {
return SessionCSVDescriptor(
DataSource.POKER_INCOME, DataSource.POKER_INCOME,
false, false,
SessionField.Start("Start Time"), SessionField.Start("Start Time"),
@ -33,8 +51,11 @@ class ProductCSVDescriptors {
SessionField.Tips("Tips"), SessionField.Tips("Tips"),
SessionField.Blind("Stake") SessionField.Blind("Stake")
) )
}
val pokerBankrollTracker: CSVDescriptor = SessionCSVDescriptor( private val pokerBankrollTracker: CSVDescriptor
get() {
return SessionCSVDescriptor(
DataSource.POKER_BANKROLL_TRACKER, DataSource.POKER_BANKROLL_TRACKER,
true, true,
SessionField.Start("starttime", dateFormat = "MM/dd/yy HH:mm"), SessionField.Start("starttime", dateFormat = "MM/dd/yy HH:mm"),
@ -62,8 +83,11 @@ class ProductCSVDescriptors {
SessionField.CurrencyRate("exchangerate"), SessionField.CurrencyRate("exchangerate"),
SessionField.TableSize("tablesize") SessionField.TableSize("tablesize")
) )
}
val runGoodTournaments: CSVDescriptor = SessionCSVDescriptor( private val runGoodTournaments: CSVDescriptor
get() {
return SessionCSVDescriptor(
DataSource.RUNGOOD, DataSource.RUNGOOD,
true, true,
SessionField.Start("Start Date", dateFormat = "dd/MM/yyyy"), SessionField.Start("Start Date", dateFormat = "dd/MM/yyyy"),
@ -88,8 +112,13 @@ class ProductCSVDescriptors {
SessionField.TournamentType("Single-Table/Multi-Table") SessionField.TournamentType("Single-Table/Multi-Table")
) )
}
private val runGoodCashGames: CSVDescriptor
get() {
val runGoodCashGames: CSVDescriptor = SessionCSVDescriptor( return SessionCSVDescriptor(
DataSource.RUNGOOD, DataSource.RUNGOOD,
false, false,
SessionField.Start("Start Date", dateFormat = "dd/MM/yyyy"), SessionField.Start("Start Date", dateFormat = "dd/MM/yyyy"),
@ -113,52 +142,66 @@ class ProductCSVDescriptors {
value.drop(1) value.drop(1)
val blinds = value.split("/") val blinds = value.split("/")
if (blinds.size == 2) { if (blinds.size == 2) {
return@Blind Pair(blinds.first().toDouble(), blinds.last().toDouble()) return@Blind Pair(
blinds.first().toDouble(),
blinds.last().toDouble()
)
} else { } else {
return@Blind null return@Blind null
} }
}) })
) )
}
/* // val pokerAnalyticsiOS: CSVDescriptor
headers.append("\"Start Date\"") // get() {
headers.append("\"End Date\"") //
headers.append("\"Break\"") // return SessionCSVDescriptor(
headers.append("\"Type\"") // DataSource.POKER_ANALYTICS,
headers.append("\"Live\"") // null,
headers.append("\"Tables\"") // SessionField.Start("Start Date"),
headers.append("\"Buyin\"") // SessionField.End("End Date"),
headers.append("\"Cashed Out\"") // SessionField.Break("Break"),
headers.append("\"Online Net\"") // SessionField.SessionType("Type"),
headers.append("\"Tips\"") // SessionField.Live("Live"),
headers.append("\"Limit\"") // SessionField.NumberOfTables("Tables"),
headers.append("\"Game\"") // SessionField.Buyin("Buy In"),
headers.append("\"Table Size\"") // SessionField.CashedOut("Cashed Out"),
headers.append("\"Location\"") // SessionField.NetResult("Online Net"),
headers.append("\"Bankroll\"") // SessionField.Tips("Tips"),
headers.append("\"Currency Code\"") // SessionField.LimitType("Limit"),
headers.append("\"Currency Rate\"") // SessionField.Game("Game"),
headers.append("\"Small Blind\"") // SessionField.TableSize("Table Size"),
headers.append("\"Big Blind\"") // SessionField.Location("Location"),
headers.append("\"Tournament Type\"") // SessionField.Bankroll("Bankroll"),
headers.append("\"Entry fee\"") // SessionField.CurrencyCode("Currency Code"),
headers.append("\"Number of players\"") // SessionField.CurrencyRate("Currency Rate"),
headers.append("\"Prize Pool\"") // SessionField.SmallBlind("Small Blind"),
headers.append("\"Position\"") // SessionField.BigBlind("Big Blind"),
headers.append("\"Comment\"") // SessionField.TournamentType("Tournament Type"),
// SessionField.TournamentEntryFee("Entry fee"),
// SessionField.TournamentNumberOfPlayers("Number of players"),
// SessionField.TournamentPosition("Position"),
// SessionField.Comment("Note")
// )
// }
*/
val pokerAnalyticsiOS: CSVDescriptor = SessionCSVDescriptor( private val pokerAnalyticsiOS: CSVDescriptor
get() {
return SessionCSVDescriptor(
DataSource.POKER_ANALYTICS, DataSource.POKER_ANALYTICS,
null, true,
SessionField.Start("Start Date"), SessionField.Start("Start Date", dateFormat = "MM/dd/yy HH:mm:ss"),
SessionField.End("End Date"), SessionField.End("End Date", dateFormat = "MM/dd/yy HH:mm:ss"),
SessionField.Break("Break"), SessionField.Break("Break", callback = { string ->
val number = NumberCSVField.defaultParse(string)
return@Break number?.times(1000.0)
}),
SessionField.SessionType("Type"), SessionField.SessionType("Type"),
SessionField.Live("Live"), SessionField.Live("Live"),
SessionField.NumberOfTables("Tables"), SessionField.NumberOfTables("Tables"),
SessionField.Buyin("Buy In"), SessionField.Buyin("Buyin"),
SessionField.CashedOut("Cashed Out"), SessionField.CashedOut("Cashed Out"),
SessionField.NetResult("Online Net"), SessionField.NetResult("Online Net"),
SessionField.Tips("Tips"), SessionField.Tips("Tips"),
@ -174,9 +217,11 @@ class ProductCSVDescriptors {
SessionField.TournamentType("Tournament Type"), SessionField.TournamentType("Tournament Type"),
SessionField.TournamentEntryFee("Entry fee"), SessionField.TournamentEntryFee("Entry fee"),
SessionField.TournamentNumberOfPlayers("Number of players"), SessionField.TournamentNumberOfPlayers("Number of players"),
SessionField.TournamentPrizePool("Prize Pool"),
SessionField.TournamentPosition("Position"), SessionField.TournamentPosition("Position"),
SessionField.Comment("Note") SessionField.Comment("Comment")
) )
}
} }

@ -121,6 +121,11 @@ sealed class SessionField {
override var callback: ((String) -> Boolean?)? = null override var callback: ((String) -> Boolean?)? = null
) : BooleanCSVField ) : BooleanCSVField
data class NumberOfTables(
override var header: String,
override var callback: ((String) -> Int?)? = null
) : IntCSVField
data class Game(override var header: String) : CSVField data class Game(override var header: String) : CSVField
data class LimitAndGame(override var header: String) : CSVField data class LimitAndGame(override var header: String) : CSVField
data class Location(override var header: String) : CSVField data class Location(override var header: String) : CSVField
@ -158,9 +163,10 @@ sealed class SessionField {
override val numberFormat: String? = null override val numberFormat: String? = null
) : NumberCSVField ) : NumberCSVField
data class NumberOfTables( data class TournamentPrizePool(
override var header: String, override var header: String,
override var callback: ((String) -> Int?)? = null override var callback: ((String) -> Double?)? = null,
) : IntCSVField override val numberFormat: String? = null
) : NumberCSVField
} }

Loading…
Cancel
Save