Poker Agent import improvement

od
Laurent 6 years ago
parent 6d3cb90755
commit 367dfa7ccb
  1. 4
      app/src/main/java/net/pokeranalytics/android/util/csv/ProductCSVDescriptors.kt
  2. 33
      app/src/main/java/net/pokeranalytics/android/util/csv/SessionCSVDescriptor.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/util/csv/SessionField.kt

@ -7,12 +7,12 @@ class ProductCSVDescriptors {
val pokerAgent: CSVDescriptor = SessionCSVDescriptor(
DataSource.POKER_AGENT,
false,
SessionField.Start("Date ", dateFormat = "MM-dd-yyyy", randomTime = true),
SessionField.Start("Date ", dateFormat = "MM-dd-yyyy"),
SessionField.Location("Location"),
SessionField.SmallBlind("SB"),
SessionField.BigBlind("BB"),
SessionField.NetResult("P/L"),
SessionField.Duration("Hrs"),
SessionField.Duration("Hrs", randomTime = true),
SessionField.LimitAndGame("Type")
)

@ -124,7 +124,7 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
private var sameDaySessionCount: Int = 0
private var currentday: String = ""
private var previousDuration: Double? = null
private var startInSeconds: Double = 20 * 3600.0
private fun parseSession(realm: Realm, record: CSVRecord): Session? {
@ -150,18 +150,13 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
when (field) {
is SessionField.Start -> {
startDate = field.parse(value)
if (field.randomTime) {
if (source == DataSource.POKER_AGENT) {
if (currentday == value) {
sameDaySessionCount++
} else {
sameDaySessionCount = 0
}
currentday = value
val hour = 20 - sameDaySessionCount * 8
val timeFormat = "$hour:00"
startDate?.setHourMinutes(timeFormat)
} else {}
}
is SessionField.End -> {
@ -174,18 +169,36 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
endDate?.setHourMinutes(value)
}
is SessionField.Duration -> {
val hoursDuration = field.parse(value)
previousDuration = hoursDuration
val hoursDuration = field.parse(value) ?: throw PAIllegalStateException("null duration")
if (startDate != null) {
if (field.randomTime) {
if (sameDaySessionCount == 0) {
startInSeconds = 20 * 3600.0
} else {
startInSeconds -= hoursDuration * 3600.0
}
if (startInSeconds < 0) {
throw PAIllegalStateException("negative start: $startDate, start = $startInSeconds, net = ${session.result?.netResult}")
}
val hour = (startInSeconds / 3600.0).toInt()
val minutes = ((startInSeconds - hour * 3600.0) / 60.0).toInt()
val formattedTime = "$hour:$minutes"
startDate?.setHourMinutes(formattedTime)
}
if (startDate != null && hoursDuration != null) {
val seconds = (hoursDuration * 3600.0).toInt()
val calendar = Calendar.getInstance()
calendar.time = startDate
calendar.add(Calendar.SECOND, seconds)
endDate = calendar.time
} else {
throw PAIllegalStateException("start date ($startDate) + hoursDuration ($hoursDuration) required")
}
}
is SessionField.Buyin -> {
val buyin = field.parse(value)

@ -19,8 +19,7 @@ sealed class SessionField {
data class Start(
override var header: String,
override var callback: ((String) -> Date?)? = null,
override val dateFormat: String? = null,
val randomTime: Boolean = false
override val dateFormat: String? = null
) : DateCSVField
data class StartTime(
@ -44,7 +43,8 @@ sealed class SessionField {
data class Duration(
override var header: String,
override var callback: ((String) -> Double?)? = null,
override val numberFormat: String? = null
override val numberFormat: String? = null,
val randomTime: Boolean = false
) : NumberCSVField
data class Buyin(

Loading…
Cancel
Save