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

Move score from lnk_contest_execution to execution #1156

Merged
merged 12 commits into from
Sep 5, 2022
10 changes: 10 additions & 0 deletions db/v-2/tables/lnk-contest-execution.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@
</rollback>
</changeSet>

<changeSet id="move-score-from-lnk_contest_execution-to-execution" author="petertrr" context="dev or prod">
<addColumn tableName="execution">
<column name="score" type="double" defaultValue="0.0"/>
</addColumn>
<sql>
update execution set score = (select score from lnk_contest_execution lce inner join execution e on e.id = lce.execution_id);
</sql>
<dropColumn tableName="lnk_contest_execution" columnName="score"/>
</changeSet>

</databaseChangeLog>
8 changes: 8 additions & 0 deletions save-backend/backend-api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7426,6 +7426,10 @@
"testSuiteSourceName": {
"type": "string"
},
"score": {
"type": "number",
"format": "double"
},
"id": {
"type": "integer",
"format": "int64"
Expand Down Expand Up @@ -7604,6 +7608,10 @@
},
"testSuiteSourceName": {
"type": "string"
},
"score": {
"type": "number",
"format": "double"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class RunExecutionController(
authentication: Authentication,
): Mono<StringResponse> = blockingToMono { executionService.findExecution(executionId) }
.switchIfEmptyToNotFound { "Not found execution id = $executionId" }
.filter { it.type != TestingType.CONTEST_MODE }
.switchIfEmptyToResponseException(HttpStatus.CONFLICT) {
"Rerun is not supported for executions that were performed under a contest"
}
.validateAccess(authentication) { execution ->
ProjectCoordinates(
execution.project.organization.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface LnkContestExecutionRepository : BaseEntityRepository<LnkContestExecuti
* @param pageable
* @return record with a page of N best scores of a contests of the project
*/
fun findByExecutionProjectAndContestNameOrderByScoreDesc(project: Project, contestName: String, pageable: Pageable): Page<LnkContestExecution>
fun findByExecutionProjectAndContestNameOrderByExecutionScoreDesc(project: Project, contestName: String, pageable: Pageable): Page<LnkContestExecution>

/**
* Get N executions of a [Project] in [Contest]
Expand Down Expand Up @@ -46,4 +46,6 @@ interface LnkContestExecutionRepository : BaseEntityRepository<LnkContestExecuti
*/
@Suppress("IDENTIFIER_LENGTH")
fun findByContestAndExecutionProjectIdInOrderByExecutionStartTimeDesc(contest: Contest, projectIds: List<Long>): List<LnkContestExecution>

fun findByExecutionProjectAndContestName(project: Project, contestName: String): LnkContestExecution?
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ class ExecutionService(
execCmd = execCmd,
batchSizeForAnalyzer = batchSizeForAnalyzer,
testSuiteSourceName = testSuiteSourceName,
score = null,
)
val savedExecution = saveExecution(execution)
log.info("Created a new execution id=${savedExecution.id} for project id=${project.id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.saveourtool.save.entities.*
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Pageable
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

/**
* Service of [LnkContestExecution]
Expand All @@ -18,10 +19,10 @@ class LnkContestExecutionService(
* @param contestName
* @return best score of a [Project] in contest with name [contestName]
*/
@Transactional
fun getBestScoreOfProjectInContestWithName(project: Project, contestName: String) =
lnkContestExecutionRepository.findByExecutionProjectAndContestNameOrderByScoreDesc(project, contestName, Pageable.ofSize(1))
.content
.singleOrNull()
lnkContestExecutionRepository.findByExecutionProjectAndContestName(project, contestName)
?.execution
?.score

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import kotlinx.serialization.Serializable
* @property expectedChecks
* @property unexpectedChecks
* @property testSuiteSourceName
* @property score see [Execution.score]
*/
@Serializable
@Suppress("LongParameterList")
Expand All @@ -39,6 +40,7 @@ data class ExecutionDto(
val expectedChecks: Long,
val unexpectedChecks: Long,
val testSuiteSourceName: String?,
val score: Double?,
) {
companion object {
val empty = ExecutionDto(
Expand All @@ -58,6 +60,7 @@ data class ExecutionDto(
expectedChecks = 0,
unexpectedChecks = 0,
testSuiteSourceName = "",
score = null,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import javax.persistence.ManyToOne
* @property execCmd
* @property batchSizeForAnalyzer
* @property testSuiteSourceName
* @property score a rating of this execution. Specific meaning may vary depending on [type]
*/
@Suppress("LongParameterList")
@Entity
Expand Down Expand Up @@ -95,28 +96,31 @@ class Execution(

var testSuiteSourceName: String?,

var score: Double?,

) : BaseEntity() {
/**
* @return Execution dto
*/
@Suppress("UnsafeCallOnNullableType")
fun toDto() = ExecutionDto(
id!!,
status,
type,
version,
startTime.toEpochSecond(ZoneOffset.UTC),
endTime?.toEpochSecond(ZoneOffset.UTC),
allTests,
runningTests,
passedTests,
failedTests,
skippedTests,
unmatchedChecks,
matchedChecks,
expectedChecks,
unexpectedChecks,
testSuiteSourceName,
id = id!!,
status = status,
type = type,
version = version,
startTime = startTime.toEpochSecond(ZoneOffset.UTC),
endTime = endTime?.toEpochSecond(ZoneOffset.UTC),
allTests = allTests,
runningTests = runningTests,
passedTests = passedTests,
failedTests = failedTests,
skippedTests = skippedTests,
unmatchedChecks = unmatchedChecks,
matchedChecks = matchedChecks,
expectedChecks = expectedChecks,
unexpectedChecks = unexpectedChecks,
testSuiteSourceName = testSuiteSourceName,
score = score,
)

/**
Expand Down Expand Up @@ -173,6 +177,7 @@ class Execution(
execCmd = null,
batchSizeForAnalyzer = null,
testSuiteSourceName = "",
score = null,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import javax.persistence.OneToOne
*
* @property contest
* @property execution
* @property score the result of an execution
*/
@Entity
class LnkContestExecution(
Expand All @@ -22,7 +21,6 @@ class LnkContestExecution(
@JoinColumn(name = "contest_id")
var contest: Contest,

var score: Double
) : BaseEntity() {
/**
* @return [ContestResult] from [LnkContestExecution]
Expand All @@ -31,7 +29,7 @@ class LnkContestExecution(
execution.project.name,
execution.project.organization.name,
contest.name,
score,
execution.score,
execution.startTime,
execution.status,
execution.sdk,
Expand Down