forked from penguin86/luna-tracker
MainActivity: generate dynamic menu from last two weeks
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
Reference in New Issue
Block a user