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
*/

@ -14,6 +14,25 @@ interface NumberCSVField: TypedCSVField<Double> {
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? {
if (value.isEmpty()) {

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

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

@ -121,6 +121,11 @@ sealed class SessionField {
override var callback: ((String) -> Boolean?)? = null
) : 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 LimitAndGame(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
) : NumberCSVField
data class NumberOfTables(
data class TournamentPrizePool(
override var header: String,
override var callback: ((String) -> Int?)? = null
) : IntCSVField
override var callback: ((String) -> Double?)? = null,
override val numberFormat: String? = null
) : NumberCSVField
}

Loading…
Cancel
Save