diff --git a/settings.gradle.kts b/settings.gradle.kts index 35111b503..07d08c6e3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,15 +16,26 @@ dependencyResolutionManagement { enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") -include(":sniper-tools", ":reactions-bot", ":common", ":cds", ":frontend", ":backend", ":cds-converter", ":schema-generator") -project(":sniper-tools").projectDir = file("src/sniper-tools") -project(":common").projectDir = file("src/common") -project(":reactions-bot").projectDir = file("src/reactions-bot") -project(":cds").projectDir = file("src/cds") -project(":frontend").projectDir = file("src/frontend") +include( + ":backend", + ":cds", + ":cds-converter", + ":clics-api", + ":common", + ":frontend", + ":reactions-bot", + ":schema-generator", + ":sniper-tools", +) project(":backend").projectDir = file("src/backend") +project(":cds").projectDir = file("src/cds") project(":cds-converter").projectDir = file("src/cds-converter") +project(":clics-api").projectDir = file("src/clics-api") +project(":common").projectDir = file("src/common") +project(":frontend").projectDir = file("src/frontend") +project(":reactions-bot").projectDir = file("src/reactions-bot") project(":schema-generator").projectDir = file("src/schema-generator") +project(":sniper-tools").projectDir = file("src/sniper-tools") gradleEnterprise.buildScan { termsOfServiceUrl = "https://gradle.com/terms-of-service" diff --git a/src/cds-converter/build.gradle.kts b/src/cds-converter/build.gradle.kts index 981e8dea3..9d81a9d28 100644 --- a/src/cds-converter/build.gradle.kts +++ b/src/cds-converter/build.gradle.kts @@ -31,6 +31,7 @@ tasks.runTask { dependencies { implementation(projects.cds) implementation(projects.common) + implementation(projects.clicsApi) implementation(libs.cli) implementation(libs.ktor.serialization.kotlinx.json) implementation(libs.ktor.server.autoHeadResponse) diff --git a/src/cds-converter/src/main/kotlin/org/icpclive/export/clics/ClicsExporter.kt b/src/cds-converter/src/main/kotlin/org/icpclive/export/clics/ClicsExporter.kt index 6899dee0f..5168af1e9 100644 --- a/src/cds-converter/src/main/kotlin/org/icpclive/export/clics/ClicsExporter.kt +++ b/src/cds-converter/src/main/kotlin/org/icpclive/export/clics/ClicsExporter.kt @@ -2,7 +2,7 @@ import io.ktor.server.application.* import io.ktor.server.response.* import io.ktor.server.routing.* import kotlinx.collections.immutable.persistentMapOf -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.* import kotlinx.datetime.Instant import kotlinx.serialization.* @@ -12,11 +12,9 @@ import org.icpclive.api.* import org.icpclive.cds.* import org.icpclive.cds.adapters.stateGroupedByTeam import org.icpclive.cds.adapters.withContestInfoBefore -import org.icpclive.cds.clics.FeedVersion - -import org.icpclive.cds.clics.api.* -import org.icpclive.cds.clics.api.Scoreboard -import org.icpclive.cds.clics.api.ScoreboardRow +import org.icpclive.clics.* +import org.icpclive.clics.Scoreboard +import org.icpclive.clics.ScoreboardRow import org.icpclive.scoreboard.calculateScoreboardWithInfo import org.icpclive.util.defaultJsonSettings import org.icpclive.util.intervalFlow @@ -393,7 +391,7 @@ object ClicsExporter { get { call.respond( ApiInfo( - FeedVersion.`2022_07`, + "2022_07", "https://ccs-specs.icpc.io/2022-07/contest_api", ApiProvider("icpc live") ) diff --git a/src/cds/build.gradle.kts b/src/cds/build.gradle.kts index 25e445ba9..bb395d60a 100644 --- a/src/cds/build.gradle.kts +++ b/src/cds/build.gradle.kts @@ -38,11 +38,6 @@ tasks { dokkaHtml { moduleName.set("ICPC-live contest data parser") dokkaSourceSets.configureEach { - // should be moved to another package, as reused by exporter - perPackageOption { - matchingRegex.set("org.icpclive.cds.clics.*") - suppress.set(true) - } perPackageOption { matchingRegex.set(".*") reportUndocumented.set(true) @@ -63,6 +58,7 @@ tasks { dependencies { api(libs.kotlinx.collections.immutable) implementation(projects.common) + implementation(projects.clicsApi) implementation(libs.grpc.protobuf) implementation(libs.grpc.stub) implementation(libs.kotlin.reflect) diff --git a/src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsDataSource.kt b/src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsDataSource.kt index 843dc456e..840a43a90 100644 --- a/src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsDataSource.kt +++ b/src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsDataSource.kt @@ -7,19 +7,14 @@ import kotlinx.serialization.SerializationException import kotlinx.serialization.json.Json import org.icpclive.api.* import org.icpclive.cds.* -import org.icpclive.cds.clics.api.Event -import org.icpclive.cds.clics.api.Event.* +import org.icpclive.clics.Event +import org.icpclive.clics.Event.* import org.icpclive.cds.common.* import org.icpclive.cds.settings.* import org.icpclive.util.getLogger import org.icpclive.util.logAndRetryWithDelay import kotlin.time.Duration.Companion.seconds -enum class FeedVersion { - `2020_03`, - `2022_07` -} - private class ParsedClicsLoaderSettings(settings: ClicsLoaderSettings, creds: Map) { private val url = settings.url @@ -137,9 +132,9 @@ internal class ClicsDataSource(val settings: ClicsSettings, creds: Map { - if (it.data != null) { + it.data?.let { comment -> onComment( - model.processCommentary(it.data) + model.processCommentary(comment) ) } } @@ -193,8 +188,8 @@ internal class ClicsDataSource(val settings: ClicsSettings, creds: Map try { when (settings.feedVersion) { - FeedVersion.`2020_03` -> Event.fromV1(jsonDecoder.decodeFromString(data)) - FeedVersion.`2022_07` -> jsonDecoder.decodeFromString(data) + ClicsSettings.FeedVersion.`2020_03` -> Event.fromV1(jsonDecoder.decodeFromString(data)) + ClicsSettings.FeedVersion.`2022_07` -> jsonDecoder.decodeFromString(data) } } catch (e: SerializationException) { logger.error("Failed to deserialize: $data", e) diff --git a/src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsModel.kt b/src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsModel.kt index 9cb2a044d..9483ad67d 100644 --- a/src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsModel.kt +++ b/src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsModel.kt @@ -2,8 +2,7 @@ package org.icpclive.cds.clics import kotlinx.datetime.Instant import org.icpclive.api.* -import org.icpclive.cds.clics.api.* -import org.icpclive.cds.clics.api.Organization +import org.icpclive.clics.* import org.icpclive.cds.clics.model.* import org.icpclive.util.Enumerator import org.icpclive.util.getLogger diff --git a/src/cds/src/main/kotlin/org/icpclive/cds/clics/model/ClicsRunInfo.kt b/src/cds/src/main/kotlin/org/icpclive/cds/clics/model/ClicsRunInfo.kt index d296bd67b..26bc4e5d9 100644 --- a/src/cds/src/main/kotlin/org/icpclive/cds/clics/model/ClicsRunInfo.kt +++ b/src/cds/src/main/kotlin/org/icpclive/cds/clics/model/ClicsRunInfo.kt @@ -2,7 +2,7 @@ package org.icpclive.cds.clics.model import org.icpclive.api.MediaType import org.icpclive.api.Verdict -import org.icpclive.cds.clics.api.Problem +import org.icpclive.clics.Problem import kotlin.time.Duration internal class ClicsRunInfo( @@ -27,9 +27,9 @@ internal class ClicsRunInfo( }, problemId = liveProblemId, teamId = teamId, - percentage = when (problem.test_data_count) { + percentage = when (val count = problem.test_data_count) { null, 0 -> if (judgementType != null) 1.0 else 0.0 - else -> minOf(passedCaseRun.size.toDouble() / problem.test_data_count, 1.0) + else -> minOf(passedCaseRun.size.toDouble() / count, 1.0) }, time = submissionTime, reactionVideos = reactionVideos, diff --git a/src/cds/src/main/kotlin/org/icpclive/cds/cms/CmsDataSoruce.kt b/src/cds/src/main/kotlin/org/icpclive/cds/cms/CmsDataSoruce.kt index 40f175e29..b75c146ff 100644 --- a/src/cds/src/main/kotlin/org/icpclive/cds/cms/CmsDataSoruce.kt +++ b/src/cds/src/main/kotlin/org/icpclive/cds/cms/CmsDataSoruce.kt @@ -1,7 +1,6 @@ package org.icpclive.cds.cms import org.icpclive.api.* -import org.icpclive.cds.clics.api.Media import org.icpclive.cds.cms.model.* import org.icpclive.cds.common.ContestParseResult import org.icpclive.cds.common.FullReloadContestDataSource diff --git a/src/cds/src/main/kotlin/org/icpclive/cds/settings/CDSSettings.kt b/src/cds/src/main/kotlin/org/icpclive/cds/settings/CDSSettings.kt index c09795f53..e6f94fa1d 100644 --- a/src/cds/src/main/kotlin/org/icpclive/cds/settings/CDSSettings.kt +++ b/src/cds/src/main/kotlin/org/icpclive/cds/settings/CDSSettings.kt @@ -16,7 +16,6 @@ import org.icpclive.cds.adapters.toEmulationFlow import org.icpclive.cds.atcoder.AtcoderDataSource import org.icpclive.cds.cats.CATSDataSource import org.icpclive.cds.clics.ClicsDataSource -import org.icpclive.cds.clics.FeedVersion import org.icpclive.cds.cms.CmsDataSource import org.icpclive.cds.codedrills.CodeDrillsDataSource import org.icpclive.cds.codeforces.CFDataSource @@ -191,7 +190,7 @@ class ClicsLoaderSettings( val login: Credential? = null, val password: Credential? = null, val eventFeedName: String = "event-feed", - val feedVersion: FeedVersion = FeedVersion.`2022_07` + val feedVersion: ClicsSettings.FeedVersion = ClicsSettings.FeedVersion.`2022_07` ) @SerialName("clics") @@ -208,6 +207,11 @@ class ClicsSettings( override val emulation: EmulationSettings? = null, override val network: NetworkSettings? = null, ) : CDSSettings() { + public enum class FeedVersion { + `2020_03`, + `2022_07` + } + val mainFeed get() = ClicsLoaderSettings(url,login, password, eventFeedName, feedVersion) override fun toDataSource(creds: Map) = ClicsDataSource(this, creds) diff --git a/src/cds/src/test/kotlin/org/icpclive/cds/CdsLoadersTest.kt b/src/cds/src/test/kotlin/org/icpclive/cds/CdsLoadersTest.kt index f66c0e4a0..b32a87966 100644 --- a/src/cds/src/test/kotlin/org/icpclive/cds/CdsLoadersTest.kt +++ b/src/cds/src/test/kotlin/org/icpclive/cds/CdsLoadersTest.kt @@ -8,7 +8,6 @@ import org.icpclive.api.ContestResultType import org.icpclive.api.tunning.* import org.icpclive.cds.adapters.applyAdvancedProperties import org.icpclive.cds.adapters.finalContestState -import org.icpclive.cds.clics.FeedVersion import org.icpclive.cds.common.ContestParseResult import org.icpclive.cds.settings.* import org.opentest4j.AssertionFailedError @@ -59,7 +58,7 @@ object CdsLoadersTest { goldenDataDir.resolve("clics202003.txt"), ClicsSettings( url = "testData/loaders/clics-2020-03", - feedVersion = FeedVersion.`2020_03` + feedVersion = ClicsSettings.FeedVersion.`2020_03` ) ) } @@ -70,7 +69,7 @@ object CdsLoadersTest { goldenDataDir.resolve("clics202207.txt"), ClicsSettings( url = "testData/loaders/clics-2022-07", - feedVersion = FeedVersion.`2022_07` + feedVersion = ClicsSettings.FeedVersion.`2022_07` ) ) } diff --git a/src/clics-api/build.gradle.kts b/src/clics-api/build.gradle.kts new file mode 100644 index 000000000..66f391129 --- /dev/null +++ b/src/clics-api/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + `java-library` + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.kotlin.serialization) +} + +dependencies { + api(libs.kotlinx.serialization.json) + api(libs.kotlinx.datetime) + api(projects.common) + testImplementation(libs.kotlin.junit) +} \ No newline at end of file diff --git a/src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsTime.kt b/src/clics-api/src/main/kotlin/org/icpclive/clics/ClicsTime.kt similarity index 98% rename from src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsTime.kt rename to src/clics-api/src/main/kotlin/org/icpclive/clics/ClicsTime.kt index bb16cb169..a72a46428 100644 --- a/src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsTime.kt +++ b/src/clics-api/src/main/kotlin/org/icpclive/clics/ClicsTime.kt @@ -1,4 +1,4 @@ -package org.icpclive.cds.clics +package org.icpclive.clics import kotlinx.datetime.* import kotlinx.serialization.KSerializer @@ -93,7 +93,9 @@ internal object ClicsTime { } val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX") - fun formatIso(instant: Instant) = Instant.fromEpochMilliseconds(instant.toEpochMilliseconds()).toJavaInstant().atZone(ZoneId.systemDefault()).format(formatter) + fun formatIso(instant: Instant) = Instant.fromEpochMilliseconds(instant.toEpochMilliseconds()).toJavaInstant().atZone(ZoneId.systemDefault()).format( + formatter + ) object DurationSerializer : KSerializer { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("ClicsDuration", PrimitiveKind.STRING) diff --git a/src/cds/src/main/kotlin/org/icpclive/cds/clics/api/Events.kt b/src/clics-api/src/main/kotlin/org/icpclive/clics/Events.kt similarity index 95% rename from src/cds/src/main/kotlin/org/icpclive/cds/clics/api/Events.kt rename to src/clics-api/src/main/kotlin/org/icpclive/clics/Events.kt index 53f64b990..b80e9a777 100644 --- a/src/cds/src/main/kotlin/org/icpclive/cds/clics/api/Events.kt +++ b/src/clics-api/src/main/kotlin/org/icpclive/clics/Events.kt @@ -1,8 +1,8 @@ -package org.icpclive.cds.clics.api +package org.icpclive.clics import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import org.icpclive.cds.clics.api.v1.Event as EventV1 +import org.icpclive.clics.v1.Event as EventV1 interface IdEvent { val id: String @@ -53,7 +53,8 @@ sealed class Event { @Serializable @SerialName("state") - data class StateEvent(override val token: String, override val data: State?) : UpdateContestEvent(), GlobalEvent + data class StateEvent(override val token: String, override val data: State?) : UpdateContestEvent(), + GlobalEvent @Serializable @SerialName("judgement-types") @@ -63,7 +64,7 @@ sealed class Event { @Serializable @SerialName("groups") data class GroupsEvent(override val id: String, override val token: String, override val data: Group?) : - UpdateContestEvent(),IdEvent + UpdateContestEvent(), IdEvent @Serializable @SerialName("submissions") @@ -107,7 +108,8 @@ sealed class Event { @Serializable @SerialName("persons") - data class PersonEvent(override val id: String, override val token: String, override val data: Person) : IgnoredEvent(), IdEvent + data class PersonEvent(override val id: String, override val token: String, override val data: Person) : IgnoredEvent(), + IdEvent @Serializable @SerialName("map-info") diff --git a/src/cds/src/main/kotlin/org/icpclive/cds/clics/api/Objects.kt b/src/clics-api/src/main/kotlin/org/icpclive/clics/Objects.kt similarity index 97% rename from src/cds/src/main/kotlin/org/icpclive/cds/clics/api/Objects.kt rename to src/clics-api/src/main/kotlin/org/icpclive/clics/Objects.kt index 0757449e9..e4d97c3df 100644 --- a/src/cds/src/main/kotlin/org/icpclive/cds/clics/api/Objects.kt +++ b/src/clics-api/src/main/kotlin/org/icpclive/clics/Objects.kt @@ -1,12 +1,10 @@ @file:Suppress("UNUSED") -package org.icpclive.cds.clics.api +package org.icpclive.clics import kotlinx.datetime.Instant import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import org.icpclive.cds.clics.ClicsTime -import org.icpclive.cds.clics.FeedVersion import org.icpclive.util.ColorSerializer import org.icpclive.util.DurationInMinutesSerializer import java.awt.Color @@ -21,7 +19,7 @@ data class ApiProvider( @Serializable data class ApiInfo( - val version: FeedVersion, + val version: String, val versionUrl: String, val provider: ApiProvider ) diff --git a/src/cds/src/main/kotlin/org/icpclive/cds/clics/api/v1/Events.kt b/src/clics-api/src/main/kotlin/org/icpclive/clics/v1/Events.kt similarity index 97% rename from src/cds/src/main/kotlin/org/icpclive/cds/clics/api/v1/Events.kt rename to src/clics-api/src/main/kotlin/org/icpclive/clics/v1/Events.kt index 3445d46d9..d78def228 100644 --- a/src/cds/src/main/kotlin/org/icpclive/cds/clics/api/v1/Events.kt +++ b/src/clics-api/src/main/kotlin/org/icpclive/clics/v1/Events.kt @@ -1,8 +1,8 @@ -package org.icpclive.cds.clics.api.v1 +package org.icpclive.clics.v1 import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import org.icpclive.cds.clics.api.* +import org.icpclive.clics.* @Serializable sealed class Event { diff --git a/src/cds/src/test/kotlin/org/icpclive/cds/clics/ClicksTimeTest.kt b/src/clics-api/src/test/kotlin/org/icpclive/clics/ClicksTimeTest.kt similarity index 99% rename from src/cds/src/test/kotlin/org/icpclive/cds/clics/ClicksTimeTest.kt rename to src/clics-api/src/test/kotlin/org/icpclive/clics/ClicksTimeTest.kt index 9454a8345..f4db20056 100644 --- a/src/cds/src/test/kotlin/org/icpclive/cds/clics/ClicksTimeTest.kt +++ b/src/clics-api/src/test/kotlin/org/icpclive/clics/ClicksTimeTest.kt @@ -1,4 +1,4 @@ -package org.icpclive.cds.clics +package org.icpclive.clics import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString