|
|
|
|
@ -4,6 +4,7 @@ import io.realm.Realm |
|
|
|
|
import io.realm.kotlin.deleteFromRealm |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.Identifiable |
|
|
|
|
import net.pokeranalytics.android.model.interfaces.ObjectIdentifier |
|
|
|
|
import net.pokeranalytics.android.model.realm.CustomField |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import net.pokeranalytics.android.util.extensions.findById |
|
|
|
|
import org.apache.commons.csv.CSVRecord |
|
|
|
|
@ -26,7 +27,7 @@ abstract class DataCSVDescriptor<T : Identifiable>(source: DataSource, vararg el |
|
|
|
|
/** |
|
|
|
|
* List of Realm object identificators |
|
|
|
|
*/ |
|
|
|
|
val realmModelIds = mutableListOf<ObjectIdentifier>() |
|
|
|
|
private val realmModelIds = mutableListOf<ObjectIdentifier>() |
|
|
|
|
|
|
|
|
|
abstract fun parseData(realm: Realm, record: CSVRecord): T? |
|
|
|
|
|
|
|
|
|
@ -83,29 +84,19 @@ abstract class CSVDescriptor(var source: DataSource, vararg elements: CSVField) |
|
|
|
|
/** |
|
|
|
|
* The CSVField list describing the CSV header format |
|
|
|
|
*/ |
|
|
|
|
protected var fields: List<CSVField> = listOf() |
|
|
|
|
protected var fields: MutableList<CSVField> = mutableListOf() |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The mapping of CSVField with their index in the CSV file |
|
|
|
|
*/ |
|
|
|
|
protected var fieldMapping: MutableMap<CSVField, Int> = mutableMapOf() |
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
if (elements.size > 0) { |
|
|
|
|
this.fields = elements.toList() |
|
|
|
|
if (elements.isNotEmpty()) { |
|
|
|
|
this.fields = elements.toMutableList() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
/** |
|
|
|
|
* The list of all managed CSVDescriptors |
|
|
|
|
*/ |
|
|
|
|
val all: List<CSVDescriptor> = |
|
|
|
|
listOf(ProductCSVDescriptors.pokerIncomeCash, |
|
|
|
|
ProductCSVDescriptors.pokerBankrollTracker, |
|
|
|
|
ProductCSVDescriptors.runGoodCashGames, |
|
|
|
|
ProductCSVDescriptors.runGoodTournaments) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Method called when iterating on a CSVRecord |
|
|
|
|
*/ |
|
|
|
|
@ -140,4 +131,24 @@ abstract class CSVDescriptor(var source: DataSource, vararg elements: CSVField) |
|
|
|
|
return count >= mandatoryfields.size |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun mapCustomField(record: CSVRecord, realm: Realm) { |
|
|
|
|
val customFields = realm.where(CustomField::class.java).findAll() |
|
|
|
|
val headers = record.toSet() |
|
|
|
|
headers.forEach { header -> |
|
|
|
|
val customField = customFields.firstOrNull { it.name == header } |
|
|
|
|
customField?.let { |
|
|
|
|
|
|
|
|
|
if (it.isListType) { |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
val f = MappedCustomCVSField.Number(header, null, "", it) |
|
|
|
|
fields.add(f) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|