|
|
|
@ -8,15 +8,19 @@ import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.Realm |
|
|
|
import kotlinx.android.synthetic.main.fragment_calendar.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_calendar.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_stats.recyclerView |
|
|
|
import kotlinx.android.synthetic.main.fragment_stats.recyclerView |
|
|
|
import kotlinx.coroutines.* |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
|
|
|
import kotlinx.coroutines.GlobalScope |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.calculus.Calculator |
|
|
|
import net.pokeranalytics.android.calculus.Calculator |
|
|
|
import net.pokeranalytics.android.calculus.Report |
|
|
|
import net.pokeranalytics.android.calculus.ComputedResults |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.model.comparison.Comparator |
|
|
|
import net.pokeranalytics.android.model.comparison.Comparator |
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
import net.pokeranalytics.android.model.comparison.combined |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.SessionObserverFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.SessionObserverFragment |
|
|
|
import net.pokeranalytics.android.ui.view.CalendarTabs |
|
|
|
import net.pokeranalytics.android.ui.view.CalendarTabs |
|
|
|
|
|
|
|
import timber.log.Timber |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
|
|
@ -36,6 +40,13 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
|
|
|
|
get() = Dispatchers.Main |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var sortedMonthlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
|
|
|
|
private var sortedYearlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
|
|
|
|
|
|
|
|
// Life Cycle |
|
|
|
// Life Cycle |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
@ -58,150 +69,138 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun initData() { |
|
|
|
private fun initData() { |
|
|
|
|
|
|
|
|
|
|
|
val realm = getRealm() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//example |
|
|
|
|
|
|
|
//per year x month |
|
|
|
|
|
|
|
val report = Calculator.computeStatsWithComparators(realm, comparators = listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR), options = Calculator.Options()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
report.results.forEach { |
|
|
|
|
|
|
|
//show net result per year x month |
|
|
|
|
|
|
|
print(it.computedStat(Stat.NETRESULT)?.value) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
si on voulait faire Year en même temps, il faudrait un array de yearData et la possibilité d'appeler un computedStat sur un array de computedResult |
|
|
|
|
|
|
|
un yearData devra alors conteneir une variable "results" qui serait un array de tous des results de tous les mois d'une année (qu'on viendrait piocher dans report.results |
|
|
|
|
|
|
|
A discuter: |
|
|
|
|
|
|
|
- stocker les queryConditions dans chaque result ? |
|
|
|
|
|
|
|
- appeler un computedStat sur un array de computedResult ? |
|
|
|
|
|
|
|
- demander si on veut ou pas une entrée vide quand pas de sessions pour une query dans report.results |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//per year |
|
|
|
|
|
|
|
val reportMonth = Calculator.computeStatsWithComparators(realm, comparators = listOf(Comparator.YEAR), options = Calculator.Options()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reportMonth.results.forEach { |
|
|
|
|
|
|
|
//show net result per year |
|
|
|
|
|
|
|
print(it.computedStat(Stat.NETRESULT)?.value) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Init UI |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CalendarTabs.values().forEach { |
|
|
|
// compute per cell (year x month) |
|
|
|
val tab = tabs.newTab() |
|
|
|
// build conditions array and save it |
|
|
|
tab.text = getString(it.resId) |
|
|
|
val conditions = listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR).combined() |
|
|
|
tabs.addTab(tab) |
|
|
|
|
|
|
|
|
|
|
|
// compute at index |
|
|
|
|
|
|
|
conditions.forEach { |
|
|
|
|
|
|
|
Calculator.computeStatsWithComparators(realm, conditions = it, options = Calculator.Options()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// compute per cell (year) |
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
// build year conditions array and save it |
|
|
|
|
|
|
|
val yearConditions = listOf(Comparator.YEAR) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// compute at index |
|
|
|
recyclerView.apply { |
|
|
|
yearConditions .forEach { |
|
|
|
setHasFixedSize(true) |
|
|
|
Calculator.computeStatsWithComparators(realm, conditions = it.queryConditions, options = Calculator.Options()) |
|
|
|
layoutManager = viewManager |
|
|
|
|
|
|
|
//adapter = statsAdapter |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
|
|
|
|
get() = Dispatchers.Main |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Launch stat computation |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun launchStatComputation() { |
|
|
|
private fun launchStatComputation() { |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
val comparator = Comparator.YEAR // returns all months |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch { |
|
|
|
GlobalScope.launch { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 1) |
|
|
|
|
|
|
|
calendar.set(Calendar.HOUR_OF_DAY, 0) |
|
|
|
|
|
|
|
calendar.set(Calendar.MINUTE, 0) |
|
|
|
|
|
|
|
calendar.set(Calendar.SECOND, 0) |
|
|
|
|
|
|
|
calendar.set(Calendar.MILLISECOND, 0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val startDate = Date() |
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
|
|
|
|
|
|
|
val report = Calculator.computeStatsWithComparators(realm, comparators = listOf(comparator), options = Calculator.Options()) |
|
|
|
val montlyReports: HashMap<Date, ComputedResults> = HashMap() |
|
|
|
Timber.d("Report results: ${report.results.size}") |
|
|
|
val yearlyReports: HashMap<Date, ComputedResults> = HashMap() |
|
|
|
|
|
|
|
|
|
|
|
report.results.forEach { |
|
|
|
// Compute data per YEAR x MONTH |
|
|
|
|
|
|
|
val conditions = listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR).combined() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
conditions.forEach { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val report = Calculator.computeStatsWithComparators(realm, conditions = it, options = Calculator.Options()) |
|
|
|
|
|
|
|
//Timber.d("======> report results: ${report.results.size}") |
|
|
|
|
|
|
|
report.results.forEach { computedResults -> |
|
|
|
|
|
|
|
//Timber.d("======> computedResults empty: ${computedResults.isEmpty}") |
|
|
|
|
|
|
|
if (!computedResults.isEmpty) { |
|
|
|
|
|
|
|
|
|
|
|
val isEmpty = it.isEmpty |
|
|
|
// Set date data |
|
|
|
val statValue = it.computedStat(Stat.NETRESULT)?.value |
|
|
|
it.forEach { condition -> |
|
|
|
Timber.d("isEmpty: $isEmpty / statValue: $statValue / Number of stats: ${it.numberOfStats()}") |
|
|
|
condition.valueMap?.get("year")?.let { year -> |
|
|
|
|
|
|
|
calendar.set(Calendar.YEAR, year as Int) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
condition.valueMap?.get("month")?.let { month -> |
|
|
|
|
|
|
|
calendar.set(Calendar.MONTH, month as Int) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
conditions.forEach { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val realm = getRealm() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
montlyReports[calendar.time] = computedResults |
|
|
|
|
|
|
|
|
|
|
|
var r = Report() |
|
|
|
//val statValue = computedResults.computedStat(Stat.NETRESULT)?.value |
|
|
|
val test = GlobalScope.async { |
|
|
|
//Timber.d("======> statValue: $statValue / Number of stats: ${computedResults.numberOfStats()}") |
|
|
|
val s = Date() |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
// Compute data per YEAR |
|
|
|
|
|
|
|
val yearConditions = Comparator.YEAR.queryConditions |
|
|
|
|
|
|
|
|
|
|
|
Timber.d("Get report for: $it") |
|
|
|
// compute at index |
|
|
|
|
|
|
|
yearConditions.forEach { condition -> |
|
|
|
|
|
|
|
|
|
|
|
val report = Calculator.computeStatsWithComparators(realm, conditions = listOf(it), options = Calculator.Options()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timber.d("Report: $report / Results: ${report.results.size}") |
|
|
|
val report = Calculator.computeStatsWithComparators(realm, conditions = listOf(condition), options = Calculator.Options()) |
|
|
|
|
|
|
|
//Timber.d("======> report results: ${report.results.size}") |
|
|
|
|
|
|
|
report.results.forEach { computedResults -> |
|
|
|
|
|
|
|
//Timber.d("======> computedResults empty: ${computedResults.isEmpty}") |
|
|
|
|
|
|
|
if (!computedResults.isEmpty) { |
|
|
|
|
|
|
|
|
|
|
|
report.results.firstOrNull()?.let { |
|
|
|
calendar.set(Calendar.MONTH, 0) |
|
|
|
|
|
|
|
|
|
|
|
val isEmpty = it.isEmpty |
|
|
|
// Set date data |
|
|
|
val statValue = it.computedStat(Stat.NETRESULT)?.value |
|
|
|
condition.valueMap?.get("year")?.let { year -> |
|
|
|
|
|
|
|
calendar.set(Calendar.YEAR, year as Int) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Timber.d("isEmpty: $isEmpty") |
|
|
|
yearlyReports[calendar.time] = computedResults |
|
|
|
Timber.d("statValue: $statValue") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
computedResults.computedStat(Stat.NETRESULT)?.let { computedStat -> |
|
|
|
|
|
|
|
Timber.d("======> statValue: ${computedStat.value}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// r = createSessionGroupsAndStartCompute(realm) |
|
|
|
Timber.d("Computation: ${System.currentTimeMillis() - startDate.time}ms") |
|
|
|
// report = r |
|
|
|
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timber.d("========== YEAR x MONTH") |
|
|
|
|
|
|
|
sortedMonthlyReports = montlyReports.toSortedMap(compareByDescending { it }) |
|
|
|
|
|
|
|
sortedMonthlyReports.keys.forEach { |
|
|
|
|
|
|
|
Timber.d("$it => ${sortedMonthlyReports[it]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
} |
|
|
|
} |
|
|
|
test.await() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isDetached) { |
|
|
|
Timber.d("========== YEARLY") |
|
|
|
// showResults(r) |
|
|
|
sortedYearlyReports = yearlyReports.toSortedMap(compareByDescending { it }) |
|
|
|
} |
|
|
|
sortedYearlyReports.keys.forEach { |
|
|
|
|
|
|
|
Timber.d("$it => ${sortedYearlyReports[it]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
|
|
|
|
displayData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Init UI |
|
|
|
* Display data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun initUI() { |
|
|
|
private fun displayData() { |
|
|
|
|
|
|
|
|
|
|
|
CalendarTabs.values().forEach { |
|
|
|
|
|
|
|
val tab = tabs.newTab() |
|
|
|
|
|
|
|
tab.text = getString(it.resId) |
|
|
|
|
|
|
|
tabs.addTab(tab) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
recyclerView.apply { |
|
|
|
|
|
|
|
setHasFixedSize(true) |
|
|
|
|
|
|
|
layoutManager = viewManager |
|
|
|
|
|
|
|
//adapter = statsAdapter |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |