diff --git a/modules/simul/src/main/JsonView.scala b/modules/simul/src/main/JsonView.scala index 03fb10da886c8..63c3a9d9dddf1 100644 --- a/modules/simul/src/main/JsonView.scala +++ b/modules/simul/src/main/JsonView.scala @@ -80,6 +80,7 @@ final class JsonView( "name" -> host.name, "rating" -> simul.hostRating ) + .add("provisional" -> simul.hostProvisional) .add("gameId" -> simul.hostGameId.ifTrue(simul.isRunning)) .add("title" -> host.title) .add("patron" -> host.isPatron) diff --git a/modules/simul/src/main/Simul.scala b/modules/simul/src/main/Simul.scala index a8ce7d07a817a..bea3b49102072 100644 --- a/modules/simul/src/main/Simul.scala +++ b/modules/simul/src/main/Simul.scala @@ -22,6 +22,7 @@ case class Simul( estimatedStartAt: Option[Instant] = None, hostId: UserId, hostRating: IntRating, + hostProvisional: Option[RatingProvisional], hostGameId: Option[String], // game the host is focusing on startedAt: Option[Instant], finishedAt: Option[Instant], @@ -152,29 +153,28 @@ object Simul: estimatedStartAt: Option[Instant], featurable: Option[Boolean], conditions: SimulCondition.All - ): Simul = Simul( - _id = SimulId(ThreadLocalRandom nextString 8), - name = name, - status = SimulStatus.Created, - clock = clock, - hostId = host.id, - hostRating = host.perfs.bestRatingIn: - variants.map { - PerfType(_, Speed(clock.config.some)) - } ::: List(PerfType.Blitz, PerfType.Rapid, PerfType.Classical) - , - hostGameId = none, - createdAt = nowInstant, - estimatedStartAt = estimatedStartAt, - variants = if position.isDefined then List(chess.variant.Standard) else variants, - position = position, - applicants = Nil, - pairings = Nil, - startedAt = none, - finishedAt = none, - hostSeenAt = nowInstant.some, - color = color.some, - text = text, - featurable = featurable, - conditions = conditions - ) + ): Simul = + val hostPerf = host.perfs.bestPerf(variants.map { PerfType(_, Speed(clock.config.some)) }) + Simul( + _id = SimulId(ThreadLocalRandom nextString 8), + name = name, + status = SimulStatus.Created, + clock = clock, + hostId = host.id, + hostRating = hostPerf.intRating, + hostProvisional = hostPerf.provisional.some, + hostGameId = none, + createdAt = nowInstant, + estimatedStartAt = estimatedStartAt, + variants = if position.isDefined then List(chess.variant.Standard) else variants, + position = position, + applicants = Nil, + pairings = Nil, + startedAt = none, + finishedAt = none, + hostSeenAt = nowInstant.some, + color = color.some, + text = text, + featurable = featurable, + conditions = conditions + ) diff --git a/modules/simul/src/main/SimulApi.scala b/modules/simul/src/main/SimulApi.scala index 7ec5c1f6d21e9..7b69eba9bb1a7 100644 --- a/modules/simul/src/main/SimulApi.scala +++ b/modules/simul/src/main/SimulApi.scala @@ -97,7 +97,7 @@ final class SimulApi( .filter(simul.variants.contains) .ifTrue(simul.nbAccepted < Game.maxPlayingRealtime) .so: variant => - val perfType = PerfType(variant, chess.Speed.Rapid) + val perfType = PerfType(variant, chess.Speed(simul.clock.config.some)) perfsRepo .withPerf(me.value, perfType) .flatMap: user => diff --git a/modules/user/src/main/UserPerfs.scala b/modules/user/src/main/UserPerfs.scala index b4431bd05ec5a..e7b3d6427f531 100644 --- a/modules/user/src/main/UserPerfs.scala +++ b/modules/user/src/main/UserPerfs.scala @@ -96,6 +96,14 @@ case class UserPerfs( case (ro, _) => ro .getOrElse(Perf.default.intRating) + def bestPerf(types: List[PerfType]): Perf = + types + .map(apply) + .foldLeft(none[Perf]): + case (ro, p) if ro.forall(_.intRating < p.intRating) => p.some + case (ro, _) => ro + .getOrElse(Perf.default) + def bestRatingInWithMinGames(types: List[PerfType], nbGames: Int): Option[IntRating] = types .map(apply) diff --git a/ui/simul/src/interfaces.ts b/ui/simul/src/interfaces.ts index 067d74685bf1e..62094d0c4b2ef 100644 --- a/ui/simul/src/interfaces.ts +++ b/ui/simul/src/interfaces.ts @@ -42,6 +42,7 @@ export interface Player extends LightUserOnline { export interface Host extends LightUserOnline { rating: number; + provisional?: boolean; gameId?: string; }