Dieser Commit ist enthalten in:
Chaoscaot 2023-12-05 17:43:59 +01:00
Ursprung c9013a69c6
Commit 33b8b8f6a0
4 geänderte Dateien mit 46 neuen und 3 gelöschten Zeilen

1
.gitignore vendored
Datei anzeigen

@ -36,3 +36,4 @@ out/
.vscode/
/config.json
/logs/
/data/

Datei anzeigen

@ -133,7 +133,7 @@ fun Route.configurePage() {
val obj = it.jsonObject
if (obj["type"]?.jsonPrimitive?.content == "dir") {
filesToCheck.add(obj["path"]?.jsonPrimitive?.content!!)
} else if (obj["type"]?.jsonPrimitive?.content == "file" && obj["name"]?.jsonPrimitive?.content?.endsWith(".md") == true) {
} else if (obj["type"]?.jsonPrimitive?.content == "file" && (obj["name"]?.jsonPrimitive?.content?.endsWith(".md") == true || obj["name"]?.jsonPrimitive?.content?.endsWith(".json") == true)) {
files.add(PageResponseList(obj, pathPageIdMap.computeIfAbsent(obj["path"]?.jsonPrimitive?.content!!) { pageId++ }))
}
}

Datei anzeigen

@ -31,16 +31,34 @@ import io.ktor.server.routing.*
import kotlinx.serialization.Serializable
@Serializable
data class UserStats(val eventFightParticipation: Int, val eventParticipation: Int, val acceptedSchematics: Int) {
data class UserStats(val eventFightParticipation: Int, val eventParticipation: Int, val acceptedSchematics: Int, val fights: Int, val playtime: Double) {
constructor(user: SteamwarUser): this(
getEventFightParticipation(user) ?: 0,
getEventParticipation(user) ?: 0,
getAcceptedSchematics(user) ?: 0
getAcceptedSchematics(user) ?: 0,
getFightCount(user) ?: 0,
user.onlinetime
)
}
fun Route.configureStats() {
route("/stats") {
get("/ranked/{gamemode}") {
val gamemode = call.parameters["gamemode"] ?: return@get call.respond(HttpStatusCode.NotFound)
@Serializable
data class RankedUser(val name: String, val elo: Int)
call.respond(getRankedList(gamemode).map { RankedUser(it.first, it.second) })
}
get("/fights") {
val list = getFightList()
@Serializable
data class Fight(val date: String, val gamemode: String, val count: Int)
call.respond(list.map { Fight(it.first, it.second, it.third) })
}
route("/user/{id}") {
install(SWPermissionCheck) {
userCheck {

Datei anzeigen

@ -41,3 +41,27 @@ fun getEventParticipation(user: SteamwarUser): Int? = eventParticipation.select(
private val acceptedSchematics = Statement("SELECT NodeOwner, COUNT(DISTINCT NodeId) AS num FROM SchematicNode WHERE NodeType != 'normal' AND NodeType IS NOT NULL AND NodeType NOT LIKE 'c%' AND NodeOwner = ?")
fun getAcceptedSchematics(user: SteamwarUser): Int? = acceptedSchematics.select(getNum, user.id)
private val fightCount = Statement("SELECT COUNT(*) AS num FROM FightPlayer WHERE UserID = ?")
fun getFightCount(user: SteamwarUser): Int? = fightCount.select(getNum, user.id)
private val rankedList = Statement("SELECT UserName, Elo FROM UserData, UserElo WHERE UserID = id AND GameMode = ? AND Season = ? ORDER BY Elo DESC")
fun getRankedList(gamemode: String): List<Pair<String, Int>> = rankedList.select({ res ->
val list = mutableListOf<Pair<String, Int>>()
while (res.next()) {
list.add(res.getString("UserName") to res.getInt("Elo"))
}
list
}, gamemode, Season.getSeason())
private val fightList = Statement("SELECT DATE(StartTime) AS Datum, GameMode AS Modus, COUNT(*) AS Anzahl FROM Fight WHERE DATE(StartTime) >= DATE(NOW()) - INTERVAL 1 WEEK GROUP BY Datum, GameMode ORDER BY Datum ASC")
fun getFightList(): List<Triple<String, String, Int>> = fightList.select({ res ->
val list = mutableListOf<Triple<String, String, Int>>()
while (res.next()) {
list.add(Triple(res.getString("Datum"), res.getString("Modus"), res.getInt("Anzahl")))
}
list
})