Skip to content

Commit

Permalink
show host proper rating with provisional
Browse files Browse the repository at this point in the history
  • Loading branch information
declarationperfume committed Nov 6, 2023
1 parent 89c648c commit 8a7ac01
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion modules/simul/src/main/JsonView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ final class JsonView(
.obj(
"id" -> host.id,
"name" -> host.name,
"rating" -> simul.hostRating
"rating" -> simul.hostRating,
"provisional" -> simul.hostProvisional
)
.add("gameId" -> simul.hostGameId.ifTrue(simul.isRunning))
.add("title" -> host.title)
Expand Down
8 changes: 3 additions & 5 deletions modules/simul/src/main/Simul.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -158,11 +159,8 @@ object Simul:
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)
,
hostRating = host.perfs.bestPerf(variants.map { PerfType(_, Speed(clock.config.some)) }).intRating,
hostProvisional = host.perfs.bestPerf(variants.map { PerfType(_, Speed(clock.config.some)) }).provisional.some,
hostGameId = none,
createdAt = nowInstant,
estimatedStartAt = estimatedStartAt,
Expand Down
8 changes: 8 additions & 0 deletions modules/user/src/main/UserPerfs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ui/simul/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface Player extends LightUserOnline {

export interface Host extends LightUserOnline {
rating: number;
provisional?: boolean;
gameId?: string;
}

Expand Down

0 comments on commit 8a7ac01

Please sign in to comment.