Skip to content

Commit

Permalink
Move clics-api to separate module to avoid exposing it from cds modul…
Browse files Browse the repository at this point in the history
…e API
  • Loading branch information
kunyavskiy committed Sep 8, 2023
1 parent 4401865 commit 0d8ccc6
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 54 deletions.
23 changes: 17 additions & 6 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/cds-converter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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
Expand Down Expand Up @@ -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")
)
Expand Down
6 changes: 1 addition & 5 deletions src/cds/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 6 additions & 11 deletions src/cds/src/main/kotlin/org/icpclive/cds/clics/ClicsDataSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>) {
private val url = settings.url

Expand Down Expand Up @@ -137,9 +132,9 @@ internal class ClicsDataSource(val settings: ClicsSettings, creds: Map<String, S
}

is CommentaryEvent -> {
if (it.data != null) {
it.data?.let { comment ->
onComment(
model.processCommentary(it.data)
model.processCommentary(comment)
)
}
}
Expand Down Expand Up @@ -193,8 +188,8 @@ internal class ClicsDataSource(val settings: ClicsSettings, creds: Map<String, S
.mapNotNull { data ->
try {
when (settings.feedVersion) {
FeedVersion.`2020_03` -> Event.fromV1(jsonDecoder.decodeFromString(data))
FeedVersion.`2022_07` -> jsonDecoder.decodeFromString<Event>(data)
ClicsSettings.FeedVersion.`2020_03` -> Event.fromV1(jsonDecoder.decodeFromString(data))
ClicsSettings.FeedVersion.`2022_07` -> jsonDecoder.decodeFromString<Event>(data)
}
} catch (e: SerializationException) {
logger.error("Failed to deserialize: $data", e)
Expand Down
3 changes: 1 addition & 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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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<String, String>) = ClicsDataSource(this, creds)
Expand Down
5 changes: 2 additions & 3 deletions src/cds/src/test/kotlin/org/icpclive/cds/CdsLoadersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
)
)
}
Expand All @@ -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`
)
)
}
Expand Down
12 changes: 12 additions & 0 deletions src/clics-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.icpclive.cds.clics
package org.icpclive.clics

import kotlinx.datetime.*
import kotlinx.serialization.KSerializer
Expand Down Expand Up @@ -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<Duration> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("ClicsDuration", PrimitiveKind.STRING)
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T> {
val id: String
Expand Down Expand Up @@ -53,7 +53,8 @@ sealed class Event {

@Serializable
@SerialName("state")
data class StateEvent(override val token: String, override val data: State?) : UpdateContestEvent(), GlobalEvent<State>
data class StateEvent(override val token: String, override val data: State?) : UpdateContestEvent(),
GlobalEvent<State>

@Serializable
@SerialName("judgement-types")
Expand All @@ -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<Group>
UpdateContestEvent(), IdEvent<Group>

@Serializable
@SerialName("submissions")
Expand Down Expand Up @@ -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<Person>
data class PersonEvent(override val id: String, override val token: String, override val data: Person) : IgnoredEvent(),
IdEvent<Person>

@Serializable
@SerialName("map-info")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,7 +19,7 @@ data class ApiProvider(

@Serializable
data class ApiInfo(
val version: FeedVersion,
val version: String,
val versionUrl: String,
val provider: ApiProvider
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.icpclive.cds.clics
package org.icpclive.clics

import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
Expand Down

0 comments on commit 0d8ccc6

Please sign in to comment.