swiss WIP

swiss
Thibault Duplessis 2020-05-05 18:58:59 -06:00
parent ab9c17b927
commit 09576cd165
9 changed files with 27 additions and 13 deletions

View File

@ -3,5 +3,5 @@ db.swiss.ensureIndex({teamId:1,startsAt:1})
db.swiss_player.ensureIndex({s:1,u:1})
db.swiss_player.ensureIndex({s:1,c:-1})
db.swiss_pairing.ensureIndex({s:1,r:1})
db.swiss_pairing.ensureIndex({s:1,u:1,r:1})
db.swiss_pairing.ensureIndex({s:1,p:1,r:1})
db.swiss_pairing.ensureIndex({t:1}, {partialFilterExpression:{t:true}})

View File

@ -62,7 +62,8 @@ private object BsonHandlers {
points = r.get[Swiss.Points](points),
tieBreak = r.get[Swiss.TieBreak](tieBreak),
performance = r.getO[Swiss.Performance](performance),
score = r.get[Swiss.Score](score)
score = r.get[Swiss.Score](score),
absent = r.boolD(absent)
)
def writes(w: BSON.Writer, o: SwissPlayer) = $doc(
id -> o.id,
@ -74,7 +75,8 @@ private object BsonHandlers {
points -> o.points,
tieBreak -> o.tieBreak,
performance -> o.performance,
score -> o.score
score -> o.score,
absent -> w.boolO(o.absent)
)
}

View File

@ -77,6 +77,12 @@ final private class PairingSystem(executable: String) {
}
).map { case (l, s) => (l + (rn.value - 1) * 10, s) }
}
} ::: p.absent.?? {
List( // http://www.rrweb.org/javafo/aum/JaVaFo2_AUM.htm#_Unusual_info_extensions
95 -> "0000",
97 -> "-",
99 -> "-"
).map { case (l, s) => (l + (swiss.round.value - 1) * 10, s) }
}
private def format(bits: Bits): String = bits.foldLeft("") {

View File

@ -106,7 +106,7 @@ final class SwissApi(
SwissPairing.fields { f =>
colls.pairing.ext
.find($doc(f.swissId -> swiss.id, f.players -> player.number))
.sort($sort desc f.date)
.sort($sort asc f.round)
.list[SwissPairing]()
} flatMap {
pairingViews(_, player)

View File

@ -123,13 +123,15 @@ final class SwissJson(
object SwissJson {
private[swiss] def playerJson(swiss: Swiss, view: SwissPlayer.View): JsObject =
playerJsonBase(swiss, view) ++ Json.obj(
"pairings" -> swiss.allRounds.map(view.pairings.get).map(_ map pairingJson(view.player))
)
playerJsonBase(swiss, view) ++ Json
.obj(
"pairings" -> swiss.allRounds.map(view.pairings.get).map(_ map pairingJson(view.player))
)
.add("absent" -> view.player.absent)
def playerJsonExt(swiss: Swiss, view: SwissPlayer.ViewExt): JsObject =
playerJsonBase(swiss, view) ++ Json.obj(
"pairings" -> swiss.allRounds.map(view.pairings.get).map {
"pairings" -> swiss.allRounds.reverse.map(view.pairings.get).map {
_ map { p =>
pairingJson(view.player)(p.pairing) ++ Json.obj(
"user" -> p.player.user,

View File

@ -14,7 +14,8 @@ case class SwissPlayer(
points: Swiss.Points,
tieBreak: Swiss.TieBreak,
performance: Option[Swiss.Performance],
score: Swiss.Score
score: Swiss.Score,
absent: Boolean
) {
def is(uid: User.ID): Boolean = uid == userId
def is(user: User): Boolean = is(user.id)
@ -47,7 +48,8 @@ object SwissPlayer {
points = Swiss.Points(0),
tieBreak = Swiss.TieBreak(0),
performance = none,
score = Swiss.Score(0)
score = Swiss.Score(0),
absent = false
).recomputeScore
case class Number(value: Int) extends AnyVal with IntValue
@ -98,6 +100,7 @@ object SwissPlayer {
val tieBreak = "t"
val performance = "e"
val score = "c"
val absent = "a"
}
def fields[A](f: Fields.type => A): A = f(Fields)
}

View File

@ -86,6 +86,7 @@ export interface Player {
performance: number;
rank: number;
pairings: [Pairing | null];
absent: boolean;
}
export interface PerfType {

View File

@ -55,7 +55,7 @@ export default function(ctrl: SwissCtrl): VNode {
if (href) window.open(href, '_blank');
})
}, data.pairings.map((p, i) => {
const round = i + 1;
const round = ctrl.data.round - i;
if (!p) return h('tr', [
h('th', '' + round),
h('td.bye', {

View File

@ -17,7 +17,7 @@ function playerTr(ctrl: SwissCtrl, player: Player) {
},
hook: bind('click', _ => ctrl.showPlayerInfo(player), ctrl.redraw)
}, [
h('td.rank', player.withdraw ? h('i', {
h('td.rank', player.absent ? h('i', {
attrs: {
'data-icon': 'Z',
'title': ctrl.trans.noarg('pause')
@ -90,7 +90,7 @@ export default function standing(ctrl: SwissCtrl, pag, klass?: string): VNode {
pag.currentPageResults.map(res => playerTr(ctrl, res)) : lastBody;
if (pag.currentPageResults) lastBody = tableBody;
return h('table.slist.swiss__standing' + (klass ? '.' + klass : ''), {
class: {
class: {
loading: !pag.currentPageResults,
long: ctrl.data.round > 35,
xlong: ctrl.data.round > 80,