Fix rounding option: correct choice is 'round down' or 'no rounding'

This commit is contained in:
Claude Brisson
2024-08-29 18:37:42 +02:00
parent 3d755efa7e
commit fe48bfb4b6
8 changed files with 12 additions and 14 deletions

View File

@@ -15,6 +15,7 @@ import kotlin.math.ceil
import kotlin.math.floor import kotlin.math.floor
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
import kotlin.math.round
// TODO CB avoid code redundancy with solvers // TODO CB avoid code redundancy with solvers
@@ -29,7 +30,7 @@ fun Tournament<*>.getSortedPairables(round: Int, includePreliminary: Boolean = f
val epsilon = 0.00001 val epsilon = 0.00001
// Note: this works for now because we only have .0 and .5 fractional parts // Note: this works for now because we only have .0 and .5 fractional parts
return if (pairing.pairingParams.main.roundDownScore) floor(score + epsilon) return if (pairing.pairingParams.main.roundDownScore) floor(score + epsilon)
else ceil(score - epsilon) else round(2 * score) / 2
} }
if (frozen != null) { if (frozen != null) {
@@ -45,7 +46,7 @@ fun Tournament<*>.getSortedPairables(round: Int, includePreliminary: Boolean = f
val score = roundScore(mmBase + val score = roundScore(mmBase +
(nbW(pairable) ?: 0.0) + (nbW(pairable) ?: 0.0) +
(1..round).map { round -> (1..round).map { round ->
if (playersPerRound.getOrNull(round - 1)?.contains(pairable.id) == true) 0 else 1 if (playersPerRound.getOrNull(round - 1)?.contains(pairable.id) == true) 0.0 else 1.0
}.sum() * pairing.pairingParams.main.mmsValueAbsent) }.sum() * pairing.pairingParams.main.mmsValueAbsent)
Pair( Pair(
if (pairing.pairingParams.main.sosValueAbsentUseBase) mmBase if (pairing.pairingParams.main.sosValueAbsentUseBase) mmBase
@@ -96,7 +97,7 @@ fun Tournament<*>.getSortedPairables(round: Int, includePreliminary: Boolean = f
val pairables = pairables.values.filter { includePreliminary || it.final }.map { it.toDetailedJson() } val pairables = pairables.values.filter { includePreliminary || it.final }.map { it.toDetailedJson() }
pairables.forEach { player -> pairables.forEach { player ->
for (crit in criteria) { for (crit in criteria) {
player[crit.first] = (crit.second[player.getID()] ?: 0.0).toInt() player[crit.first] = crit.second[player.getID()] ?: 0.0
} }
player["results"] = Json.MutableArray(List(round) { "0=" }) player["results"] = Json.MutableArray(List(round) { "0=" })
} }

View File

@@ -48,7 +48,7 @@ abstract class BasePairingHelper(
// Decide each pairable group based on the main criterion // Decide each pairable group based on the main criterion
protected val groupsCount get() = 1 + (mainLimits.second - mainLimits.first).toInt() protected val groupsCount get() = 1 + (mainLimits.second - mainLimits.first).toInt()
private val _groups by lazy { private val _groups by lazy {
pairables.associate { pairable -> Pair(pairable.id, pairable.main.toInt()) } pairables.associate { pairable -> Pair(pairable.id, (pairable.main * 2).toInt() / 2) }
} }
// place (among sorted pairables) // place (among sorted pairables)

View File

@@ -480,7 +480,7 @@ sealed class BaseSolver(
val epsilon = 0.00001 val epsilon = 0.00001
// Note: this works for now because we only have .0 and .5 fractional parts // Note: this works for now because we only have .0 and .5 fractional parts
return if (pairing.main.roundDownScore) floor(score + epsilon) return if (pairing.main.roundDownScore) floor(score + epsilon)
else ceil(score - epsilon) else round(2 * score) / 2
} }
open fun HandicapParams.clamp(input: Int): Int { open fun HandicapParams.clamp(input: Int): Int {

View File

@@ -5,6 +5,7 @@
<tool key="translate" class="org.jeudego.pairgoth.view.TranslationTool"/> <tool key="translate" class="org.jeudego.pairgoth.view.TranslationTool"/>
<tool key="strings" class="org.apache.commons.lang3.StringUtils"/> <tool key="strings" class="org.apache.commons.lang3.StringUtils"/>
<tool key="utils" class="org.jeudego.pairgoth.view.PairgothTool"/> <tool key="utils" class="org.jeudego.pairgoth.view.PairgothTool"/>
<tool key="number" locale="en_US"/>
<!-- <!--
<tool key="number" format="#0.00"/> <tool key="number" format="#0.00"/>
<tool key="date" locale="fr_FR" format="yyyy-MM-dd"/> <tool key="date" locale="fr_FR" format="yyyy-MM-dd"/>

View File

@@ -204,3 +204,4 @@ Pairgoth mailing list liste de diffusion Pairgoth
to be notified about updates and to discuss the software. pour être mis au courant des mises à jour et pour discuter du logiciel. to be notified about updates and to discuss the software. pour être mis au courant des mises à jour et pour discuter du logiciel.
(give us a star if you have a github account!) (donnez-nous une étoile si vous avez un compte github !) (give us a star if you have a github account!) (donnez-nous une étoile si vous avez un compte github !)
Clear results Effacer les résultats Clear results Effacer les résultats
round down NBW/MMS score arrondir le score NBW/MMS à l'entier inférieur

View File

@@ -256,3 +256,4 @@ rather than pairing players of the same country. 점 차이를 선호
rather than pairing players of the same club. 동일 클럽 선수끼리 매칭하는 것보다 3점 차이를 선호 rather than pairing players of the same club. 동일 클럽 선수끼리 매칭하는 것보다 3점 차이를 선호
use MMS rather than rank for handicap 핸디캡에는 랭킹 대신 MMS 사용 use MMS rather than rank for handicap 핸디캡에는 랭킹 대신 MMS 사용
Handicap ceiling: 핸디캡 상한: Handicap ceiling: 핸디캡 상한:
round down NBW/MMS score 라운드 내림 라운드 NBW/MMS

View File

@@ -14,14 +14,7 @@
#if($tour.pairing.type == 'MAC_MAHON') #if($tour.pairing.type == 'MAC_MAHON')
<div class="inline fields"> <div class="inline fields">
<div class="field"> <div class="field">
<label> <label><input type="checkbox" name="roundDownScore" value="true" #if($tour.pairing.main.roundDownScore) checked #end>&nbsp;round down NBW/MMS score</label>
Round
<select name="roundDownScore">
<option value="true" #if($tour.pairing.main.roundDownScore) selected #end>down</option>
<option value="false" #if(!$tour.pairing.main.roundDownScore) selected #end>up</option>
</select>
NBW/MMS score
</label>
</div> </div>
</div> </div>
#end #end

View File

@@ -97,7 +97,8 @@
<td class="nobreak game-result" #if($opponent)title="$esc.html($opponent.name)#if($opponent.firstname) $esc.html($opponent.firstname)#end #rank($opponent.rank)#if($opponent.country) $opponent.country#end"#end>$rst</td> <td class="nobreak game-result" #if($opponent)title="$esc.html($opponent.name)#if($opponent.firstname) $esc.html($opponent.firstname)#end #rank($opponent.rank)#if($opponent.country) $opponent.country#end"#end>$rst</td>
#end #end
#foreach($crit in $criteres) #foreach($crit in $criteres)
<td>$number.format('0.#', $part[$crit])</td> #set($value = "$number.format('0.#', $part[$crit])")
<td data-sort="$value">$value.replace('.5', '½')</td>
#end #end
</tr> </tr>
#end #end