|
|
|
|
@ -1,10 +1,8 @@ |
|
|
|
|
package net.pokeranalytics.android.model.filter |
|
|
|
|
|
|
|
|
|
import io.realm.RealmList |
|
|
|
|
import io.realm.RealmQuery |
|
|
|
|
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
|
|
|
|
import net.pokeranalytics.android.model.realm.FilterCondition |
|
|
|
|
import net.pokeranalytics.android.model.realm.FilterElementBlind |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import net.pokeranalytics.android.util.extensions.endOfDay |
|
|
|
|
import net.pokeranalytics.android.util.extensions.startOfDay |
|
|
|
|
@ -31,7 +29,7 @@ enum class QueryCondition(var operator: Operator? = null) { |
|
|
|
|
LIMIT, |
|
|
|
|
TABLE_SIZE, |
|
|
|
|
TOURNAMENT_TYPE, |
|
|
|
|
BLINDS, |
|
|
|
|
STAKE, |
|
|
|
|
LAST_GAMES, |
|
|
|
|
LAST_SESSIONS, |
|
|
|
|
MORE_NUMBER_OF_TABLE(Operator.MORE), |
|
|
|
|
@ -74,10 +72,6 @@ enum class QueryCondition(var operator: Operator? = null) { |
|
|
|
|
MORE_THAN_DURATION(Operator.MORE), |
|
|
|
|
LESS_THAN_DURATION(Operator.LESS), |
|
|
|
|
|
|
|
|
|
CURRENCY, |
|
|
|
|
CURRENCY_CODE, |
|
|
|
|
BIG_BLIND, |
|
|
|
|
SMALL_BLIND, |
|
|
|
|
COMMENT, |
|
|
|
|
|
|
|
|
|
; |
|
|
|
|
@ -115,7 +109,7 @@ enum class QueryCondition(var operator: Operator? = null) { |
|
|
|
|
return when (this) { |
|
|
|
|
BANKROLL, GAME, LOCATION, ANY_TOURNAMENT_FEATURES, ALL_TOURNAMENT_FEATURES, TOURNAMENT_NAME -> arrayOf("ids") |
|
|
|
|
LIMIT, TOURNAMENT_TYPE, TABLE_SIZE -> arrayOf("values") |
|
|
|
|
BLINDS -> arrayOf("blinds") |
|
|
|
|
STAKE -> arrayOf("stakes") |
|
|
|
|
STARTED_FROM_DATE, STARTED_TO_DATE, ENDED_FROM_DATE, ENDED_TO_DATE -> arrayOf("date") |
|
|
|
|
DAY_OF_WEEK -> arrayOf("dayOfWeek") |
|
|
|
|
MONTH -> arrayOf("month") |
|
|
|
|
@ -129,50 +123,8 @@ enum class QueryCondition(var operator: Operator? = null) { |
|
|
|
|
* providing a base RealmQuery [realmQuery], the method is able to attached the corresponding query and returns the newly formed [RealmQuery] |
|
|
|
|
*/ |
|
|
|
|
inline fun <reified T : Filterable> filter(realmQuery: RealmQuery<T>): RealmQuery<T> { |
|
|
|
|
when { |
|
|
|
|
this == BLINDS -> { |
|
|
|
|
|
|
|
|
|
val smallBlindFieldName = FilterHelper.fieldNameForQueryType<T>(SMALL_BLIND) |
|
|
|
|
val bigBlindFieldName = FilterHelper.fieldNameForQueryType<T>(BIG_BLIND) |
|
|
|
|
val currencyCodeFieldName = FilterHelper.fieldNameForQueryType<T>(CURRENCY_CODE) |
|
|
|
|
smallBlindFieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown |
|
|
|
|
bigBlindFieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown |
|
|
|
|
currencyCodeFieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown |
|
|
|
|
|
|
|
|
|
val blinds: RealmList<FilterElementBlind> by valueMap |
|
|
|
|
blinds.forEachIndexed { index, blind -> |
|
|
|
|
realmQuery |
|
|
|
|
.beginGroup() |
|
|
|
|
|
|
|
|
|
blind.sb?.let { |
|
|
|
|
realmQuery |
|
|
|
|
.equalTo(smallBlindFieldName, it) |
|
|
|
|
.and() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
realmQuery |
|
|
|
|
.equalTo(bigBlindFieldName, blind.bb) |
|
|
|
|
.and() |
|
|
|
|
|
|
|
|
|
blind.currencyCode?.let { |
|
|
|
|
realmQuery.equalTo(currencyCodeFieldName, it) |
|
|
|
|
} ?: run { |
|
|
|
|
realmQuery.isNull(currencyCodeFieldName) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
realmQuery.endGroup() |
|
|
|
|
|
|
|
|
|
if (index < blinds.size - 1) { |
|
|
|
|
realmQuery.or() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return realmQuery |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
|
|
|
|
|
val fieldName = FilterHelper.fieldNameForQueryType<T>(this) |
|
|
|
|
fieldName ?: throw PokerAnalyticsException.QueryValueMapUnknown |
|
|
|
|
|
|
|
|
|
when (operator) { |
|
|
|
|
Operator.LESS -> { |
|
|
|
|
val value: Double by valueMap |
|
|
|
|
@ -204,6 +156,10 @@ enum class QueryCondition(var operator: Operator? = null) { |
|
|
|
|
val ids: Array<String> by valueMap |
|
|
|
|
realmQuery.`in`(fieldName, ids) |
|
|
|
|
} |
|
|
|
|
STAKE -> { |
|
|
|
|
val stakes: Array<String> by valueMap |
|
|
|
|
realmQuery.`in`(fieldName, stakes) |
|
|
|
|
} |
|
|
|
|
BANKROLL, GAME, LOCATION, TOURNAMENT_NAME -> { |
|
|
|
|
val ids: Array<String> by valueMap |
|
|
|
|
realmQuery.`in`(fieldName, ids) |
|
|
|
|
@ -290,9 +246,6 @@ enum class QueryCondition(var operator: Operator? = null) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun updateValueMap(filterCondition: FilterCondition) { |
|
|
|
|
if (filterValuesExpectedKeys == null) { |
|
|
|
|
@ -311,8 +264,8 @@ enum class QueryCondition(var operator: Operator? = null) { |
|
|
|
|
LIMIT, TOURNAMENT_TYPE, TABLE_SIZE -> { |
|
|
|
|
valueMap = mapOf("values" to filterCondition.values) |
|
|
|
|
} |
|
|
|
|
BLINDS -> { |
|
|
|
|
valueMap = mapOf("blinds" to filterCondition.blinds) |
|
|
|
|
STAKE -> { |
|
|
|
|
valueMap = mapOf("stakes" to filterCondition.stakes) |
|
|
|
|
} |
|
|
|
|
STARTED_FROM_DATE, STARTED_TO_DATE, ENDED_FROM_DATE, ENDED_TO_DATE -> { |
|
|
|
|
valueMap = mapOf("date" to filterCondition.date) |
|
|
|
|
|