Skip to content

Commit

Permalink
Always use contestSystemId as team id
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyavskiy committed Mar 16, 2024
1 parent 66dd417 commit e58805f
Show file tree
Hide file tree
Showing 61 changed files with 105,142 additions and 106,719 deletions.
10 changes: 5 additions & 5 deletions schemas/advanced.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"default": "TaskStatus"
},
"teamId": {
"type": "number"
"type": "string"
},
"isMedia": {
"type": "boolean"
Expand Down Expand Up @@ -370,7 +370,7 @@
"additionalProperties": false,
"required": []
},
"kotlin.collections.LinkedHashMap?<kotlin.String,org.icpclive.cds.tunning.TeamInfoOverride>": {
"kotlin.collections.LinkedHashMap?<org.icpclive.cds.api.TeamId,org.icpclive.cds.tunning.TeamInfoOverride>": {
"oneOf": [
{
"type": "object",
Expand Down Expand Up @@ -620,7 +620,7 @@
"$ref": "#/$defs/kotlin.collections.ArrayList<org.icpclive.cds.api.AwardsSettings.MedalSettings>"
}
},
"kotlin.collections.ArrayList<kotlin.String>": {
"kotlin.collections.ArrayList<org.icpclive.cds.api.TeamId>": {
"type": "array",
"items": {
"type": "string"
Expand All @@ -636,7 +636,7 @@
"type": "string"
},
"teamCdsIds": {
"$ref": "#/$defs/kotlin.collections.ArrayList<kotlin.String>"
"$ref": "#/$defs/kotlin.collections.ArrayList<org.icpclive.cds.api.TeamId>"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -709,7 +709,7 @@
"$ref": "#/$defs/org.icpclive.cds.tunning.TeamRegexOverrides?<org.icpclive.cds.tunning.RegexSet?,kotlin.collections.LinkedHashMap?,kotlin.collections.LinkedHashMap?>"
},
"teamOverrides": {
"$ref": "#/$defs/kotlin.collections.LinkedHashMap?<kotlin.String,org.icpclive.cds.tunning.TeamInfoOverride>"
"$ref": "#/$defs/kotlin.collections.LinkedHashMap?<org.icpclive.cds.api.TeamId,org.icpclive.cds.tunning.TeamInfoOverride>"
},
"groupOverrides": {
"$ref": "#/$defs/kotlin.collections.LinkedHashMap?<org.icpclive.cds.api.GroupId,org.icpclive.cds.tunning.GroupInfoOverride>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class ExternalRunInfo(

@Serializable
class ExternalTeamInfo(
val id: String,
val fullName: String,
val displayName: String,
val contestSystemId: String,
val groups: List<GroupInfo>,
val hashTag: String?,
val medias: Map<TeamMediaType, MediaType>,
Expand Down
6 changes: 3 additions & 3 deletions src/backend-api/src/main/kotlin/org/icpclive/api/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TickerSettings : ObjectSettings

@Serializable
data class ExternalTeamViewSettings(
val teamId: Int? = null,
val teamId: TeamId? = null,
val mediaTypes: List<TeamMediaType> = emptyList(),
val showTaskStatus: Boolean = true,
val showAchievement: Boolean = false,
Expand All @@ -64,7 +64,7 @@ data class TeamLocatorCircleSettings(
val x: Int,
val y: Int,
val radius: Int,
val teamId: Int,
val teamId: TeamId,
)

@Serializable
Expand All @@ -78,7 +78,7 @@ data class TeamLocatorExternalCircleSettings(
val x: Int,
val y: Int,
val radius: Int,
val teamId: Int? = null,
val teamId: TeamId? = null,
val cdsTeamId: String? = null,
)

Expand Down
5 changes: 3 additions & 2 deletions src/backend-api/src/main/kotlin/org/icpclive/api/Social.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package org.icpclive.api

import kotlinx.serialization.Serializable
import org.icpclive.cds.api.TeamId

@Serializable
sealed class SocialEvent {
abstract val rawText: String
abstract val teamIds: List<Int>
abstract val teamIds: List<TeamId>
abstract val author: String
}

@Serializable
data class ChatMessage(
override val rawText: String,
override val teamIds: List<Int> = emptyList(),
override val teamIds: List<TeamId> = emptyList(),
override val author: String,
val platform: String,
) : SocialEvent()
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package org.icpclive.api

import kotlinx.serialization.Serializable
import org.icpclive.cds.api.TeamId
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

sealed class KeyTeamCause
class RunCause(val runId: Int) : KeyTeamCause()
object ScoreSumCause : KeyTeamCause()

data class KeyTeam(val teamId: Int, val cause: KeyTeamCause)
data class CurrentTeamState(val teamId: Int, val score: Double)
data class KeyTeam(val teamId: TeamId, val cause: KeyTeamCause)
data class CurrentTeamState(val teamId: TeamId, val score: Double)

@Serializable
data class InterestingTeam(val teamId: Int, val teamName: String, val score: Double)
data class InterestingTeam(val teamId: TeamId, val teamName: String, val score: Double)

@Serializable
data class AddTeamScoreRequest(val teamId: Int, val score: Double)
data class AddTeamScoreRequest(val teamId: TeamId, val score: Double)

data class TeamSpotlightFlowSettings(
val notJudgedRunScore: Double = 5.0,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/src/main/kotlin/org/icpclive/admin/Info.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ private fun RunInfo.toExternal(contestInfo: ContestInfo): ExternalRunInfo? {
private fun TeamInfo.toExternal(contestInfo: ContestInfo) : ExternalTeamInfo? {
if (isHidden) return null
return ExternalTeamInfo(
id = id.value,
fullName = fullName,
displayName = displayName,
contestSystemId = contestSystemId,
groups = groups.mapNotNull { contestInfo.groups[it] },
hashTag = hashTag,
medias = medias,
Expand Down
1 change: 1 addition & 0 deletions src/backend/src/main/kotlin/org/icpclive/admin/Social.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.ktor.server.websocket.*
import kotlinx.coroutines.flow.MutableSharedFlow
import org.icpclive.api.ChatMessage
import org.icpclive.api.SocialEvent
import org.icpclive.cds.api.TeamId
import org.icpclive.util.completeOrThrow
import org.icpclive.data.DataBus
import org.icpclive.util.sendJsonFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class LocatorWidgetController(manager: Manager<TeamLocatorWidget>) :
SingleWidgetController<ExternalTeamLocatorSettings, TeamLocatorWidget>(ExternalTeamLocatorSettings(), manager) {
override suspend fun onDelete(id: Int) {}

fun TeamLocatorExternalCircleSettings.getTeam(info: ContestInfo) =
info.teams[teamId] ?: info.cdsTeams[cdsTeamId]
fun TeamLocatorExternalCircleSettings.getTeam(info: ContestInfo) = info.teams[teamId]

override suspend fun checkSettings(settings: ExternalTeamLocatorSettings) {
val info = DataBus.contestInfoFlow.await().first()
Expand Down
3 changes: 1 addition & 2 deletions src/backend/src/main/kotlin/org/icpclive/overlay/Routing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import kotlinx.coroutines.flow.*
import org.icpclive.Config
import org.icpclive.admin.getExternalRun
import org.icpclive.cds.api.OptimismLevel
import org.icpclive.cds.api.RunInfo
import org.icpclive.data.DataBus
import org.icpclive.cds.scoreboard.ScoreboardAndContestInfo
import org.icpclive.cds.scoreboard.toLegacyScoreboard
Expand Down Expand Up @@ -44,7 +43,7 @@ fun Route.configureOverlayRouting() {
}
}
route("/svgAchievement"){
configureSvgAtchievementRouting(Config.mediaDirectory)
configureSvgAchievementRouting(Config.mediaDirectory)
}
get("/visualConfig.json") { call.respond(DataBus.visualConfigFlow.await().value) }
get("/externalRun/{id}") {
Expand Down
8 changes: 5 additions & 3 deletions src/backend/src/main/kotlin/org/icpclive/overlay/SmartSvg.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.util.*
import org.icpclive.admin.getTeams
import kotlinx.coroutines.flow.first
import org.icpclive.cds.api.TeamId
import org.icpclive.data.DataBus
import org.icpclive.util.Svg
import java.io.File
import java.nio.file.Path

fun Route.configureSvgAtchievementRouting(mediaDirectory: Path) {
fun Route.configureSvgAchievementRouting(mediaDirectory: Path) {
get("{path...}") {
val relativePath = call.parameters.getAll("path")?.joinToString(File.separator) ?: ""
val paths = mediaDirectory.resolve(relativePath)

val substitute = call.request.queryParameters.toMap().mapValues { it.value.first() }.toMutableMap()
substitute["teamId"]?.let { teamId ->
getTeams().firstOrNull { it.contestSystemId == teamId }?.let {
DataBus.contestInfoFlow.await().first().teams[TeamId(teamId)]?.let {
substitute["team.name"] = it.fullName
substitute["team.shortName"] = it.displayName
substitute["team.hashTag"] = it.hashTag ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private fun TeamAccent.getScoreDelta(flowSettings: TeamSpotlightFlowSettings) =
}

@Serializable
class TeamState(val teamId: Int) : Comparable<TeamState> {
class TeamState(val teamId: TeamId) : Comparable<TeamState> {
var score = 0.0
private set
private var causedRun: RunInfo? = null
Expand All @@ -91,7 +91,7 @@ class TeamState(val teamId: Int) : Comparable<TeamState> {
override fun compareTo(other: TeamState): Int = when {
other.score > score -> 1
other.score < score -> -1
else -> teamId.compareTo(other.teamId)
else -> teamId.value.compareTo(other.teamId.value)
}
}

Expand All @@ -101,7 +101,7 @@ class TeamSpotlightService(
) {
private val mutex = Mutex()
private val queue = mutableSetOf<TeamState>()
private fun getTeamInQueue(teamId: Int) =
private fun getTeamInQueue(teamId: TeamId) =
queue.find { it.teamId == teamId } ?: TeamState(teamId).also { queue += it }

fun getFlow(): Flow<KeyTeam> {
Expand Down
5 changes: 2 additions & 3 deletions src/cds-converter/src/main/kotlin/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVParser
import org.icpclive.cds.api.ContestInfo
import org.icpclive.cds.api.RunInfo
import org.icpclive.cds.tunning.AdvancedProperties
import org.icpclive.cds.tunning.TeamInfoOverride
import org.icpclive.cds.ContestUpdate
import org.icpclive.cds.adapters.*
import org.icpclive.cds.api.*
import org.icpclive.cds.cli.CdsCommandLineOptions
import org.icpclive.export.icpc.csv.IcpcCsvExporter
import org.icpclive.util.*
Expand Down Expand Up @@ -109,7 +108,7 @@ object IcpcCSVDumpCommand : DumpFileCommand(
} else {
val parser = CSVParser(mappingFile.inputStream().reader(), CSVFormat.TDF)
val map = parser.records.associate {
it[1]!! to it[0]!!
TeamId(it[1]!!) to it[0]!!
}
val advanced = AdvancedProperties(
teamOverrides = map.mapValues {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private fun MediaType.toClicsMedia() = when (this) {
}

private fun TeamInfo.toClicsTeam() = Team(
id = contestSystemId,
id = id.value,
name = fullName,
hidden = isHidden,
group_ids = groups.map { it.value },
Expand Down Expand Up @@ -204,7 +204,6 @@ object ClicsExporter {
}

private val submissionsCreated = mutableSetOf<Int>()
private var teamIdToCdsId = mapOf<Int, String>()

private suspend fun FlowCollector<EventProducer>.processRun(info: ContestInfo, run: RunInfo) {
if (run.id !in submissionsCreated) {
Expand All @@ -215,7 +214,7 @@ object ClicsExporter {
id = run.id.toString(),
language_id = unknownLanguage.id,
problem_id = run.problemId.value,
team_id = teamIdToCdsId[run.teamId]!!,
team_id = run.teamId.value,
time = info.startTime + run.time,
contest_time = run.time,
),
Expand Down Expand Up @@ -249,12 +248,10 @@ object ClicsExporter {
private val groupsMap = mutableMapOf<GroupId, GroupInfo>()
private val orgsMap = mutableMapOf<OrganizationId, OrganizationInfo>()
private val problemsMap = mutableMapOf<ProblemId, ProblemInfo>()
private val teamsMap = mutableMapOf<String, TeamInfo>()
private val teamsMap = mutableMapOf<TeamId, TeamInfo>()

@OptIn(InefficientContestInfoApi::class)
private suspend fun FlowCollector<EventProducer>.calculateDiff(oldInfo: ContestInfo?, newInfo: ContestInfo) {
teamIdToCdsId = newInfo.teamList.associate { it.id to it.contestSystemId }

diff(oldInfo, newInfo, ::getContest, Event::ContestEvent)
diff(oldInfo, newInfo, ::getState, Event::StateEvent)
if (oldInfo == null) {
Expand All @@ -269,7 +266,7 @@ object ClicsExporter {
diffChange(groupsMap, newInfo.groupList, { id }, { toClicsGroup() }) { id, token, data -> Event.GroupsEvent(id.value, token, data) }
diffChange(orgsMap, newInfo.organizationList, { id }, { toClicsOrg() }) { id, token, data -> Event.OrganizationEvent(id.value, token, data) }

diff(teamsMap, newInfo.teamList, TeamInfo::contestSystemId, TeamInfo::toClicsTeam, Event::TeamEvent)
diff(teamsMap, newInfo.teamList, { id }, TeamInfo::toClicsTeam) { id, token, data -> Event.TeamEvent(id.value, token, data) }

diffRemove(groupsMap, newInfo.groupList, { id }) { id, token, data -> Event.GroupsEvent(id.value, token, data) }
diffRemove(orgsMap, newInfo.organizationList, { id }) { id, token, data -> Event.OrganizationEvent(id.value, token, data) }
Expand All @@ -285,7 +282,7 @@ object ClicsExporter {
event.relativeTime,
event.message,
event.tags,
event.teamIds.map { teamIdToCdsId[it]!! },
event.teamIds.map { it.value },
emptyList(),
event.runIds.map { it.toString() }
),
Expand Down Expand Up @@ -460,7 +457,7 @@ object ClicsExporter {
val row = scoreboardSnapshot.rows[teamId]!!
ScoreboardRow(
rank,
info.teams[teamId]!!.contestSystemId,
teamId.value,
ScoreboardRowScore(row.totalScore.toInt(), row.penalty.inWholeMinutes),
row.problemResults.mapIndexed { index, v ->
val iv = v as ICPCProblemResult
Expand All @@ -478,15 +475,15 @@ object ClicsExporter {

private fun ScoreboardAndContestInfo.toClicsAwards() = buildList {
for (award in scoreboardSnapshot.awards) {
add(Award(award.id, award.citation, award.teams.map { info.teams[it]!!.contestSystemId }))
add(Award(award.id, award.citation, award.teams.map { it.value }))
}
for ((index, problem) in info.scoreboardProblems.withIndex()) {
add(Award(
"first-to-solve-${problem.id}",
"First to solve problem ${problem.displayName}",
scoreboardSnapshot.rows.entries
.filter { (it.value.problemResults[index] as? ICPCProblemResult)?.isFirstToSolve == true }
.map { info.teams[it.key]!!.contestSystemId }
.map { it.key.value }
))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object IcpcCsvExporter {
"institution"
)

fun TeamInfo.icpcId() = customFields["icpc_id"] ?: contestSystemId
fun TeamInfo.icpcId() = customFields["icpc_id"] ?: id.value

fun format(info: ContestInfo, runs: List<RunInfo>) : String {
if (info.resultType == ContestResultType.IOI) TODO("IOI is not supported yet")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ object PCMSExporter {

private fun Element.buildSessionNode(info: ContestInfo, teamInfo: TeamInfo, row: ScoreboardRow, runs: List<RunInfo>, awards: List<Award>) {
setAttribute("party", teamInfo.fullName)
setAttribute("id", teamInfo.contestSystemId)
setAttribute("id", teamInfo.id.value)
// setAttribute("time", "")
setAttribute("alias", teamInfo.contestSystemId)
setAttribute("alias", teamInfo.id.value)
setAttribute("penalty", row.penalty.inWholeMinutes.toString())
setAttribute("solved", row.totalScore.toInt().toString())
for (award in awards) {
Expand Down
Loading

0 comments on commit e58805f

Please sign in to comment.