Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ interface Playtime {
* @param since Optional start time to filter playtime.
* @return An [Object2ObjectMap] where keys are server names and values are durations.
*/
fun playtimesPerServer(since: ZonedDateTime? = null): Object2ObjectMap<String, Duration>
fun playtimesPerServer(since: ZonedDateTime? = null, sortByPlaytime: Boolean = true): Object2ObjectMap<String, Duration>

/**
* Returns a mapping of categories to their respective total playtime durations.
*
* @param since Optional start time to filter playtime.
* @return An [Object2ObjectMap] where keys are category names and values are durations.
*/
fun playtimesPerCategory(since: ZonedDateTime? = null): Object2ObjectMap<String, Duration>
fun playtimesPerCategory(since: ZonedDateTime? = null, sortByPlaytime: Boolean = true): Object2ObjectMap<String, Duration>

fun playtimePerCategoryPerServer(since: ZonedDateTime? = null): Object2ObjectMap<String, Object2ObjectMap<String, Duration>>
fun playtimePerCategoryPerServer(since: ZonedDateTime? = null, sortByPlaytime: Boolean = true): Object2ObjectMap<String, Object2ObjectMap<String, Duration>>

/**
* Returns the average playtime per server, optionally filtered by category and start time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private fun sendPlaytime(sender: CommandSender, player: OfflineCloudPlayer) = pl
variableValue("${player.name()} (${player.uuid})")
appendNewPrefixedLine()
appendNewPrefixedLine {
variableKey("Total")
variableKey("Gesamt")
spacer(": ")
variableValue(complete.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,83 @@ class PlaytimeImpl(private val entries: ObjectList<PlaytimeEntry>) : Playtime {
.sumOf { it.durationSeconds }
.seconds

override fun playtimesPerServer(since: ZonedDateTime?): Object2ObjectMap<String, Duration> =
entries.filter { since == null || it.createdAt.isAfter(since) }
override fun playtimesPerServer(
since: ZonedDateTime?,
sortByPlaytime: Boolean
): Object2ObjectMap<String, Duration> {
val result = entries
.filter { since == null || it.createdAt.isAfter(since) }
.groupBy { it.server }
.mapValuesTo(mutableObject2ObjectMapOf()) { (_, group) ->
group.sumOf { it.durationSeconds }.seconds
}

override fun playtimesPerCategory(since: ZonedDateTime?): Object2ObjectMap<String, Duration> =
entries.filter { since == null || it.createdAt.isAfter(since) }
return if (sortByPlaytime) {
result.entries
.sortedByDescending { it.value }
.associateTo(mutableObject2ObjectMapOf()) { it.toPair() }
} else result
}


override fun playtimesPerCategory(
since: ZonedDateTime?,
sortByPlaytime: Boolean
): Object2ObjectMap<String, Duration> {
val result = entries
.filter { since == null || it.createdAt.isAfter(since) }
.groupBy { it.category }
.mapValuesTo(mutableObject2ObjectMapOf()) { (_, group) ->
group.sumOf { it.durationSeconds }.seconds
}

override fun playtimePerCategoryPerServer(since: ZonedDateTime?): Object2ObjectMap<String, Object2ObjectMap<String, Duration>> =
entries.filter { since == null || it.createdAt.isAfter(since) }
.groupBy { it.category }
.mapValuesTo(mutableObject2ObjectMapOf()) { (_, groupEntries) ->
groupEntries.groupBy { it.server }
.mapValuesTo(mutableObject2ObjectMapOf()) { (_, serverEntries) ->
serverEntries.sumOf { it.durationSeconds }.seconds
}
return if (sortByPlaytime) {
result.entries
.sortedByDescending { it.value }
.associateTo(mutableObject2ObjectMapOf()) { it.toPair() }
} else result
}


override fun playtimePerCategoryPerServer(
since: ZonedDateTime?,
sortByPlaytime: Boolean
): Object2ObjectMap<String, Object2ObjectMap<String, Duration>> {
val filtered = entries
.filter { since == null || it.createdAt.isAfter(since) }

val grouped = filtered.groupBy { it.category }
.mapValues { (_, entriesByCategory) ->
val serverDurations = entriesByCategory
.groupingBy { it.server }
.fold(0L) { acc, e -> acc + e.durationSeconds }
.mapValues { it.value.seconds }

val sorted = if (sortByPlaytime)
serverDurations.entries.sortedByDescending { it.value }
else serverDurations.entries

mutableObject2ObjectMapOf<String, Duration>().apply {
sorted.forEach { (k, v) -> this[k] = v }
}
}

val categorySums = grouped.mapValues { (_, serverDurations) ->
serverDurations.values.sumOf { it.inWholeSeconds }
}

val finalResult = if (sortByPlaytime)
grouped.entries.sortedByDescending { categorySums[it.key] }
else grouped.entries

return mutableObject2ObjectMapOf<String, Object2ObjectMap<String, Duration>>().apply {
finalResult.forEach { (k, v) -> this[k] = v }
}
}





override fun averagePlaytimePerServer(
category: String?,
Expand Down