|
|
|
|
@ -2,21 +2,38 @@ package net.pokeranalytics.android.model.comparison |
|
|
|
|
|
|
|
|
|
import io.realm.Realm |
|
|
|
|
import io.realm.RealmQuery |
|
|
|
|
import io.realm.Sort |
|
|
|
|
import io.realm.kotlin.where |
|
|
|
|
import net.pokeranalytics.android.exceptions.PokerAnalyticsException |
|
|
|
|
import net.pokeranalytics.android.model.filter.Filterable |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
|
|
|
|
|
enum class Comparator { |
|
|
|
|
DAY_OF_WEEK, |
|
|
|
|
MONTH_OF_YEAR, |
|
|
|
|
MONTH, |
|
|
|
|
YEAR, |
|
|
|
|
BLIND, |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
val queryConditions: List<QueryCondition> |
|
|
|
|
get() { |
|
|
|
|
return when (this) { |
|
|
|
|
MONTH_OF_YEAR -> List(12) { index-> QueryCondition.MONTH().apply { setMonth(index+1) } } |
|
|
|
|
DAY_OF_WEEK -> listOf() |
|
|
|
|
YEAR -> { |
|
|
|
|
val years = arrayListOf<QueryCondition.YEAR>() |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
val distinctYears = realm.where<Session>().distinct("year").findAll().sort("year", Sort.DESCENDING) |
|
|
|
|
distinctYears.forEach { session -> |
|
|
|
|
session.year?.let { year -> |
|
|
|
|
years.add(QueryCondition.YEAR().apply { setYear(year) }) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
realm.close() |
|
|
|
|
years |
|
|
|
|
} |
|
|
|
|
else -> throw PokerAnalyticsException.QueryTypeUnhandled |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|