Skip to content

Commit

Permalink
Add the ability to override problem name in advanced.json
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyavskiy committed Aug 29, 2023
1 parent 17dbcb6 commit 0b68db0
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 47 deletions.
22 changes: 22 additions & 0 deletions config/_examples/_cms/advanced.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"problemOverrides": {
"SC2022CEOI13prize": {
"displayName": "A1"
},
"SC2022CEOI11abracadabra": {
"displayName": "B1"
},
"SC2022CEOI12homework": {
"displayName": "C1"
},
"SC2022CEOI22measures": {
"displayName": "A2"
},
"SC2022CEOI21drawing": {
"displayName": "B2"
},
"SC2022CEOI23parking": {
"displayName": "C2"
}
}
}
5 changes: 4 additions & 1 deletion schemas/advanced.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,10 @@
".*": {
"type": "object",
"properties": {
"name": {
"displayName": {
"type": "string"
},
"fullName": {
"type": "string"
},
"color": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class AnalyticsGenerator(jsonTemplatePath: Path) {
private fun getMessage(analyse: RunAnalyse, team: TeamInfo, problem: ProblemInfo): String {
val substitute = mapOf(
"{team.shortName}" to team.displayName,
"{problem.letter}" to problem.letter,
"{problem.name}" to problem.name,
"{problem.letter}" to problem.displayName,
"{problem.name}" to problem.fullName,
"{run.result}" to (analyse.run.result as? ICPCRunResult)?.verdict?.shortName.orEmpty(),
"{result.rank}" to analyse.result.rank.toString(),
"{result.solvedProblems}" to analyse.solvedProblems?.takeIf { it > 0 }?.toString().orEmpty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ typealias EventProducer = (String) -> Event
private fun ProblemInfo.toClicsProblem() = Problem(
id = contestSystemId,
ordinal = ordinal,
label = letter,
name = name,
label = displayName,
name = fullName,
rgb = color,
test_data_count = 1,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.icpclive.cds.ContestUpdate
import org.icpclive.cds.adapters.*
import org.icpclive.scoreboard.getScoreboardCalculator
import org.icpclive.util.createChild
import org.icpclive.util.getLogger
import org.w3c.dom.Element
import java.io.StringWriter
import javax.xml.parsers.DocumentBuilderFactory
Expand Down Expand Up @@ -58,8 +57,8 @@ object PCMSExporter {
private fun Element.buildChallengeNode(info: ContestInfo) {
info.scoreboardProblems.forEach { problem ->
createChild("problem").also {
it.setAttribute("alias", problem.letter)
it.setAttribute("name", problem.name)
it.setAttribute("alias", problem.displayName)
it.setAttribute("name", problem.fullName)
}
}
}
Expand Down Expand Up @@ -87,7 +86,7 @@ object PCMSExporter {
probNode.setAttribute("accepted", isAcceptedInt.toString())
probNode.setAttribute("attempts", (probResult.wrongAttempts + isAcceptedInt).toString())
probNode.setAttribute("id", info.scoreboardProblems[index].contestSystemId)
probNode.setAttribute("alias", info.scoreboardProblems[index].letter)
probNode.setAttribute("alias", info.scoreboardProblems[index].displayName)
probNode.setAttribute("time", (probResult.lastSubmitTime ?: Duration.ZERO).inWholeMilliseconds.toString())
probNode.setAttribute("penalty", (if (probResult.isSolved) {
(probResult.lastSubmitTime!! + info.penaltyPerWrongAttempt * probResult.wrongAttempts).inWholeMinutes
Expand Down
4 changes: 2 additions & 2 deletions src/cds/src/main/kotlin/org/icpclive/api/ContestInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ enum class ScoreMergeMode {

@Serializable
data class ProblemInfo(
val letter: String,
val name: String,
@SerialName("letter") val displayName: String,
@SerialName("name") val fullName: String,
val id: Int,
val ordinal: Int,
val contestSystemId: String,
Expand Down
14 changes: 9 additions & 5 deletions src/cds/src/main/kotlin/org/icpclive/api/tunning/Advanced.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ data class TeamInfoOverride(
)

/**
* @param name Problem name.
* @param displayName Name to show in scoreboard and queue.
* @param fullName Problem name.
* @param color Color of a problem balloon. It would be shown in queue and scoreboard in places related to the problem
* @param ordinal Number to sort problems in the scoreboard
* @param minScore In ioi mode minimal possible value of points in this problem
* @param maxScore In ioi mode maximal possible value of points in this problem
* @param scoreMergeMode In ioi mode, select the ruleset to calculate final score based on the scores for each submission.
* @param scoreMergeMode In ioi mode, select the ruleset to calculate the final score based on the scores for each submission.
*/
@OptIn(ExperimentalSerializationApi::class)
@Serializable
data class ProblemInfoOverride(
val name: String? = null,
val displayName: String? = null,
val fullName: String? = null,
@Serializable(ColorSerializer::class) val color: Color? = null,
val ordinal: Int? = null,
val minScore: Double? = null,
Expand Down Expand Up @@ -208,8 +211,9 @@ fun ContestInfo.toAdvancedProperties(fields: Set<String>) : AdvancedProperties {
)
},
problemOverrides = problemList.associate {
it.letter to ProblemInfoOverride(
name = it.name.takeIfAsked("problemName"),
it.contestSystemId to ProblemInfoOverride(
displayName = it.displayName.takeIfAsked("problemDisplayName"),
fullName = it.fullName.takeIfAsked("problemFullName"),
color = it.color.takeIfAsked("color"),
ordinal = it.ordinal.takeIfAsked("ordinal"),
minScore = it.minScore.takeIfAsked("minScore"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ private fun mergeProblems(
) = mergeOverrides(
problems,
overrides,
ProblemInfo::letter,
ProblemInfo::contestSystemId,
unusedMessage = { "No problem for override: $it" }
) { problem, override ->
ProblemInfo(
letter = problem.letter,
name = override.name ?: problem.name,
displayName = override.displayName ?: problem.displayName,
fullName = override.fullName ?: problem.fullName,
id = problem.id,
ordinal = override.ordinal ?: problem.ordinal,
contestSystemId = problem.contestSystemId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.icpclive.cds.common.FullReloadContestDataSource
import org.icpclive.cds.common.jsonLoader
import org.icpclive.cds.settings.AtcoderSettings
import org.icpclive.util.*
import kotlin.time.Duration
import kotlin.time.Duration.Companion.ZERO
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.nanoseconds
Expand Down Expand Up @@ -86,8 +85,8 @@ internal class AtcoderDataSource(val settings: AtcoderSettings) : FullReloadCont
val data = loader.load()
val problems = data.TaskInfo.mapIndexed { index, task ->
ProblemInfo(
letter = task.Assignment,
name = task.TaskName,
displayName = task.Assignment,
fullName = task.TaskName,
id = problemIds[task.TaskScreenName],
ordinal = index,
contestSystemId = task.TaskScreenName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ internal class CATSDataSource(val settings: CatsSettings, creds: Map<String, Str
.asSequence()
.mapIndexed { index, problem ->
ProblemInfo(
letter = problem.code,
name = problem.name,
displayName = problem.code,
fullName = problem.name,
color = null,
id = problem.id,
ordinal = index,
Expand Down
4 changes: 2 additions & 2 deletions src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ internal class ClicsModel(
}

private fun Problem.toApi() = ProblemInfo(
letter = label,
name = name,
displayName = label,
fullName = name,
id = problemToId[id],
ordinal = ordinal,
contestSystemId = id,
Expand Down
4 changes: 2 additions & 2 deletions src/cds/src/main/kotlin/org/icpclive/cds/cms/CmsDataSoruce.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ internal class CmsDataSource(val settings: CmsSettings) : FullReloadContestDataS
val problems = tasksLoader.load().entries.groupBy { it.value.contest }.mapValues {
it.value.map { (k, v) ->
ProblemInfo(
letter = v.short_name,
name = v.name,
displayName = v.short_name,
fullName = v.name,
id = problemId[k],
contestSystemId = k,
ordinal = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ internal class CodeDrillsDataSource(val settings: CodeDrillsSettings, creds: Map
val contest = scoreboard.scoreboard.contest
val problems = scoreboard.scoreboard.problemList.mapIndexed { index, problem ->
ProblemInfo(
letter = problem.index,
name = problem.title,
displayName = problem.index,
fullName = problem.title,
id = problem.id,
contestSystemId = problem.id.toString(),
ordinal = index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ internal class CFContestInfo {
if (problemsMap.isEmpty() && standings.problems.isNotEmpty()) {
for ((id, problem) in standings.problems.withIndex()) {
val problemInfo = ProblemInfo(
letter = problem.index,
name = problem.name!!,
displayName = problem.index,
fullName = problem.name!!,
id = id,
ordinal = id,
contestSystemId = id.toString(),
Expand All @@ -59,16 +59,16 @@ internal class CFContestInfo {
}
if (contestType == CFContestType.CF) {
val hacksInfo = ProblemInfo(
letter = "*",
name = "Hacks",
displayName = "*",
fullName = "Hacks",
id = -1,
ordinal = -1,
contestSystemId = "hacks",
minScore = null,
maxScore = null,
scoreMergeMode = ScoreMergeMode.SUM,
)
problemsMap[hacksInfo.letter] = hacksInfo
problemsMap[hacksInfo.displayName] = hacksInfo
problems.add(hacksInfo)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ internal class EjudgeDataSource(val settings: EjudgeSettings) : FullReloadContes
.child("problems")
.children().mapIndexed { index, element ->
ProblemInfo(
letter = element.getAttribute("short_name"),
name = element.getAttribute("long_name"),
displayName = element.getAttribute("short_name"),
fullName = element.getAttribute("long_name"),
id = element.getAttribute("id").toInt(),
ordinal = index,
contestSystemId = element.getAttribute("id"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ internal class KRSUDataSource(val settings: KRSUSettings) : FullReloadContestDat

val problemsList = contest.ProblemSet.mapIndexed { index, it ->
ProblemInfo(
letter = "" + ('A' + index),
name = "" + ('A' + index),
displayName = "" + ('A' + index),
fullName = "" + ('A' + index),
id = it.Problem,
ordinal = index,
contestSystemId = index.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ internal class PCMSDataSource(val settings: PCMSSettings, creds: Map<String, Str
.children("problem")
.mapIndexed { index, it ->
ProblemInfo(
letter = it.getAttribute("alias"),
name = it.getAttribute("name"),
displayName = it.getAttribute("alias"),
fullName = it.getAttribute("name"),
id = problemIds[it.getAttribute("alias")],
ordinal = index,
contestSystemId = it.getAttribute("id").takeIf { it.isNotEmpty() } ?: it.getAttribute("alias"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ internal class TestSysDataSource(val settings: TestSysSettings) : FullReloadCont
val problemsWithPenalty = (data["@p"] ?: emptyList()).mapIndexed { index, prob ->
val (letter, name, penalty) = prob.splitCommas()
ProblemInfo(
letter = letter,
name = name,
displayName = letter,
fullName = name,
id = index,
ordinal = index,
contestSystemId = letter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

private fun Problem.toApi(index:Int, resultType: ContestResultType) = ProblemInfo(
letter = alias,
name = name,
displayName = alias,
fullName = name,
id = index,
ordinal = index,
contestSystemId = id,
Expand Down Expand Up @@ -46,7 +46,7 @@ internal class YandexContestInfo private constructor(
)

fun submissionToRun(submission: Submission): RunInfo {
val problemId = problems.indexOfFirst { it.letter == submission.problemAlias }
val problemId = problems.indexOfFirst { it.displayName == submission.problemAlias }
if (problemId == -1) {
throw IllegalStateException("Problem not found: ${submission.problemAlias}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Bot(private val config: Config) {
val ci = runBlocking { contestInfo.await().value }
ci.teams[reaction.teamId]?.let { team ->
ci.problems[reaction.problemId]?.let { problem ->
caption = "${team.fullName}, problem ${problem.letter}"
caption = "${team.fullName}, problem ${problem.displayName}"
}
}
}
Expand Down

0 comments on commit 0b68db0

Please sign in to comment.