MainActivity: generate dynamic menu from last two weeks

This commit is contained in:
2026-02-19 00:12:45 +01:00
parent 3779e7e34d
commit 1763a9cfd0

View File

@@ -148,12 +148,14 @@ class MainActivity : AppCompatActivity() {
val eventTypeStats = mutableMapOf<LunaEvent.Type, Int>() val eventTypeStats = mutableMapOf<LunaEvent.Type, Int>()
if (dynamicMenu) { if (dynamicMenu) {
val sampleSize = 100 // populate frequency map from all events of the last two weeks
// populate frequency map from first 100 events val lastWeekTime = (System.currentTimeMillis() / 1000) - (14 * 24 * 60 * 60)
allEvents.take(sampleSize.coerceAtMost(allEvents.size)).forEach { allEvents.forEach {
if (it.time > lastWeekTime) {
eventTypeStats[it.type] = 1 + (eventTypeStats[it.type] ?: 0) eventTypeStats[it.type] = 1 + (eventTypeStats[it.type] ?: 0)
} }
} }
}
// sort all event types by frequency and ordinal // sort all event types by frequency and ordinal
val eventTypesSorted = LunaEvent.Type.entries.toList().sortedWith( val eventTypesSorted = LunaEvent.Type.entries.toList().sortedWith(