|
|
|
@ -38,7 +38,11 @@ import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
|
|
class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
|
|
enum class TimeFilter { |
|
|
|
private enum class SessionType { |
|
|
|
|
|
|
|
ALL, CASH, TOURNAMENT |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private enum class TimeFilter { |
|
|
|
MONTH, YEAR |
|
|
|
MONTH, YEAR |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -64,7 +68,10 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
private var rows: ArrayList<CustomizableRowRepresentable> = ArrayList() |
|
|
|
private var rows: ArrayList<CustomizableRowRepresentable> = ArrayList() |
|
|
|
private var sortedMonthlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
private var sortedMonthlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
private var sortedYearlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
private var sortedYearlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
private var currentTimeFilter = TimeFilter.YEAR |
|
|
|
|
|
|
|
|
|
|
|
private var currentSessionType = SessionType.ALL |
|
|
|
|
|
|
|
private var currentTimeFilter = TimeFilter.MONTH |
|
|
|
|
|
|
|
private var currentStat = Stat.NETRESULT |
|
|
|
|
|
|
|
|
|
|
|
// Life Cycle |
|
|
|
// Life Cycle |
|
|
|
|
|
|
|
|
|
|
|
@ -107,15 +114,16 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
when (tab.position) { |
|
|
|
when (tab.position) { |
|
|
|
0 -> displayData(Stat.NETRESULT) |
|
|
|
0 -> currentStat = Stat.NETRESULT |
|
|
|
1 -> displayData(Stat.HOURLY_RATE) |
|
|
|
1 -> currentStat = Stat.HOURLY_RATE |
|
|
|
2 -> displayData(Stat.NUMBER_OF_GAMES) |
|
|
|
2 -> currentStat = Stat.NUMBER_OF_GAMES |
|
|
|
3 -> displayData(Stat.WIN_RATIO) |
|
|
|
3 -> currentStat = Stat.WIN_RATIO |
|
|
|
4 -> displayData(Stat.STANDARD_DEVIATION_HOURLY) |
|
|
|
4 -> currentStat = Stat.STANDARD_DEVIATION_HOURLY |
|
|
|
5 -> displayData(Stat.AVERAGE) |
|
|
|
5 -> currentStat = Stat.AVERAGE |
|
|
|
6 -> displayData(Stat.AVERAGE_DURATION) |
|
|
|
6 -> currentStat = Stat.AVERAGE_DURATION |
|
|
|
7 -> displayData(Stat.DURATION) |
|
|
|
7 -> currentStat = Stat.DURATION |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
displayData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onTabUnselected(tab: TabLayout.Tab) { |
|
|
|
override fun onTabUnselected(tab: TabLayout.Tab) { |
|
|
|
@ -123,8 +131,61 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
|
|
|
|
|
|
|
|
override fun onTabReselected(tab: TabLayout.Tab) { |
|
|
|
override fun onTabReselected(tab: TabLayout.Tab) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Manage session type filter |
|
|
|
|
|
|
|
filterSessionAll.setOnCheckedChangeListener { buttonView, isChecked -> |
|
|
|
|
|
|
|
if (isChecked) { |
|
|
|
|
|
|
|
currentSessionType = SessionType.ALL |
|
|
|
|
|
|
|
filterSessionCash.isChecked = false |
|
|
|
|
|
|
|
filterSessionTournament.isChecked = false |
|
|
|
|
|
|
|
launchStatComputation() |
|
|
|
|
|
|
|
} else if (currentSessionType == SessionType.ALL) { |
|
|
|
|
|
|
|
filterSessionAll.isChecked = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
filterSessionCash.setOnCheckedChangeListener { buttonView, isChecked -> |
|
|
|
|
|
|
|
if (isChecked) { |
|
|
|
|
|
|
|
currentSessionType = SessionType.CASH |
|
|
|
|
|
|
|
filterSessionAll.isChecked = false |
|
|
|
|
|
|
|
filterSessionTournament.isChecked = false |
|
|
|
|
|
|
|
launchStatComputation() |
|
|
|
|
|
|
|
} else if (currentSessionType == SessionType.CASH) { |
|
|
|
|
|
|
|
filterSessionCash.isChecked = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
filterSessionTournament.setOnCheckedChangeListener { buttonView, isChecked -> |
|
|
|
|
|
|
|
if (isChecked) { |
|
|
|
|
|
|
|
currentSessionType = SessionType.TOURNAMENT |
|
|
|
|
|
|
|
filterSessionAll.isChecked = false |
|
|
|
|
|
|
|
filterSessionCash.isChecked = false |
|
|
|
|
|
|
|
launchStatComputation() |
|
|
|
|
|
|
|
} else if (currentSessionType == SessionType.TOURNAMENT) { |
|
|
|
|
|
|
|
filterSessionTournament.isChecked = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Manage time filter |
|
|
|
|
|
|
|
filterTimeMonth.setOnCheckedChangeListener { buttonView, isChecked -> |
|
|
|
|
|
|
|
if (isChecked) { |
|
|
|
|
|
|
|
currentTimeFilter = TimeFilter.MONTH |
|
|
|
|
|
|
|
filterTimeYear.isChecked = false |
|
|
|
|
|
|
|
displayData() |
|
|
|
|
|
|
|
} else if (currentTimeFilter == TimeFilter.MONTH) { |
|
|
|
|
|
|
|
filterTimeMonth.isChecked = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
filterTimeYear.setOnCheckedChangeListener { buttonView, isChecked -> |
|
|
|
|
|
|
|
if (isChecked) { |
|
|
|
|
|
|
|
currentTimeFilter = TimeFilter.YEAR |
|
|
|
|
|
|
|
filterTimeMonth.isChecked = false |
|
|
|
|
|
|
|
displayData() |
|
|
|
|
|
|
|
} else if (currentTimeFilter == TimeFilter.YEAR) { |
|
|
|
|
|
|
|
filterTimeYear.isChecked = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
calendarAdapter = RowRepresentableAdapter(this, this) |
|
|
|
calendarAdapter = RowRepresentableAdapter(this, this) |
|
|
|
@ -154,13 +215,19 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
val yearlyReports: HashMap<Date, ComputedResults> = HashMap() |
|
|
|
val yearlyReports: HashMap<Date, ComputedResults> = HashMap() |
|
|
|
|
|
|
|
|
|
|
|
// Compute data per YEAR and MONTH |
|
|
|
// Compute data per YEAR and MONTH |
|
|
|
val conditions = listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR).combined() |
|
|
|
|
|
|
|
conditions.forEach { |
|
|
|
val monthConditions = when(currentSessionType) { |
|
|
|
val report = Calculator.computeStatsWithComparators(realm, conditions = it, options = Calculator.Options()) |
|
|
|
SessionType.ALL -> listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR).combined() |
|
|
|
|
|
|
|
SessionType.CASH -> listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR, Comparator.CASH).combined() |
|
|
|
|
|
|
|
SessionType.TOURNAMENT -> listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR, Comparator.TOURNAMENT).combined() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
monthConditions.forEach {conditions -> |
|
|
|
|
|
|
|
val report = Calculator.computeStatsWithComparators(realm, conditions = conditions, options = Calculator.Options()) |
|
|
|
report.results.forEach { computedResults -> |
|
|
|
report.results.forEach { computedResults -> |
|
|
|
if (!computedResults.isEmpty) { |
|
|
|
if (!computedResults.isEmpty) { |
|
|
|
// Set date data |
|
|
|
// Set date data |
|
|
|
it.forEach { condition -> |
|
|
|
conditions.forEach { condition -> |
|
|
|
condition.valueMap?.get("year")?.let { year -> |
|
|
|
condition.valueMap?.get("year")?.let { year -> |
|
|
|
calendar.set(Calendar.YEAR, year as Int) |
|
|
|
calendar.set(Calendar.YEAR, year as Int) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -177,38 +244,47 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
calendar.time = Date().startOfYear() |
|
|
|
calendar.time = Date().startOfYear() |
|
|
|
|
|
|
|
|
|
|
|
// Compute data per YEAR |
|
|
|
// Compute data per YEAR |
|
|
|
val yearConditions = Comparator.YEAR.queryConditions |
|
|
|
val yearConditions = when(currentSessionType) { |
|
|
|
yearConditions.forEach { condition -> |
|
|
|
SessionType.ALL -> listOf(Comparator.YEAR).combined() |
|
|
|
val report = Calculator.computeStatsWithComparators(realm, conditions = listOf(condition), options = Calculator.Options()) |
|
|
|
SessionType.CASH -> listOf(Comparator.YEAR, Comparator.CASH).combined() |
|
|
|
|
|
|
|
SessionType.TOURNAMENT -> listOf(Comparator.YEAR, Comparator.TOURNAMENT).combined() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yearConditions.forEach { conditions -> |
|
|
|
|
|
|
|
val report = Calculator.computeStatsWithComparators(realm, conditions = conditions, options = Calculator.Options()) |
|
|
|
report.results.forEach { computedResults -> |
|
|
|
report.results.forEach { computedResults -> |
|
|
|
if (!computedResults.isEmpty) { |
|
|
|
if (!computedResults.isEmpty) { |
|
|
|
// Set date data |
|
|
|
// Set date data |
|
|
|
condition.valueMap?.get("year")?.let { year -> |
|
|
|
conditions.forEach { condition -> |
|
|
|
calendar.set(Calendar.YEAR, year as Int) |
|
|
|
condition.valueMap?.get("year")?.let { year -> |
|
|
|
|
|
|
|
calendar.set(Calendar.YEAR, year as Int) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
yearlyReports[calendar.time] = computedResults |
|
|
|
yearlyReports[calendar.time] = computedResults |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Logs |
|
|
|
sortedMonthlyReports = monthlyReports.toSortedMap(compareByDescending { it }) |
|
|
|
|
|
|
|
sortedYearlyReports = yearlyReports.toSortedMap(compareByDescending { it }) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Logs |
|
|
|
|
|
|
|
/* |
|
|
|
Timber.d("Computation: ${System.currentTimeMillis() - startDate.time}ms") |
|
|
|
Timber.d("Computation: ${System.currentTimeMillis() - startDate.time}ms") |
|
|
|
|
|
|
|
|
|
|
|
Timber.d("========== YEAR x MONTH") |
|
|
|
Timber.d("========== YEAR x MONTH") |
|
|
|
sortedMonthlyReports = monthlyReports.toSortedMap(compareByDescending { it }) |
|
|
|
|
|
|
|
sortedMonthlyReports.keys.forEach { |
|
|
|
sortedMonthlyReports.keys.forEach { |
|
|
|
Timber.d("$it => ${sortedMonthlyReports[it]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
Timber.d("$it => ${sortedMonthlyReports[it]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Timber.d("========== YEARLY") |
|
|
|
Timber.d("========== YEARLY") |
|
|
|
sortedYearlyReports = yearlyReports.toSortedMap(compareByDescending { it }) |
|
|
|
|
|
|
|
sortedYearlyReports.keys.forEach { |
|
|
|
sortedYearlyReports.keys.forEach { |
|
|
|
Timber.d("$it => ${sortedYearlyReports[it]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
Timber.d("$it => ${sortedYearlyReports[it]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch(Dispatchers.Main) { |
|
|
|
GlobalScope.launch(Dispatchers.Main) { |
|
|
|
displayData(Stat.NETRESULT) |
|
|
|
displayData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
@ -218,16 +294,12 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Display data |
|
|
|
* Display data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun displayData(stat: Stat) { |
|
|
|
private fun displayData() { |
|
|
|
|
|
|
|
|
|
|
|
val startDate = Date() |
|
|
|
val startDate = Date() |
|
|
|
|
|
|
|
|
|
|
|
rows.clear() |
|
|
|
rows.clear() |
|
|
|
|
|
|
|
|
|
|
|
Timber.d("currentTimeFilter: $currentTimeFilter") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentTimeFilter = TimeFilter.MONTH |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when (currentTimeFilter) { |
|
|
|
when (currentTimeFilter) { |
|
|
|
|
|
|
|
|
|
|
|
// Create monthly reports |
|
|
|
// Create monthly reports |
|
|
|
@ -246,7 +318,7 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sortedMonthlyReports[date]?.computedStat(stat)?.let { computedStat -> |
|
|
|
sortedMonthlyReports[date]?.computedStat(currentStat)?.let { computedStat -> |
|
|
|
rows.add( |
|
|
|
rows.add( |
|
|
|
CustomizableRowRepresentable( |
|
|
|
CustomizableRowRepresentable( |
|
|
|
customViewType = RowViewType.TITLE_VALUE_ARROW, |
|
|
|
customViewType = RowViewType.TITLE_VALUE_ARROW, |
|
|
|
@ -263,7 +335,7 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
|
|
|
|
|
|
|
|
sortedYearlyReports.keys.forEach { date -> |
|
|
|
sortedYearlyReports.keys.forEach { date -> |
|
|
|
Timber.d("$date => ${sortedYearlyReports[date]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
Timber.d("$date => ${sortedYearlyReports[date]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
sortedYearlyReports[date]?.computedStat(stat)?.let { computedStat -> |
|
|
|
sortedYearlyReports[date]?.computedStat(currentStat)?.let { computedStat -> |
|
|
|
rows.add( |
|
|
|
rows.add( |
|
|
|
CustomizableRowRepresentable( |
|
|
|
CustomizableRowRepresentable( |
|
|
|
customViewType = RowViewType.TITLE_VALUE_ARROW, |
|
|
|
customViewType = RowViewType.TITLE_VALUE_ARROW, |
|
|
|
|