Adds PokerAgent import

od
Laurent 6 years ago
parent e45121e575
commit 1a6e39cef1
  1. 1
      app/src/main/AndroidManifest.xml
  2. 1
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  3. 11
      app/src/main/java/net/pokeranalytics/android/model/Limit.kt
  4. 15
      app/src/main/java/net/pokeranalytics/android/model/realm/Result.kt
  5. 2
      app/src/main/java/net/pokeranalytics/android/ui/activity/ImportActivity.kt
  6. 27
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FeedFragment.kt
  7. 3
      app/src/main/java/net/pokeranalytics/android/util/csv/CSVDescriptor.kt
  8. 12
      app/src/main/java/net/pokeranalytics/android/util/csv/ProductCSVDescriptors.kt
  9. 53
      app/src/main/java/net/pokeranalytics/android/util/csv/SessionCSVDescriptor.kt
  10. 10
      app/src/main/java/net/pokeranalytics/android/util/csv/SessionField.kt
  11. 4
      app/src/main/java/net/pokeranalytics/android/util/extensions/DateExtension.kt

@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.android.vending.BILLING" /> <uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application <application
android:name=".PokerAnalyticsApplication" android:name=".PokerAnalyticsApplication"

@ -64,6 +64,7 @@ class PokerAnalyticsApplication : Application() {
} }
Patcher.patchAll(this.applicationContext) Patcher.patchAll(this.applicationContext)
} }
/** /**

@ -38,13 +38,12 @@ enum class Limit : RowRepresentable {
val longName: String val longName: String
get() { get() {
val limit = "Limit"
return when (this) { return when (this) {
NO -> "No $limit" NO -> "No Limit"
POT -> "Pot $limit" POT -> "Pot Limit"
FIXED -> "Fixed $limit" FIXED -> "Limit"
MIXED -> "Mixed $limit" MIXED -> "Mixed Limit"
SPREAD -> "Spread $limit" SPREAD -> "Spread Limit"
} }
} }

@ -6,7 +6,6 @@ import io.realm.RealmResults
import io.realm.annotations.Ignore import io.realm.annotations.Ignore
import io.realm.annotations.LinkingObjects import io.realm.annotations.LinkingObjects
import io.realm.annotations.RealmClass import io.realm.annotations.RealmClass
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.filter.Filterable import net.pokeranalytics.android.model.filter.Filterable
import net.pokeranalytics.android.model.filter.QueryCondition import net.pokeranalytics.android.model.filter.QueryCondition
@ -51,13 +50,13 @@ open class Result : RealmObject(), Filterable {
var netResult: Double? = null var netResult: Double? = null
set(value) { set(value) {
this.session?.bankroll?.let { bankroll -> // this.session?.bankroll?.let { bankroll ->
if (bankroll.live) { // if (bankroll.live) {
throw PAIllegalStateException("Can't set net result on a live bankroll") // throw PAIllegalStateException("Can't set net result on a live bankroll")
} // }
} ?: run { // } ?: run {
throw PAIllegalStateException("Session doesn't have any bankroll") // throw PAIllegalStateException("Session doesn't have any bankroll")
} // }
field = value field = value
this.computeNet(false) this.computeNet(false)

@ -47,6 +47,8 @@ class ImportActivity : PokerAnalyticsActivity() {
intent?.data?.let { intent?.data?.let {
this.fileURI = it this.fileURI = it
} ?: run {
this.fileURI = intent.getParcelableExtra(ImportActivity.IntentKey.URI.keyName) as Uri
} }
setContentView(R.layout.activity_import) setContentView(R.layout.activity_import)

@ -132,6 +132,33 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
initUI() initUI()
initData() initData()
// if (ContextCompat.checkSelfPermission(requireActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
// != PackageManager.PERMISSION_GRANTED) {
//
// if (ActivityCompat.shouldShowRequestPermissionRationale(requireActivity(),
// Manifest.permission.READ_EXTERNAL_STORAGE)) {
// // Show an explanation to the user *asynchronously* -- don't block
// // this thread waiting for the user's response! After the user
// // sees the explanation, try again to request the permission.
// } else {
// // No explanation needed, we can request the permission.
// ActivityCompat.requestPermissions(requireActivity(),
// arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
// 12)
//
// // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
// // app-defined int constant. The callback method gets the
// // result of the request.
// }
//
// } else {
//
// val uri = Uri.fromFile(File("sdcard/Download/Results_0802.csv"))
// ImportActivity.newInstanceForResult(requireActivity(), uri)
//
// }
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

@ -103,7 +103,8 @@ abstract class CSVDescriptor(var source: DataSource, vararg elements: CSVField)
listOf(ProductCSVDescriptors.pokerIncomeCash, listOf(ProductCSVDescriptors.pokerIncomeCash,
ProductCSVDescriptors.pokerBankrollTracker, ProductCSVDescriptors.pokerBankrollTracker,
ProductCSVDescriptors.runGoodCashGames, ProductCSVDescriptors.runGoodCashGames,
ProductCSVDescriptors.runGoodTournaments) ProductCSVDescriptors.runGoodTournaments,
ProductCSVDescriptors.pokerAgent)
} }
/** /**

@ -4,6 +4,18 @@ class ProductCSVDescriptors {
companion object { companion object {
val pokerAgent: CSVDescriptor = SessionCSVDescriptor(
DataSource.POKER_INCOME,
false,
SessionField.Start("Date ", dateFormat = "MM-dd-yyyy", defaultTimeFormat = "20:00"),
SessionField.Location("Location"),
SessionField.SmallBlind("SB"),
SessionField.BigBlind("BB"),
SessionField.NetResult("P/L"),
SessionField.Duration("Hrs"),
SessionField.LimitAndGame("Type")
)
val pokerIncomeCash: CSVDescriptor = SessionCSVDescriptor( val pokerIncomeCash: CSVDescriptor = SessionCSVDescriptor(
DataSource.POKER_INCOME, DataSource.POKER_INCOME,
false, false,

@ -1,6 +1,7 @@
package net.pokeranalytics.android.util.csv package net.pokeranalytics.android.util.csv
import io.realm.Realm import io.realm.Realm
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.Limit import net.pokeranalytics.android.model.Limit
import net.pokeranalytics.android.model.TableSize import net.pokeranalytics.android.model.TableSize
import net.pokeranalytics.android.model.TournamentType import net.pokeranalytics.android.model.TournamentType
@ -144,7 +145,11 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
val value = record.get(index) val value = record.get(index)
when (field) { when (field) {
is SessionField.Start -> { is SessionField.Start -> {
startDate = field.parse(value) startDate = field.parse(value)
field.defaultTimeFormat?.let {
startDate?.setHourMinutes(it)
}
} }
is SessionField.End -> { is SessionField.End -> {
endDate = field.parse(value) endDate = field.parse(value)
@ -155,6 +160,19 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
is SessionField.EndTime -> { is SessionField.EndTime -> {
endDate?.setHourMinutes(value) endDate?.setHourMinutes(value)
} }
is SessionField.Duration -> {
val hoursDuration = field.parse(value)
if (startDate != null && hoursDuration != null) {
val minutes = (hoursDuration * 60.0).toInt()
val calendar = Calendar.getInstance()
calendar.time = startDate
calendar.add(Calendar.MINUTE, minutes)
endDate = calendar.time
} else {
throw PAIllegalStateException("start date ($startDate) + hoursDuration ($hoursDuration) required")
}
}
is SessionField.Buyin -> { is SessionField.Buyin -> {
val buyin = field.parse(value) val buyin = field.parse(value)
session.result?.buyin = buyin session.result?.buyin = buyin
@ -164,6 +182,7 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
} }
} }
is SessionField.CashedOut -> session.result?.cashout = field.parse(value) is SessionField.CashedOut -> session.result?.cashout = field.parse(value)
is SessionField.NetResult -> session.result?.netResult = field.parse(value)
is SessionField.SessionType -> { is SessionField.SessionType -> {
Session.Type.getValueFromString(value)?.let { type -> Session.Type.getValueFromString(value)?.let { type ->
session.type = type.ordinal session.type = type.ordinal
@ -177,6 +196,21 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
session.breakDuration = it.toLong() * 60 * 1000 session.breakDuration = it.toLong() * 60 * 1000
} }
} }
is SessionField.LimitAndGame -> {
if (value.isNotEmpty()) {
var limitAndGame = value
for (someLimit in Limit.values()) {
if (value.startsWith(someLimit.longName)) {
session.limit = someLimit.ordinal
limitAndGame = limitAndGame.removePrefix(someLimit.longName)
break
}
}
session.game = realm.getOrCreate(limitAndGame.trim())
} else {
}
}
is SessionField.Game -> { is SessionField.Game -> {
if (value.isNotEmpty()) { if (value.isNotEmpty()) {
session.game = realm.getOrCreate(value) session.game = realm.getOrCreate(value)
@ -184,8 +218,9 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
} }
} }
is SessionField.Location -> { is SessionField.Location -> {
if (value.isNotEmpty()) { val trimmedValue = value.trim()
session.location = realm.getOrCreate(value) if (trimmedValue.isNotEmpty()) {
session.location = realm.getOrCreate(trimmedValue)
} else { } else {
} }
} }
@ -197,8 +232,18 @@ class SessionCSVDescriptor(source: DataSource, private var isTournament: Boolean
session.cgSmallBlind = blinds?.first session.cgSmallBlind = blinds?.first
session.cgBigBlind = blinds?.second session.cgBigBlind = blinds?.second
} }
is SessionField.SmallBlind -> session.cgSmallBlind = field.parse(value) is SessionField.SmallBlind -> {
is SessionField.BigBlind -> session.cgBigBlind = field.parse(value) val sb = field.parse(value)
if (sb != null && sb > 0.0) {
session.cgSmallBlind = sb
} else {}
}
is SessionField.BigBlind -> {
val bb = field.parse(value)
if (bb != null && bb > 0.0) {
session.cgBigBlind = bb
} else {}
}
is SessionField.TableSize -> session.tableSize = TableSize.valueForLabel(value) is SessionField.TableSize -> session.tableSize = TableSize.valueForLabel(value)
is SessionField.TournamentPosition -> session.result?.tournamentFinalPosition = is SessionField.TournamentPosition -> session.result?.tournamentFinalPosition =
field.parse(value)?.toInt() field.parse(value)?.toInt()

@ -19,7 +19,8 @@ sealed class SessionField {
data class Start( data class Start(
override var header: String, override var header: String,
override var callback: ((String) -> Date?)? = null, override var callback: ((String) -> Date?)? = null,
override val dateFormat: String? = null override val dateFormat: String? = null,
val defaultTimeFormat: String? = null
) : DateCSVField ) : DateCSVField
data class StartTime( data class StartTime(
@ -40,6 +41,12 @@ sealed class SessionField {
override val dateFormat: String? = null override val dateFormat: String? = null
) : DateCSVField ) : DateCSVField
data class Duration(
override var header: String,
override var callback: ((String) -> Double?)? = null,
override val numberFormat: String? = null
) : NumberCSVField
data class Buyin( data class Buyin(
override var header: String, override var header: String,
override var callback: ((String) -> Double?)? = null, override var callback: ((String) -> Double?)? = null,
@ -110,6 +117,7 @@ sealed class SessionField {
BlindCSVField BlindCSVField
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 Location(override var header: String) : CSVField data class Location(override var header: String) : CSVField
data class LocationType(override var header: String) : CSVField data class LocationType(override var header: String) : CSVField
data class Bankroll(override var header: String) : CSVField data class Bankroll(override var header: String) : CSVField

@ -180,7 +180,9 @@ fun Date.getNextMinuteInMilliseconds(): Long {
fun Date.setHourMinutes(value: String, dateFormat: String = "HH:mm") { fun Date.setHourMinutes(value: String, dateFormat: String = "HH:mm") {
val calendar1 = Calendar.getInstance() val calendar1 = Calendar.getInstance()
calendar1.time = this calendar1.time = this
val calendar2 = Calendar.getInstance().apply { time = SimpleDateFormat(dateFormat, Locale.getDefault()).parse(value) } val calendar2 = Calendar.getInstance().apply {
time = SimpleDateFormat(dateFormat, Locale.getDefault()).parse(value)
}
calendar1.set(Calendar.HOUR_OF_DAY, calendar2.get(Calendar.HOUR_OF_DAY)) calendar1.set(Calendar.HOUR_OF_DAY, calendar2.get(Calendar.HOUR_OF_DAY))
calendar1.set(Calendar.MINUTE, calendar2.get(Calendar.MINUTE)) calendar1.set(Calendar.MINUTE, calendar2.get(Calendar.MINUTE))
calendar1.set(Calendar.SECOND, 0) calendar1.set(Calendar.SECOND, 0)

Loading…
Cancel
Save