From 09fe4a142c60be105a0d54b23015965c639fcbe0 Mon Sep 17 00:00:00 2001 From: Tetsuya Yamamoto Date: Thu, 29 May 2025 11:14:58 +0900 Subject: [PATCH 1/4] =?UTF-8?q?debug:=20=E6=A4=9C=E8=A8=BC=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E5=B7=AE=E3=81=97=E8=BE=BC=E3=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/sportsday/services/GamesService.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/kotlin/net/sportsday/services/GamesService.kt b/src/main/kotlin/net/sportsday/services/GamesService.kt index 5ef5cda..c75ae2d 100644 --- a/src/main/kotlin/net/sportsday/services/GamesService.kt +++ b/src/main/kotlin/net/sportsday/services/GamesService.kt @@ -336,6 +336,10 @@ object GamesService { * @param id game id */ fun calculateLeagueResults(id: Int, restrict: Boolean = false): Result { + val DEBUG = true + val EPSILON = 1e-6 + fun d(msg: String) { if (DEBUG) println(msg) } + val result = transaction { val game = GameEntity.findById(id) ?: throw NotFoundException("invalid game id") @@ -436,6 +440,8 @@ object GamesService { match.leftTeamId == it.teamId || match.rightTeamId == it.teamId } + d("TEAM=${it.teamId} raw[score=${it.score}, goal=${it.goal}, lose=${it.loseGoal}] matches=$matchCount") + if (matchCount > 0) { it.score /= matchCount.toDouble() it.goal /= matchCount.toDouble() @@ -447,6 +453,8 @@ object GamesService { it.loseGoal = -999.0 it.goalDiff = -999.0 } + + d("TEAM=${it.teamId} avg[score=${it.score}, goal=${it.goal}, diff=${it.goalDiff}]") } var lastResult: LeagueTeamResult? = null @@ -466,6 +474,14 @@ object GamesService { }, ) .map { leagueTeamResult -> + if (lastResult != null) { + val scoreGap = (leagueTeamResult.score - lastResult!!.score) + val diffGap = (leagueTeamResult.goalDiff - lastResult!!.goalDiff) + d("cmp TEAM=${leagueTeamResult.teamId} " + + "scoreGap=${scoreGap} diffGap=${diffGap} " + + "=> rank=${leagueTeamResult.rank}") + } + if (lastResult == null) { leagueTeamResult.rank = 1 } else { From 9ac7c9a11ebbd5ba3587f85d3de19f375770c346 Mon Sep 17 00:00:00 2001 From: Tetsuya Yamamoto Date: Thu, 29 May 2025 11:28:51 +0900 Subject: [PATCH 2/4] =?UTF-8?q?debug:=20=E3=81=95=E3=82=89=E3=81=AB?= =?UTF-8?q?=E8=A9=B3=E3=81=97=E3=81=84=E3=83=87=E3=83=90=E3=83=83=E3=82=B0?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/net/sportsday/services/GamesService.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/net/sportsday/services/GamesService.kt b/src/main/kotlin/net/sportsday/services/GamesService.kt index c75ae2d..aa97dd8 100644 --- a/src/main/kotlin/net/sportsday/services/GamesService.kt +++ b/src/main/kotlin/net/sportsday/services/GamesService.kt @@ -12,6 +12,8 @@ import org.jetbrains.exposed.sql.transactions.transaction import java.time.LocalDateTime import kotlin.time.Duration.Companion.minutes +private val Double.format8: String get() = "%,.8f".format(this) + /** * Created by testusuke on 2023/05/05 * @author testusuke @@ -440,8 +442,6 @@ object GamesService { match.leftTeamId == it.teamId || match.rightTeamId == it.teamId } - d("TEAM=${it.teamId} raw[score=${it.score}, goal=${it.goal}, lose=${it.loseGoal}] matches=$matchCount") - if (matchCount > 0) { it.score /= matchCount.toDouble() it.goal /= matchCount.toDouble() @@ -454,7 +454,7 @@ object GamesService { it.goalDiff = -999.0 } - d("TEAM=${it.teamId} avg[score=${it.score}, goal=${it.goal}, diff=${it.goalDiff}]") + d("TEAM=${it.teamId} avg[score=${it.score.format8}, goal=${it.goal.format8}, diff=${it.goalDiff.format8}]") } var lastResult: LeagueTeamResult? = null @@ -473,12 +473,17 @@ object GamesService { } }, ) + .mapIndexed { idx, r -> + d("%2d位 TEAM=${r.teamId} score=${r.score.format8} diff=${r.goalDiff.format8} goal=${r.goal.format8}" + .format(idx + 1)) + r + } .map { leagueTeamResult -> if (lastResult != null) { val scoreGap = (leagueTeamResult.score - lastResult!!.score) val diffGap = (leagueTeamResult.goalDiff - lastResult!!.goalDiff) d("cmp TEAM=${leagueTeamResult.teamId} " - + "scoreGap=${scoreGap} diffGap=${diffGap} " + + "scoreGap=${scoreGap.format8} diffGap=${diffGap.format8} " + "=> rank=${leagueTeamResult.rank}") } From 4b73a93c818ab728ba78126f5eafa1a90c0a017d Mon Sep 17 00:00:00 2001 From: Tetsuya Yamamoto Date: Thu, 29 May 2025 11:42:38 +0900 Subject: [PATCH 3/4] =?UTF-8?q?debug:=20=E4=BF=AE=E6=AD=A3=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/sportsday/services/GamesService.kt | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/net/sportsday/services/GamesService.kt b/src/main/kotlin/net/sportsday/services/GamesService.kt index aa97dd8..ae11254 100644 --- a/src/main/kotlin/net/sportsday/services/GamesService.kt +++ b/src/main/kotlin/net/sportsday/services/GamesService.kt @@ -10,6 +10,7 @@ import net.sportsday.utils.configuration.KeyValueStore import org.jetbrains.exposed.sql.SizedCollection import org.jetbrains.exposed.sql.transactions.transaction import java.time.LocalDateTime +import kotlin.math.abs import kotlin.time.Duration.Companion.minutes private val Double.format8: String get() = "%,.8f".format(this) @@ -464,14 +465,18 @@ object GamesService { if (game.calculationType == CalculationType.DIFF_SCORE || game.calculationType == CalculationType.TOTAL_SCORE) { leagueTeamResults.values .sortedWith( - compareByDescending { it.score } - .apply { - if (game.calculationType == CalculationType.DIFF_SCORE) { - thenByDescending { it.goalDiff } - } else if (game.calculationType == CalculationType.TOTAL_SCORE) { - thenByDescending { it.goal } - } - }, + when (game.calculationType) { + CalculationType.DIFF_SCORE -> + compareByDescending { it.score } + .thenByDescending { it.goalDiff } + + CalculationType.TOTAL_SCORE -> + compareByDescending { it.score } + .thenByDescending { it.goal } + + else -> + compareByDescending { it.score } + } ) .mapIndexed { idx, r -> d("%2d位 TEAM=${r.teamId} score=${r.score.format8} diff=${r.goalDiff.format8} goal=${r.goal.format8}" @@ -493,8 +498,8 @@ object GamesService { // if score is same, rank is same if (game.calculationType == CalculationType.TOTAL_SCORE) { if ( - lastResult!!.score == leagueTeamResult.score && - lastResult!!.goal == leagueTeamResult.goal + abs(lastResult!!.score - leagueTeamResult.score) < EPSILON && + abs(lastResult!!.goal - leagueTeamResult.goal) < EPSILON ) { leagueTeamResult.rank = lastRank } else { @@ -502,8 +507,8 @@ object GamesService { } } else { if ( - lastResult!!.score == leagueTeamResult.score && - lastResult!!.goalDiff == leagueTeamResult.goalDiff + abs(lastResult!!.score - leagueTeamResult.score) < EPSILON && + abs(lastResult!!.goalDiff - leagueTeamResult.goalDiff) < EPSILON ) { leagueTeamResult.rank = lastRank } else { @@ -525,7 +530,7 @@ object GamesService { if (lastResult == null) { leagueTeamResult.rank = 1 } else { - if (lastResult!!.score == leagueTeamResult.score) { + if (abs(lastResult!!.score - leagueTeamResult.score) < EPSILON) { leagueTeamResult.rank = lastRank } else { leagueTeamResult.rank = lastRank + 1 From f3d29522b49a4ba39cd8a74a1292e4423ba0a16c Mon Sep 17 00:00:00 2001 From: Tetsuya Yamamoto Date: Thu, 29 May 2025 13:11:00 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E9=A0=86=E4=BD=8D=E8=A8=88=E7=AE=97?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E8=A7=A3=E6=B1=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/sportsday/services/GamesService.kt | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/main/kotlin/net/sportsday/services/GamesService.kt b/src/main/kotlin/net/sportsday/services/GamesService.kt index ae11254..fd013f8 100644 --- a/src/main/kotlin/net/sportsday/services/GamesService.kt +++ b/src/main/kotlin/net/sportsday/services/GamesService.kt @@ -13,7 +13,7 @@ import java.time.LocalDateTime import kotlin.math.abs import kotlin.time.Duration.Companion.minutes -private val Double.format8: String get() = "%,.8f".format(this) +private const val EPSILON = 1e-6 /** * Created by testusuke on 2023/05/05 @@ -339,10 +339,6 @@ object GamesService { * @param id game id */ fun calculateLeagueResults(id: Int, restrict: Boolean = false): Result { - val DEBUG = true - val EPSILON = 1e-6 - fun d(msg: String) { if (DEBUG) println(msg) } - val result = transaction { val game = GameEntity.findById(id) ?: throw NotFoundException("invalid game id") @@ -454,8 +450,6 @@ object GamesService { it.loseGoal = -999.0 it.goalDiff = -999.0 } - - d("TEAM=${it.teamId} avg[score=${it.score.format8}, goal=${it.goal.format8}, diff=${it.goalDiff.format8}]") } var lastResult: LeagueTeamResult? = null @@ -478,20 +472,7 @@ object GamesService { compareByDescending { it.score } } ) - .mapIndexed { idx, r -> - d("%2d位 TEAM=${r.teamId} score=${r.score.format8} diff=${r.goalDiff.format8} goal=${r.goal.format8}" - .format(idx + 1)) - r - } .map { leagueTeamResult -> - if (lastResult != null) { - val scoreGap = (leagueTeamResult.score - lastResult!!.score) - val diffGap = (leagueTeamResult.goalDiff - lastResult!!.goalDiff) - d("cmp TEAM=${leagueTeamResult.teamId} " - + "scoreGap=${scoreGap.format8} diffGap=${diffGap.format8} " - + "=> rank=${leagueTeamResult.rank}") - } - if (lastResult == null) { leagueTeamResult.rank = 1 } else {