Fix randomness parameter interface (-> none/deterministic/non-deterministic)
This commit is contained in:
@@ -2,9 +2,11 @@ package org.jeudego.pairgoth.api
|
|||||||
|
|
||||||
import com.republicate.kson.Json
|
import com.republicate.kson.Json
|
||||||
import com.republicate.kson.toJsonObject
|
import com.republicate.kson.toJsonObject
|
||||||
|
import com.republicate.kson.toMutableJsonObject
|
||||||
import org.jeudego.pairgoth.api.ApiHandler.Companion.PAYLOAD_KEY
|
import org.jeudego.pairgoth.api.ApiHandler.Companion.PAYLOAD_KEY
|
||||||
import org.jeudego.pairgoth.api.ApiHandler.Companion.badRequest
|
import org.jeudego.pairgoth.api.ApiHandler.Companion.badRequest
|
||||||
import org.jeudego.pairgoth.ext.OpenGotha
|
import org.jeudego.pairgoth.ext.OpenGotha
|
||||||
|
import org.jeudego.pairgoth.model.BaseCritParams
|
||||||
import org.jeudego.pairgoth.model.TeamTournament
|
import org.jeudego.pairgoth.model.TeamTournament
|
||||||
import org.jeudego.pairgoth.model.Tournament
|
import org.jeudego.pairgoth.model.Tournament
|
||||||
import org.jeudego.pairgoth.model.fromJson
|
import org.jeudego.pairgoth.model.fromJson
|
||||||
@@ -65,7 +67,7 @@ object TournamentHandler: PairgothApiHandler {
|
|||||||
override fun put(request: HttpServletRequest, response: HttpServletResponse): Json? {
|
override fun put(request: HttpServletRequest, response: HttpServletResponse): Json? {
|
||||||
// CB TODO - some checks are needed here (cannot lower rounds number if games have been played in removed rounds, for instance)
|
// CB TODO - some checks are needed here (cannot lower rounds number if games have been played in removed rounds, for instance)
|
||||||
val tournament = getTournament(request)
|
val tournament = getTournament(request)
|
||||||
val payload = getObjectPayload(request)
|
val payload = getObjectPayload(request).toMutableJsonObject()
|
||||||
// disallow changing type
|
// disallow changing type
|
||||||
if (payload.getString("type")?.let { it != tournament.type.name } == true) badRequest("tournament type cannot be changed")
|
if (payload.getString("type")?.let { it != tournament.type.name } == true) badRequest("tournament type cannot be changed")
|
||||||
// specific handling for 'excludeTables'
|
// specific handling for 'excludeTables'
|
||||||
@@ -77,6 +79,46 @@ object TournamentHandler: PairgothApiHandler {
|
|||||||
tournament.tablesExclusion[round - 1] = tablesExclusion
|
tournament.tablesExclusion[round - 1] = tablesExclusion
|
||||||
tournament.dispatchEvent(TournamentUpdated, request, tournament.toJson())
|
tournament.dispatchEvent(TournamentUpdated, request, tournament.toJson())
|
||||||
} else {
|
} else {
|
||||||
|
// translate client-side conventions to actual parameters
|
||||||
|
val base = payload.getObject("pairing")?.getObject("base") as Json.MutableObject?
|
||||||
|
if (base != null) {
|
||||||
|
base.getString("randomness")?.let { randomness ->
|
||||||
|
when (randomness) {
|
||||||
|
"none" -> {
|
||||||
|
base["random"] = 0.0
|
||||||
|
base["deterministic"] = true
|
||||||
|
}
|
||||||
|
"deterministic" -> {
|
||||||
|
base["random"] = BaseCritParams.MAX_RANDOM
|
||||||
|
base["deterministic"] = true
|
||||||
|
}
|
||||||
|
"non-deterministic" -> {
|
||||||
|
base["random"] = BaseCritParams.MAX_RANDOM
|
||||||
|
base["deterministic"] = false
|
||||||
|
}
|
||||||
|
else -> badRequest("invalid randomness parameter: $randomness")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base.getBoolean("colorBalance")?.let { colorBalance ->
|
||||||
|
base["colorBalanceWeight"] =
|
||||||
|
if (colorBalance) BaseCritParams.MAX_COLOR_BALANCE
|
||||||
|
else 0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val main = payload.getObject("pairing")?.getObject("main") as Json.MutableObject?
|
||||||
|
if (main != null) {
|
||||||
|
main.getBoolean("firstSeedAddRating")?.let { firstSeedAddRating ->
|
||||||
|
main["firstSeedAddCrit"] =
|
||||||
|
if (firstSeedAddRating) "RATING"
|
||||||
|
else "NONE"
|
||||||
|
}
|
||||||
|
main.getBoolean("secondSeedAddRating")?.let { secondSeedAddRating ->
|
||||||
|
main["secondSeedAddCrit"] =
|
||||||
|
if (secondSeedAddRating) "RATING"
|
||||||
|
else "NONE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// prepare updated tournament version
|
||||||
val updated = Tournament.fromJson(payload, tournament)
|
val updated = Tournament.fromJson(payload, tournament)
|
||||||
// copy players, games, criteria (this copy should be provided by the Tournament class - CB TODO)
|
// copy players, games, criteria (this copy should be provided by the Tournament class - CB TODO)
|
||||||
updated.players.putAll(tournament.players)
|
updated.players.putAll(tournament.players)
|
||||||
|
@@ -224,17 +224,17 @@ onLoad(() => {
|
|||||||
let tour = {
|
let tour = {
|
||||||
pairing: {
|
pairing: {
|
||||||
base: {
|
base: {
|
||||||
deterministic: form.val('deterministic'),
|
randomness: form.val('randomness'),
|
||||||
colorBalanceWeight: form.val('colorBalance') ? 1000000.0 : 0.0 // TODO use client side boolean
|
colorBalance: form.val('colorBalance')
|
||||||
},
|
},
|
||||||
main: {
|
main: {
|
||||||
mmsValueAbsent: form.val('mmsValueAbsent'),
|
mmsValueAbsent: form.val('mmsValueAbsent'),
|
||||||
roundDownScore: form.val('roundDownScore'),
|
roundDownScore: form.val('roundDownScore'),
|
||||||
sosValueAbsentUseBase: form.val('sosValueAbsentUseBase'),
|
sosValueAbsentUseBase: form.val('sosValueAbsentUseBase'),
|
||||||
firstSeedLastRound: form.val('firstSeedLastRound'),
|
firstSeedLastRound: form.val('firstSeedLastRound'),
|
||||||
firstSeedAddCrit: form.val('firstSeedAddRating') ? 'RATING' : 'NONE', // TODO use client side boolean
|
firstSeedAddRating: form.val('firstSeedAddRating'),
|
||||||
firstSeed: form.val('firstSeed'),
|
firstSeed: form.val('firstSeed'),
|
||||||
secondSeedAddCrit: form.val('secondSeedAddRating') ? 'RATING' : 'NONE', // TODO use client side boolean
|
secondSeedAddRating: form.val('secondSeedAddRating'),
|
||||||
secondSeed: form.val('secondSeed'),
|
secondSeed: form.val('secondSeed'),
|
||||||
upDownCompensate: form.val('upDownCompensate'),
|
upDownCompensate: form.val('upDownCompensate'),
|
||||||
upDownUpperMode: form.val('upDownUpperMode'),
|
upDownUpperMode: form.val('upDownUpperMode'),
|
||||||
|
@@ -3,7 +3,14 @@
|
|||||||
<div class="title"><i class="dropdown icon"></i>Base parameters</div>
|
<div class="title"><i class="dropdown icon"></i>Base parameters</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label><input type="checkbox" name="deterministic" value="true" #if($tour.pairing.base.deterministic) checked #end> deterministic randomness</label>
|
<label>
|
||||||
|
Randomness:
|
||||||
|
<select name="randomness">
|
||||||
|
<option value="none" #if($tour.pairing.base.random == 0.0)selected#end>none</option>
|
||||||
|
<option value="deterministic" #if($tour.pairing.base.random != 0.0 && $tour.pairing.base.deterministic)selected#end>deterministic</option>
|
||||||
|
<option value="non-deterministic" #if($tour.pairing.base.random != 0.0 && !$tour.pairing.base.deterministic)selected#end>non-deterministic</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label><input type="checkbox" name="colorBalance" value="true" #if($tour.pairing.base.colorBalanceWeight) checked #end> balance white and black</label>
|
<label><input type="checkbox" name="colorBalance" value="true" #if($tour.pairing.base.colorBalanceWeight) checked #end> balance white and black</label>
|
||||||
|
Reference in New Issue
Block a user