refactor rating stats controller and hide more user ratings

noratings
Thibault Duplessis 2021-10-21 11:48:39 +02:00
parent fd1594375e
commit a3d1ead023
8 changed files with 39 additions and 41 deletions

View File

@ -140,7 +140,6 @@ final class LilaComponents(ctx: ApplicationLoader.Context) extends BuiltInCompon
lazy val search: Search = wire[Search]
lazy val setup: Setup = wire[Setup]
lazy val simul: Simul = wire[Simul]
lazy val stat: Stat = wire[Stat]
lazy val streamer: Streamer = wire[Streamer]
lazy val study: Study = wire[Study]
lazy val team: Team = wire[Team]

View File

@ -211,7 +211,7 @@ Allow: /
case 103 => s"$faq#acpl"
case 258 => s"$faq#marks"
case 13 => s"$faq#titles"
case 87 => routes.Stat.ratingDistribution("blitz").url
case 87 => routes.User.ratingDistribution("blitz").url
case 110 => s"$faq#name"
case 29 => s"$faq#titles"
case 4811 => s"$faq#lm"

View File

@ -1,18 +0,0 @@
package controllers
import lila.app._
import views._
final class Stat(env: Env) extends LilaController(env) {
def ratingDistribution(perfKey: lila.rating.Perf.Key) =
Open { implicit ctx =>
lila.rating.PerfType(perfKey).filter(lila.rating.PerfType.leaderboardable.has) match {
case Some(perfType) =>
env.user.rankingApi.weeklyRatingDistribution(perfType) dmap { data =>
Ok(html.stat.ratingDistribution(perfType, data))
}
case _ => notFound
}
}
}

View File

@ -579,6 +579,17 @@ final class User(
}
}
def ratingDistribution(perfKey: lila.rating.Perf.Key) =
Open { implicit ctx =>
lila.rating.PerfType(perfKey).filter(lila.rating.PerfType.leaderboardable.has) match {
case Some(perfType) =>
env.user.rankingApi.weeklyRatingDistribution(perfType) dmap { data =>
Ok(html.stat.ratingDistribution(perfType, data))
}
case _ => notFound
}
}
def myself =
Auth { _ => me =>
fuccess(Redirect(routes.User.show(me.username)))

View File

@ -41,33 +41,36 @@ object ratingDistribution {
a(
dataIcon := pt.iconChar,
cls := (perfType == pt).option("current"),
href := routes.Stat.ratingDistribution(pt.key)
href := routes.User.ratingDistribution(pt.key)
)(pt.trans)
}
)
)
),
div(cls := "desc", dataIcon := perfType.iconChar)(
ctx.me.flatMap(_.perfs(perfType).glicko.establishedIntRating).map { rating =>
lila.user.Stat.percentile(data, rating) match {
case (under, sum) =>
div(
trans
.nbPerfTypePlayersThisWeek(strong(sum.localize), perfType.trans),
br,
trans.yourPerfTypeRatingIsRating(perfType.trans, strong(rating)),
br,
trans.youAreBetterThanPercentOfPerfTypePlayers(
strong((under * 100.0 / sum).round, "%"),
perfType.trans
ctx.me.ifTrue(ctx.pref.showRatings).flatMap(_.perfs(perfType).glicko.establishedIntRating).map {
rating =>
lila.user.Stat.percentile(data, rating) match {
case (under, sum) =>
div(
trans
.nbPerfTypePlayersThisWeek(strong(sum.localize), perfType.trans),
br,
trans.yourPerfTypeRatingIsRating(perfType.trans, strong(rating)),
br,
trans.youAreBetterThanPercentOfPerfTypePlayers(
strong((under * 100.0 / sum).round, "%"),
perfType.trans
)
)
)
}
}
} getOrElse div(
trans.nbPerfTypePlayersThisWeek
.plural(data.sum, strong(data.sum.localize), perfType.trans),
br,
trans.youDoNotHaveAnEstablishedPerfTypeRating(perfType.trans)
ctx.pref.showRatings option frag(
br,
trans.youDoNotHaveAnEstablishedPerfTypeRating(perfType.trans)
)
)
),
div(id := "rating_distribution_chart")(spinner)

View File

@ -14,7 +14,10 @@ object bits {
def communityMenu(active: String)(implicit ctx: Context) =
st.nav(cls := "page-menu__menu subnav")(
a(cls := active.active("leaderboard"), href := routes.User.list)(trans.leaderboard()),
a(cls := active.active("ratings"), href := routes.Stat.ratingDistribution("blitz"))(
a(
cls := active.active("ratings"),
href := routes.User.ratingDistribution("blitz")
)(
trans.ratingStats()
),
a(cls := active.active("tournament"), href := routes.Tournament.leaderboard)(

View File

@ -96,13 +96,13 @@ object perfStat {
span(cls := "details")(
if (ctx is u) {
trans.youAreBetterThanPercentOfPerfTypePlayers(
a(href := routes.Stat.ratingDistribution(perfType.key))(strong(percentile, "%")),
a(href := routes.User.ratingDistribution(perfType.key))(strong(percentile, "%")),
a(href := routes.User.topNb(200, perfType.key))(perfType.trans)
)
} else {
trans.userIsBetterThanPercentOfPerfTypePlayers(
a(href := routes.User.show(u.username))(u.username),
a(href := routes.Stat.ratingDistribution(perfType.key))(strong(percentile, "%")),
a(href := routes.User.ratingDistribution(perfType.key))(strong(percentile, "%")),
a(href := routes.User.topNb(200, perfType.key))(perfType.trans)
)
}

View File

@ -635,7 +635,7 @@ POST /appeal/:username/snooze/:dur controllers.Appeal.snooze(username: Strin
POST /appeal/:username/send-to-zulip controllers.Appeal.sendToZulip(username: String)
# Stats
GET /stat/rating/distribution/:perf controllers.Stat.ratingDistribution(perf: String)
GET /stat/rating/distribution/:perf controllers.User.ratingDistribution(perf: String)
# API
GET /api controllers.Api.index