Fixes import issues

blinds
Laurent 3 years ago
parent 0c7d99f288
commit 4a4943864b
  1. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 15
      app/src/main/java/net/pokeranalytics/android/model/utils/DataUtils.kt
  3. 21
      app/src/main/java/net/pokeranalytics/android/ui/fragment/ImportFragment.kt
  4. 1
      app/src/main/java/net/pokeranalytics/android/util/csv/CSVDescriptor.kt
  5. 20
      app/src/main/java/net/pokeranalytics/android/util/csv/CSVImporter.kt
  6. 10
      app/src/main/java/net/pokeranalytics/android/util/csv/PACSVDescriptor.kt
  7. 2
      app/src/main/java/net/pokeranalytics/android/util/csv/ProductCSVDescriptors.kt
  8. 1
      app/src/main/res/values-fr/strings.xml
  9. 1
      app/src/main/res/values/strings.xml

@ -789,7 +789,7 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
// } // }
// } // }
} else if (value == null) { } else if (value == null) {
this.cgBiggestBet = null this.cgBlinds = null
this.cgAnte = null this.cgAnte = null
} }
SessionPropertiesRow.BREAK_TIME -> { SessionPropertiesRow.BREAK_TIME -> {

@ -11,15 +11,18 @@ class DataUtils {
companion object { companion object {
/** /**
* Returns true if the provided parameters doesn't correspond to an existing session * Returns the number of sessions corresponding to the provided parameters
*/ */
fun sessionCount(realm: Realm, startDate: Date, endDate: Date, net: Double): Int { fun sessionCount(realm: Realm, startDate: Date, endDate: Date?, net: Double): Int {
val sessions = realm.where(Session::class.java) var sessionQuery = realm.where(Session::class.java)
.equalTo("startDate", startDate) .equalTo("startDate", startDate)
.equalTo("endDate", endDate)
.equalTo("result.net", net) .equalTo("result.net", net)
.findAll()
return sessions.size endDate?.let {
sessionQuery = sessionQuery.equalTo("endDate", it)
}
return sessionQuery.findAll().size
} }
/** /**

@ -31,7 +31,9 @@ class ImportFragment : RealmFragment(), ImportDelegate {
private var _binding: FragmentImportBinding? = null private var _binding: FragmentImportBinding? = null
private val binding get() = _binding!! private val binding get() = _binding!!
// Life Cycle private val exceptions: MutableList<Exception> = mutableListOf()
// Life Cycle
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
super.onCreateView(inflater, container, savedInstanceState) super.onCreateView(inflater, container, savedInstanceState)
@ -44,7 +46,6 @@ class ImportFragment : RealmFragment(), ImportDelegate {
_binding = null _binding = null
} }
fun setData(path: String) { fun setData(path: String) {
this.filePath = path this.filePath = path
} }
@ -90,7 +91,6 @@ class ImportFragment : RealmFragment(), ImportDelegate {
this.importer = CSVImporter(inputStream) this.importer = CSVImporter(inputStream)
this.importer.delegate = this this.importer.delegate = this
var exception: Exception? = null
GlobalScope.launch(coroutineContext) { GlobalScope.launch(coroutineContext) {
@ -98,11 +98,8 @@ class ImportFragment : RealmFragment(), ImportDelegate {
val s = Date() val s = Date()
Timber.d(">>> Start Import...") Timber.d(">>> Start Import...")
try { importer.start()
importer.start()
} catch (e: Exception) {
exception = e
}
val e = Date() val e = Date()
val duration = (e.time - s.time) / 1000.0 val duration = (e.time - s.time) / 1000.0
Timber.d(">>> Import ended in $duration seconds") Timber.d(">>> Import ended in $duration seconds")
@ -110,9 +107,9 @@ class ImportFragment : RealmFragment(), ImportDelegate {
} }
test.await() test.await()
val exceptionMessage = exception?.message val exceptionMessage = exceptions.firstOrNull()?.message
if (exceptionMessage != null && view != null) { if (exceptionMessage != null && view != null) {
val message = exceptionMessage + ". " + requireContext().getString(R.string.import_error) val message = "${exceptions.size} " + requireContext().getString(R.string.errors) + ":\n" + exceptionMessage + ".\n" + requireContext().getString(R.string.import_error)
val snackBar = Snackbar.make(view!!, message, Snackbar.LENGTH_INDEFINITE) val snackBar = Snackbar.make(view!!, message, Snackbar.LENGTH_INDEFINITE)
snackBar.setAction(R.string.ok) { snackBar.setAction(R.string.ok) {
snackBar.dismiss() snackBar.dismiss()
@ -160,4 +157,8 @@ class ImportFragment : RealmFragment(), ImportDelegate {
binding.totalCounter.text = this.numberFormatter.format(totalCount) binding.totalCounter.text = this.numberFormatter.format(totalCount)
} }
override fun exceptionCaught(e: Exception) {
this.exceptions.add(e)
}
} }

@ -14,6 +14,7 @@ import timber.log.Timber
*/ */
enum class DataSource { enum class DataSource {
POKER_ANALYTICS, POKER_ANALYTICS,
POKER_ANALYTICS_6,
POKER_INCOME, POKER_INCOME,
POKER_BANKROLL_TRACKER, POKER_BANKROLL_TRACKER,
RUN_GOOD, RUN_GOOD,

@ -3,8 +3,6 @@ package net.pokeranalytics.android.util.csv
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import io.realm.Realm import io.realm.Realm
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.util.extensions.count
import org.apache.commons.csv.CSVFormat import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVParser import org.apache.commons.csv.CSVParser
import org.apache.commons.csv.CSVRecord import org.apache.commons.csv.CSVRecord
@ -18,6 +16,7 @@ class ImportException(message: String) : Exception(message)
interface ImportDelegate { interface ImportDelegate {
fun parsingCountUpdate(importedCount: Int, totalCount: Int) fun parsingCountUpdate(importedCount: Int, totalCount: Int)
fun exceptionCaught(e: Exception)
} }
/** /**
@ -107,7 +106,7 @@ open class CSVImporter(istream: InputStream) {
realm.beginTransaction() realm.beginTransaction()
parser.forEachIndexed { index, record -> this.parser.forEachIndexed { index, record ->
// Timber.d("line $index") // Timber.d("line $index")
this.notifyDelegate() this.notifyDelegate()
@ -146,12 +145,19 @@ open class CSVImporter(istream: InputStream) {
null // reset descriptor when encountering an empty line (multiple descriptors can be found in a single file) null // reset descriptor when encountering an empty line (multiple descriptors can be found in a single file)
this.descriptorFindingAttempts = 0 this.descriptorFindingAttempts = 0
} else { } else {
val count = it.parse(realm, record)
this.importedRecords += count try {
this.totalParsedRecords++ val count = it.parse(realm, record)
this.importedRecords += count
this.totalParsedRecords++
this.notifyDelegate()
} catch (e: Exception) {
this.delegate?.exceptionCaught(e)
}
this.notifyDelegate()
} }
} ?: run { } ?: run {
realm.cancelTransaction() realm.cancelTransaction()

@ -1,11 +1,11 @@
package net.pokeranalytics.android.util.csv package net.pokeranalytics.android.util.csv
import net.pokeranalytics.android.model.interfaces.Identifiable
import io.realm.Realm import io.realm.Realm
import net.pokeranalytics.android.exceptions.PAIllegalStateException 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
import net.pokeranalytics.android.model.interfaces.Identifiable
import net.pokeranalytics.android.model.realm.* import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.model.utils.DataUtils import net.pokeranalytics.android.model.utils.DataUtils
import net.pokeranalytics.android.util.BLIND_SEPARATOR import net.pokeranalytics.android.util.BLIND_SEPARATOR
@ -80,7 +80,9 @@ abstract class PACSVDescriptor<T : Identifiable>(source: DataSource,
} else {} } else {}
} }
is SessionField.End -> { is SessionField.End -> {
endDate = parseDate(field, value) if (value.isNotEmpty()) {
endDate = parseDate(field, value)
}
} }
is SessionField.StartTime -> { is SessionField.StartTime -> {
startDate?.setHourMinutes(value) startDate?.setHourMinutes(value)
@ -276,9 +278,9 @@ abstract class PACSVDescriptor<T : Identifiable>(source: DataSource,
} }
val net = session.result?.net val net = session.result?.net
if (startDate != null && endDate != null && net != null) { // valid session if (startDate != null && net != null) { // valid session
// session already in realm, we'd love not put it in Realm before doing the check // session already in realm, we'd love not put it in Realm before doing the check
val count = DataUtils.sessionCount(realm, startDate!!, endDate!!, net) val count = DataUtils.sessionCount(realm, startDate!!, endDate, net)
if (this.noSessionImport || count == 0) { if (this.noSessionImport || count == 0) {
val managedSession = realm.copyToRealm(session) val managedSession = realm.copyToRealm(session)

@ -279,7 +279,7 @@ class ProductCSVDescriptors {
val pokerAnalyticsAndroid6Sessions: SessionCSVDescriptor val pokerAnalyticsAndroid6Sessions: SessionCSVDescriptor
get() { get() {
return SessionCSVDescriptor( return SessionCSVDescriptor(
DataSource.POKER_ANALYTICS, DataSource.POKER_ANALYTICS_6,
true, true,
SessionField.Start("Start Date", dateFormat = "MM/dd/yy HH:mm:ss"), SessionField.Start("Start Date", dateFormat = "MM/dd/yy HH:mm:ss"),
SessionField.End("End Date", dateFormat = "MM/dd/yy HH:mm:ss"), SessionField.End("End Date", dateFormat = "MM/dd/yy HH:mm:ss"),

@ -778,4 +778,5 @@
<string name="estimated">estimation</string> <string name="estimated">estimation</string>
<string name="dhph_explanation">Vous pouvez changer le nombre de mains distribuées par heure. Cette valeur correspond au nombre total de mains distribuées à tous les joueur d\'une table en une heure. Exemple: Vous jouez 25 mains par heure sur des tables de 10 joueurs, entrez: 10 x 25 = 250.</string> <string name="dhph_explanation">Vous pouvez changer le nombre de mains distribuées par heure. Cette valeur correspond au nombre total de mains distribuées à tous les joueur d\'une table en une heure. Exemple: Vous jouez 25 mains par heure sur des tables de 10 joueurs, entrez: 10 x 25 = 250.</string>
<string name="dealt_hands_per_hour">Mains par heure</string> <string name="dealt_hands_per_hour">Mains par heure</string>
<string name="errors">erreur(s)</string>
</resources> </resources>

@ -821,5 +821,6 @@
<string name="report_name_cannot_be_empty">You need to give a name to the report</string> <string name="report_name_cannot_be_empty">You need to give a name to the report</string>
<string name="wildcards_warning">The hand you\'ve created has suit wildcards. By convenience - sorry! - we\'re currently removing such cards to determine which hand wins, resulting in potentially wrong chip distribution.</string> <string name="wildcards_warning">The hand you\'ve created has suit wildcards. By convenience - sorry! - we\'re currently removing such cards to determine which hand wins, resulting in potentially wrong chip distribution.</string>
<string name="proceed">proceed</string> <string name="proceed">proceed</string>
<string name="errors">error(s)</string>
</resources> </resources>

Loading…
Cancel
Save