Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more relaxed about matching attempt-only Activities #686

Merged
merged 2 commits into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,28 +274,16 @@ object WCIFScrambleMatcher {

val actGroup = activity.activityCode.groupNumber

// uh oh. no child activities where there should be some.
// uh oh. no child activities where there should be some. Resort to creating them ourselves…
if (actGroup == null) {
val actAttempt = activity.activityCode.attemptNumber
val inventedChildren = List(matchedRound.scrambleSetCount) {
val copiedActCode = activity.activityCode.copyParts(groupNumber = it)
val childSetId = matchedRound.scrambleSets[it].id

// resort to creating them ourselves…
if (actAttempt == null) {
val inventedChildren = List(matchedRound.scrambleSetCount) {
val copiedActCode = activity.activityCode.copyParts(groupNumber = it)
val childSetId = matchedRound.scrambleSets[it].id

activity.copy(id = ID_PENDING, activityCode = copiedActCode, childActivities = listOf(), scrambleSetId = childSetId)
}

return activity.copy(childActivities = inventedChildren)
}

if (matchedRound.scrambleSetCount > 1) {
ScrambleMatchingException.error("Attempt-only specification ${activity.activityCode} for activity ${activity.id} is impossible to match")
activity.copy(id = ID_PENDING, activityCode = copiedActCode, childActivities = listOf(), scrambleSetId = childSetId)
}

val onlyPossibleSet = matchedRound.scrambleSets.single()
return activity.copy(scrambleSetId = onlyPossibleSet.id)
return activity.copy(childActivities = inventedChildren)
}

// manually compensating for https://github.com/thewca/worldcubeassociation.org/issues/4653
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.worldcubeassociation.tnoodle.server.webscrambles

import kotlinx.coroutines.*
import kotlinx.serialization.builtins.ListSerializer
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.function.ThrowingSupplier
import org.worldcubeassociation.tnoodle.server.serial.JsonConfig
import org.worldcubeassociation.tnoodle.server.model.EventData
import org.worldcubeassociation.tnoodle.server.serial.JsonConfig
import org.worldcubeassociation.tnoodle.server.webscrambles.wcif.UpcomingCompetition
import org.worldcubeassociation.tnoodle.server.webscrambles.wcif.WCIFDataBuilder
import org.worldcubeassociation.tnoodle.server.webscrambles.wcif.WCIFScrambleMatcher
Expand All @@ -16,46 +17,44 @@ import java.time.LocalDateTime
import kotlin.random.Random
import kotlin.system.measureTimeMillis

object APIIntegrationTest {
class APIIntegrationTest {
@Test
fun `test that every upcoming competition produces some output without error`() {
val competitionsLimit = 10
val upcomingRaw = URL("https://www.worldcubeassociation.org/api/v0/competitions/").readText()
val upcomingComps = JsonConfig.SERIALIZER.decodeFromString(ListSerializer(UpcomingCompetition.serializer()), upcomingRaw).shuffled().take(competitionsLimit)
fun `test that every upcoming competition produces some output without error`() = runBlocking {
val upcomingRaw = withContext(Dispatchers.IO) { URL("https://www.worldcubeassociation.org/api/v0/competitions/").readText() }
val upcomingComps = JsonConfig.SERIALIZER.decodeFromString(ListSerializer(UpcomingCompetition.serializer()), upcomingRaw).shuffled()

val generationDate = LocalDateTime.now()
val testCompCount = upcomingComps.size

for ((i, upcomingComp) in upcomingComps.withIndex()) {
val id = upcomingComp.id
println("(${i+1}/$testCompCount) Testing ZIP builder for '${upcomingComp.name}' (id $id)")
val jobs = upcomingComps.map { it.id }.map {
launch(Dispatchers.Default) {
val url = "https://www.worldcubeassociation.org/api/v0/competitions/$it/wcif/public"

val url = "https://www.worldcubeassociation.org/api/v0/competitions/$id/wcif/public"
val wcifRaw = withContext(Dispatchers.IO) { URL(url).readText() }
val multiCubes = MultiScrambleCountExtension(Random.nextInt(10, 20))

val wcifRaw = URL(url).readText()
val multiCubes = MultiScrambleCountExtension(Random.nextInt(10, 20))
val websiteWcif = JsonConfig.SERIALIZER.decodeFromString(Competition.serializer(), wcifRaw)
val blankWcif = WCIFScrambleMatcher.installExtensionForEvents(websiteWcif, multiCubes, EventData.THREE_MULTI_BLD)

val websiteWcif = JsonConfig.SERIALIZER.decodeFromString(Competition.serializer(), wcifRaw)
val blankWcif = WCIFScrambleMatcher.installExtensionForEvents(websiteWcif, multiCubes, EventData.THREE_MULTI_BLD)
println("[$it] Fetched WCIF. On to computing scrambles…")
val scrambledWcif = WCIFScrambleMatcher.fillScrambleSets(blankWcif)

println("Fetched WCIF. On to computing scrambles…")
val scrambledWcif = WCIFScrambleMatcher.fillScrambleSets(blankWcif)
println("[$it] Scrambles generated successfully. On to rendering the PDF…")
val completePdf = WCIFDataBuilder.wcifToCompletePdf(scrambledWcif, generationDate.toLocalDate(), "JUnit-Test", Translate.DEFAULT_LOCALE)
val renderedPdf = Assertions.assertDoesNotThrow(ThrowingSupplier { completePdf.render() })
Assertions.assertTrue(renderedPdf.isNotEmpty())

println("Scrambles generated successfully. On to rendering the PDF…")
val completePdf = WCIFDataBuilder.wcifToCompletePdf(scrambledWcif, generationDate.toLocalDate(), "JUnit-Test", Translate.DEFAULT_LOCALE)
val renderedPdf = Assertions.assertDoesNotThrow(ThrowingSupplier { completePdf.render() })
Assertions.assertTrue(renderedPdf.isNotEmpty())
val computationTime = measureTimeMillis {
println("[$it] Single PDF rendered successfully. On to compiling the ZIP…")
val completeZip = WCIFDataBuilder.wcifToZip(scrambledWcif, null, generationDate, "JUnit-Test", "https://test.local")
Assertions.assertTrue(completeZip.allFiles.isNotEmpty())
val compiledZip = Assertions.assertDoesNotThrow(ThrowingSupplier { completeZip.compress() })
Assertions.assertTrue(compiledZip.isNotEmpty())
}

val computationTime = measureTimeMillis {
println("Single PDF rendered successfully. On to compiling the ZIP…")
val completeZip = WCIFDataBuilder.wcifToZip(scrambledWcif, null, generationDate, "JUnit-Test", "https://test.local")
Assertions.assertTrue(completeZip.allFiles.isNotEmpty())
val compiledZip = Assertions.assertDoesNotThrow(ThrowingSupplier { completeZip.compress() })
Assertions.assertTrue(compiledZip.isNotEmpty())
println("[$it] ZIP compilation was successful! Took $computationTime ms")
}

println("ZIP compilation was successful! Took $computationTime ms")
println()
}

jobs.joinAll()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.worldcubeassociation.tnoodle.server.webscrambles.wcif.model.ScrambleS
import java.time.LocalDate
import java.util.*

object WcifDataBuilderTest {
class WcifDataBuilderTest {
val TEST_INSTANCE = LocalDate.now()

@Test
Expand Down