Skip to content

Commit

Permalink
Remove best_score field from lnk_contest_project (#1526)
Browse files Browse the repository at this point in the history
### What's done:
* Remove best score field from lnk_contest_project
  • Loading branch information
kgevorkyan authored Nov 29, 2022
1 parent e976956 commit 2dadddf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 6 additions & 0 deletions db/v-2/tables/lnk-contest-project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@
onDelete="CASCADE"/>
</changeSet>

<changeSet id="drop-test-suite-ids" author="kgevorkyan">
<dropColumn tableName="lnk_contest_project">
<column name="best_score"/>
</dropColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class LnkContestProjectService(
* @return best score of [project] under [Contest] with name [contestName]
*/
fun getBestScoreOfProjectInContestWithName(project: Project, contestName: String) =
lnkContestProjectRepository.findByProjectAndContestName(project, contestName)?.bestScore
lnkContestProjectRepository.findByProjectAndContestName(project, contestName)?.bestExecution?.score

/**
* @param project a [Project]
Expand All @@ -68,7 +68,7 @@ class LnkContestProjectService(
fun saveLnkContestProject(project: Project, contest: Contest): Boolean = if (lnkContestProjectRepository.findByContestAndProject(contest, project).isPresent) {
false
} else {
lnkContestProjectRepository.save(LnkContestProject(project, contest, null, 0.0))
lnkContestProjectRepository.save(LnkContestProject(project, contest, null))
true
}

Expand All @@ -87,15 +87,14 @@ class LnkContestProjectService(
.orElseThrow {
IllegalStateException("Project ${project.shortToString()} is not bound to contest name=${contest.name}")
}
val oldBestScore = lnkContestProject.bestScore
val oldBestScore = lnkContestProject.bestExecution?.score
if (oldBestScore == null || oldBestScore <= newScore) {
logger.debug {
"For project ${project.shortToString()} updating best_score from execution " +
"[id=${lnkContestProject.bestExecution?.id},score=$oldBestScore] to " +
"[id=${newExecution.id},score=$newScore]"
}
lnkContestProject.bestExecution = newExecution
lnkContestProject.bestScore = newExecution.score
lnkContestProjectRepository.save(lnkContestProject)

updateProjectContestRating(project)
Expand All @@ -104,7 +103,7 @@ class LnkContestProjectService(

private fun updateProjectContestRating(project: Project) {
val projectContestRating = lnkContestProjectRepository.findByProject(project).mapNotNull {
it.bestScore
it.bestExecution?.score
}.sum()

projectService.updateProject(project.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LnkContestProjectServiceTest {
then(lnkContestProjectRepository)
.should(times(1))
.save(argWhere {
abs(it.bestScore!! - 4.0) < 1e-4
abs(it.bestExecution?.score!! - 4.0) < 1e-4
})
}

Expand All @@ -54,7 +54,7 @@ class LnkContestProjectServiceTest {
then(lnkContestProjectRepository)
.should(times(1))
.save(argWhere {
abs(it.bestScore!! - 4.0) < 1e-4
abs(it.bestExecution?.score!! - 4.0) < 1e-4
})
}

Expand All @@ -80,7 +80,7 @@ class LnkContestProjectServiceTest {
@Suppress("PARAMETER_NAME_IN_OUTER_LAMBDA")
given(lnkContestProjectRepository.findByContestAndProject(any(), any()))
.willAnswer {
LnkContestProject(it.arguments[1] as Project, it.arguments[0] as Contest, oldBestExecution, oldBestExecution?.score)
LnkContestProject(it.arguments[1] as Project, it.arguments[0] as Contest, oldBestExecution)
.let { Optional.of(it) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import javax.persistence.OneToOne
* @property project
* @property contest
* @property bestExecution
* @property bestScore
*/
@Entity
class LnkContestProject(
Expand All @@ -25,9 +24,6 @@ class LnkContestProject(
@OneToOne
@JoinColumn(name = "best_execution_id")
var bestExecution: Execution?,

var bestScore: Double?,

) : BaseEntity() {
/**
* Get [ContestResult]
Expand Down

0 comments on commit 2dadddf

Please sign in to comment.