Skip to content

Commit

Permalink
more getting rid of standard and using combinations of perfs instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Aug 3, 2014
1 parent dc994eb commit e0f0a83
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 155 deletions.
5 changes: 2 additions & 3 deletions app/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class Env(
lobby = Env.lobby.lobby,
lobbyVersion = () => Env.lobby.history.version,
featured = Env.tv.featured,
leaderboard = Env.user.cached.topRatingDay.apply,
leaderboard = Env.user.cached.topToday.apply,
tourneyWinners = Env.tournament.winners.scheduled,
timelineEntries = Env.timeline.getter.userEntries _,
nowPlaying = Env.round.nowPlaying,
Expand All @@ -29,14 +29,13 @@ final class Env(
getPools = () => Env.pool.repo.all apply true)

lazy val userInfo = mashup.UserInfo(
countUsers = () => Env.user.countEnabled,
bookmarkApi = Env.bookmark.api,
relationApi = Env.relation.api,
gameCached = Env.game.cached,
crosstableApi = Env.game.crosstableApi,
postApi = Env.forum.postApi,
getRatingChart = Env.history.ratingChartApi.apply,
getRank = Env.user.ranking.get,
getRanks = Env.user.cached.ranking.getAll,
getDonated = Env.donation.api.donatedByUser) _

system.actorOf(Props(new actor.Renderer), name = RendererName)
Expand Down
24 changes: 9 additions & 15 deletions app/controllers/User.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import lila.game.GameRepo
import lila.security.Permission
import lila.user.tube.userTube
import lila.user.{ User => UserModel, UserRepo }
import lila.rating.PerfType
import views._

object User extends LilaController {
Expand All @@ -28,11 +29,10 @@ object User extends LilaController {
OptionFuResult(UserRepo named username) { user =>
GameRepo nowPlaying user.id zip
(ctx.userId ?? { relationApi.blocks(user.id, _) }) zip
(ctx.userId ?? { relationApi.follows(user.id, _) }) zip
(ctx.isAuth ?? { Env.pref.api.followable(user.id) }) zip
(ctx.userId ?? { relationApi.relation(_, user.id) }) map {
case ((((game, blocked), followed), followable), relation) =>
Ok(html.user.mini(user, game, blocked, followed, followable, relation))
case (((game, blocked), followable), relation) =>
Ok(html.user.mini(user, game, blocked, followable, relation))
.withHeaders(CACHE_CONTROL -> "max-age=5")
}
}
Expand Down Expand Up @@ -94,12 +94,12 @@ object User extends LilaController {
def list = Open { implicit ctx =>
val nb = 10
for {
bullet env.cached topBulletWeek nb
blitz env.cached topBlitzWeek nb
classical env.cached topClassicalWeek nb
chess960 env.cached topChess960Week nb
kingOfTheHill env.cached topKingOfTheHillWeek nb
threeCheck env.cached topThreeCheckWeek nb
bullet env.cached topPerf PerfType.Bullet.key
blitz env.cached topPerf PerfType.Blitz.key
classical env.cached topPerf PerfType.Classical.key
chess960 env.cached topPerf PerfType.Chess960.key
kingOfTheHill env.cached topPerf PerfType.KingOfTheHill.key
threeCheck env.cached topPerf PerfType.ThreeCheck.key
nbAllTime env.cached topNbGame nb map2 { (user: UserModel) =>
user -> user.count.game
}
Expand All @@ -121,12 +121,6 @@ object User extends LilaController {
nbAllTime = nbAllTime)
}

def leaderboard = Open { implicit ctx =>
UserRepo topRating 500 map { users =>
html.user.leaderboard(users)
}
}

def mod(username: String) = Secure(_.UserSpy) { implicit ctx =>
me => OptionFuOk(UserRepo named username) { user =>
Env.evaluation.evaluator find user zip
Expand Down
7 changes: 4 additions & 3 deletions app/mashup/Preload.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,23 @@ import lila.socket.History
import lila.timeline.Entry
import lila.tournament.{ Enterable, Winner }
import lila.tv.{ Featured, StreamOnAir }
import lila.rating.PerfType
import lila.user.User
import makeTimeout.large

final class Preload(
lobby: ActorRef,
lobbyVersion: () => Int,
featured: Featured,
leaderboard: Int => Fu[List[User]],
leaderboard: Boolean => Fu[List[(User, PerfType)]],
tourneyWinners: Int => Fu[List[Winner]],
timelineEntries: String => Fu[List[Entry]],
nowPlaying: (User, Int) => Fu[List[Pov]],
streamsOnAir: => () => Fu[List[StreamOnAir]],
dailyPuzzle: () => Fu[Option[lila.puzzle.DailyPuzzle]],
getPools: () => Fu[List[Pool]]) {

private type Response = (JsObject, List[Entry], List[MiniForumPost], List[Enterable], Option[Game], List[User], List[Winner], Option[lila.puzzle.DailyPuzzle], List[Pov], List[Pool], List[StreamOnAir])
private type Response = (JsObject, List[Entry], List[MiniForumPost], List[Enterable], Option[Game], List[(User, PerfType)], List[Winner], Option[lila.puzzle.DailyPuzzle], List[Pov], List[Pool], List[StreamOnAir])

def apply(
posts: Fu[List[MiniForumPost]],
Expand All @@ -44,7 +45,7 @@ final class Preload(
tours zip
featured.one zip
(ctx.userId ?? timelineEntries) zip
leaderboard(10) zip
leaderboard(true) zip
tourneyWinners(10) zip
dailyPuzzle() zip
(ctx.me ?? { nowPlaying(_, 3) }) zip
Expand Down
13 changes: 5 additions & 8 deletions app/mashup/UserInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import lila.user.User

case class UserInfo(
user: User,
rank: Option[(Int, Int)],
ranks: Map[lila.rating.Perf.Key, Int],
nbPlaying: Int,
crosstable: Option[Crosstable],
nbBookmark: Int,
Expand All @@ -36,18 +36,15 @@ case class UserInfo(
object UserInfo {

def apply(
countUsers: () => Fu[Int],
bookmarkApi: BookmarkApi,
relationApi: RelationApi,
gameCached: lila.game.Cached,
crosstableApi: lila.game.CrosstableApi,
postApi: PostApi,
getRatingChart: User => Fu[Option[String]],
getRank: String => Fu[Option[Int]],
getRanks: String => Fu[Map[String, Int]],
getDonated: String => Fu[Int])(user: User, ctx: Context): Fu[UserInfo] =
(getRank(user.id) flatMap {
_ ?? { rank => countUsers() map { nb => (rank -> nb).some } }
}) zip
getRanks(user.id) zip
((ctx is user) ?? { gameCached nbPlaying user.id map (_.some) }) zip
(ctx.me.filter(user!=) ?? { me => crosstableApi(me.id, user.id) }) zip
getRatingChart(user) zip
Expand All @@ -57,9 +54,9 @@ object UserInfo {
postApi.nbByUser(user.id) zip
getDonated(user.id) zip
PlayTime(user) map {
case (((((((((rank, nbPlaying), crosstable), ratingChart), nbFollowing), nbFollowers), nbBlockers), nbPosts), donated), playTime) => new UserInfo(
case (((((((((ranks, nbPlaying), crosstable), ratingChart), nbFollowing), nbFollowers), nbBlockers), nbPosts), donated), playTime) => new UserInfo(
user = user,
rank = rank,
ranks = ranks,
nbPlaying = ~nbPlaying,
crosstable = crosstable,
nbBookmark = bookmarkApi countByUser user,
Expand Down
12 changes: 7 additions & 5 deletions app/templating/UserHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@ trait UserHelper { self: I18nHelper with StringHelper =>
PerfType.ThreeCheck)

def showPerfRating(rating: Int, name: String, nb: Int, icon: Char, klass: String) = Html {
s"""<span data-hint="$name rating over $nb games" class="$klass"><span data-icon="$icon">${(nb > 0).fold(rating, "&nbsp;&nbsp;&nbsp;-")}</span></span>"""
val title = s"$name rating over $nb games"
val attr = if (klass == "title") "title" else "data-hint"
s"""<span $attr="$title" class="$klass"><span data-icon="$icon">${(nb > 0).fold(rating, "&nbsp;&nbsp;&nbsp;-")}</span></span>"""
}

def showPerfRating(perfType: PerfType, perf: Perf, klass: String = "hint--bottom"): Html =
def showPerfRating(perfType: PerfType, perf: Perf, klass: String): Html =
showPerfRating(perf.intRating, perfType.name, perf.nb, perfType.iconChar, klass)

def showPerfRating(u: User, perfType: PerfType): Option[Html] =
u.perfs.perfsMap get perfType.key map { showPerfRating(perfType, _) }
def showPerfRating(u: User, perfType: PerfType, klass: String = "hint--bottom"): Html =
showPerfRating(perfType, u perfs perfType, klass)

def showPerfRating(u: User, perfKey: String): Option[Html] =
PerfType(perfKey) flatMap { showPerfRating(u, _) }
PerfType(perfKey) map { showPerfRating(u, _) }

def showRatingDiff(diff: Int) = Html {
diff match {
Expand Down
4 changes: 2 additions & 2 deletions app/views/game/variantLink.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(variant: chess.Variant, name: String)
@(variant: chess.Variant, name: String, hintAsTitle: Boolean = false)
@import chess.Variant
@url = {
@variant match {
Expand All @@ -9,4 +9,4 @@
case chess.Variant.FromPosition => {@routes.Editor.index}
}
}
<a href="@url" target="_blank" data-hint="@variant.title" class="hint--bottom">@name</a>
<a href="@url" target="_blank" @if(hintAsTitle){title}else{data-hint}="@variant.title" class="hint--bottom">@name</a>
10 changes: 6 additions & 4 deletions app/views/lobby/home.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(preload: String, userTimeline: List[lila.timeline.Entry], forumRecent: List[lila.forum.MiniForumPost], tours: List[lila.tournament.Enterable], featured: Option[Game], leaderboard: List[User], tournamentWinners: List[lila.tournament.Winner], puzzle: Option[lila.puzzle.DailyPuzzle], playing: List[Pov], streams: List[lila.tv.StreamOnAir], lastPost: List[lila.blog.MiniPost], pools: List[lila.pool.Pool])(implicit ctx: Context)
@(preload: String, userTimeline: List[lila.timeline.Entry], forumRecent: List[lila.forum.MiniForumPost], tours: List[lila.tournament.Enterable], featured: Option[Game], leaderboard: List[(User, lila.rating.PerfType)], tournamentWinners: List[lila.tournament.Winner], puzzle: Option[lila.puzzle.DailyPuzzle], playing: List[Pov], streams: List[lila.tv.StreamOnAir], lastPost: List[lila.blog.MiniPost], pools: List[lila.pool.Pool])(implicit ctx: Context)

@underchat = {
<div id="featured_game">
Expand Down Expand Up @@ -136,13 +136,15 @@
<div class="undertable_inner scroll-shadow-hard">
<table>
<tbody>
@leaderboard.map { u =>
@leaderboard.map {
case (u, pt) => {
<tr>
<td>@userLink(u, cssClass="revert-underline".some)</td>
<td>@u.rating</td>
<td>@showProgress(u.progress, withTitle = false)</td>
<td>@showPerfRating(u, pt, klass = "title")</td>
<td>@showProgress(u.perfs(pt).progress, withTitle = false)</td>
</tr>
}
}
</tbody>
</table>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/setup/challengeNotification.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@userLink(user)<br />
@trans.challengeToPlay.en()<br />
@clockNameNoCtx(g.clock)<br />
@game.variantLink(g.variant, variantNameNoCtx(g.variant)), @modeNameNoCtx(g.mode)
@game.variantLink(g.variant, variantNameNoCtx(g.variant), hintAsTitle = true), @modeNameNoCtx(g.mode)
<div class="actions">
<a class="action decline" href="@routes.Setup.decline(g.id)" data-icon="L">&nbsp;@trans.decline.en()</a>
<a class="action" href="@routes.Round.watcher(g.id, "white")" data-icon="v">&nbsp;View challenge</a>
Expand Down
8 changes: 5 additions & 3 deletions app/views/user/list.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ <h2 @icon.map { i => data-icon="@i" }> @title</h2>
<div class="user_lists">
<div class="user_top">
<h2>@trans.onlinePlayers()</h2>
@online.map { u =>
@userLink(u, cssClass="revert-underline".some)
}
<ul>
@online.map { u =>
<li>@userLink(u, cssClass="revert-underline".some)</li>
}
</ul>
</div>
<a class="more" href="@routes.User.online">@trans.more() »</a>
</div>
Expand Down
6 changes: 2 additions & 4 deletions app/views/user/mini.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(u: User, playing: Option[Game], blocked: Boolean, followed: Boolean, followable: Boolean, rel: Option[lila.relation.Relation])(implicit ctx: Context)
@(u: User, playing: Option[Game], blocked: Boolean, followable: Boolean, rel: Option[lila.relation.Relation])(implicit ctx: Context)
<div class="title">
<div>
@u.profileOrDefault.countryInfo.map {
Expand All @@ -17,9 +17,7 @@
</div>
<div class="ratings">
@miniViewSortedPerfTypes.map { pt =>
@u.perfs(pt.key).map { perf =>
@showPerfRating(pt, perf)
}
@showPerfRating(u, pt)
}
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions app/views/user/show.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ <h3 class="hint--top" data-hint="@perfType.title">
'description -> describeUser(u))) {
<div class="content_box no_padding user_show">
<div class="content_box_top">
@*
@if(info.rank.map(_._1).exists(1==)) {
<span class="trophy hint--left" data-hint="Lichess champion">
<img src="@staticUrl("images/best64.png")" width=64 height=64 />
Expand All @@ -86,6 +87,7 @@ <h3 class="hint--top" data-hint="@perfType.title">
</span>
}
}
*@
<h1 class="lichess_title"><span@if(isOnline(u.id)) { class="connected" } data-icon="r"></span> @u.username</h1>
@if(u.disabled) {
<span class="staff">CLOSED</span>
Expand Down
1 change: 0 additions & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ GET /@/:username controllers.User.show(username: String)
GET /player controllers.User.list
GET /player/online controllers.User.online
GET /player/autocomplete controllers.User.autocomplete
GET /leaderboard controllers.User.leaderboard

# Account
GET /account/passwd controllers.Account.passwd
Expand Down
5 changes: 1 addition & 4 deletions modules/api/src/main/UserApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ private[api] final class UserApi(
case Some(teamId) => lila.team.MemberRepo.userIdsByTeam(teamId) flatMap UserRepo.enabledByIds
case None => $find(pimpQB($query(
UserRepo.enabledSelect ++ (engine ?? UserRepo.engineSelect)
)) sort ((~engine).fold(
UserRepo.sortCreatedAtDesc,
UserRepo.sortRatingDesc
)), makeNb(nb, token))
)) sort UserRepo.sortPerfDesc(lila.rating.PerfType.Standard.key), makeNb(nb, token))
}) flatMap { users =>
users.map(u => makeUrl(R User u.username)).sequenceFu map { urls =>
Json.obj(
Expand Down
2 changes: 2 additions & 0 deletions modules/rating/src/main/Perf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ case class Perf(

case object Perf {

type Key = String

val default = Perf(Glicko.default, 0, Nil, None)

val recentMaxSize = 12
Expand Down
6 changes: 3 additions & 3 deletions modules/rating/src/main/PerfType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package lila.rating
import chess.{ Variant, Speed }

sealed abstract class PerfType(
val key: String,
val key: Perf.Key,
val name: String,
val title: String,
val iconChar: Char)
Expand Down Expand Up @@ -69,8 +69,8 @@ object PerfType {

val default = Standard

def apply(key: String): Option[PerfType] = byKey get key
def orDefault(key: String): PerfType = apply(key) | default
def apply(key: Perf.Key): Option[PerfType] = byKey get key
def orDefault(key: Perf.Key): PerfType = apply(key) | default

val nonPoolPuzzle: List[PerfType] = List(Bullet, Blitz, Classical, Chess960, KingOfTheHill, ThreeCheck)
}
Loading

0 comments on commit e0f0a83

Please sign in to comment.