Skip to content

Commit

Permalink
Add name property to AdditionalProblemProperties on backend
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmusin committed Mar 18, 2024
1 parent b469f82 commit 6986307
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ import io.github.jvmusin.polybacs.api.StatementFormat.PDF
* @param statementFormat format of the statement, actually `PDF` or `HTML`.
*/
data class AdditionalProblemProperties(
val prefix: String? = null,
val name: String,
val prefix: String? = null, // TODO: Drop nullability; drop whole concept?
val suffix: String? = null,
val timeLimitMillis: Int? = null,
val memoryLimitMegabytes: Int? = null,
val statementFormat: StatementFormat = PDF
) {
companion object {
/** Do not add any prefix/suffix and use problem's default time and memory limits. */
val defaultProperties = AdditionalProblemProperties()
}

/** Build problem name prefixing it with [prefix] and suffixing with [suffix] if they are not `null`. */
fun buildFullName(problemName: String) = "${prefix.orEmpty()}$problemName${suffix.orEmpty()}"
fun buildFullName() = "${prefix.orEmpty()}$name${suffix.orEmpty()}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ class BacsArchiveService(
/** Uploads [problem] to Bacs archive with extra [properties]. */
suspend fun uploadProblem(
problem: IRProblem,
properties: AdditionalProblemProperties = AdditionalProblemProperties.defaultProperties,
properties: AdditionalProblemProperties = AdditionalProblemProperties(problem.name),
): String {
val zip = problem.toZipArchive(properties)
uploadProblem(zip)
val fullName = properties.buildFullName(problem.name)
val fullName = properties.buildFullName()
val state = waitTillProblemIsImported(fullName)
if (state != BacsProblemState.IMPORTED)
throw BacsProblemUploadException("Задача $fullName не импортирована, статус $state")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class SolutionsController(
@RequestMapping("/createTestProblem")
fun createTestProblem(@PathVariable problemId: Int, session: HttpSession) =
offloadScope.launch(exceptionHandler("create test problem", session)) {
val properties = AdditionalProblemProperties(suffix = "-test")
val fullName = properties.buildFullName(polygonService.downloadProblem(problemId).name)
val problemName = polygonService.downloadProblem(problemId).name
val properties = AdditionalProblemProperties(name = problemName, suffix = "-test")
val fullName = properties.buildFullName()

val toastSender = webSocketConnectionKeeper.createSender(session.id)
transferProblemToBacs(toastSender, problemId, properties, false, polygonService, bacsArchiveService)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.jvmusin.polybacs.sybon

import io.github.jvmusin.polybacs.api.AdditionalProblemProperties
import io.github.jvmusin.polybacs.api.AdditionalProblemProperties.Companion.defaultProperties
import io.github.jvmusin.polybacs.ir.IRProblem
import io.github.jvmusin.polybacs.util.toZipArchive
import java.nio.file.Path
Expand All @@ -16,8 +15,8 @@ import kotlin.io.path.writeText
*
* @return file where the zip is located.
*/
fun IRProblem.toZipArchive(properties: AdditionalProblemProperties = defaultProperties): Path {
val fullName = properties.buildFullName(name)
fun IRProblem.toZipArchive(properties: AdditionalProblemProperties = AdditionalProblemProperties(name)): Path {
val fullName = properties.buildFullName()
val destinationPath = Paths.get(
"sybon-packages",
"$fullName-${UUID.randomUUID()}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ class SybonSpecialCollectionTests(
) : StringSpec({
val specialCollectionId = 10023
val polygonProblemId = 147360
val properties = AdditionalProblemProperties(
fun properties(problemName: String) = AdditionalProblemProperties(
name = problemName,
suffix = LocalDateTime.now().format(
DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss")
) + "-polybacs-test-rustam"
)

"Full cycle" {
val irProblem = polygonService.downloadProblem(polygonProblemId, includeTests = true)
val fullName = bacsArchiveService.uploadProblem(irProblem, properties)
val fullName = bacsArchiveService.uploadProblem(irProblem, properties(irProblem.name))
println("Problem full name: $fullName")
delay(2.minutes) // wait for the problem to appear in the archive
val sybonProblemId = repeat(3.minutes, 10.seconds) {
Expand Down

0 comments on commit 6986307

Please sign in to comment.