show more interresting current games
This commit is contained in:
parent
ddbd848319
commit
474d5212fe
|
@ -28,9 +28,10 @@ object Game extends LilaController with BaseGame {
|
|||
}
|
||||
|
||||
def realtime = Open { implicit ctx ⇒
|
||||
GameRepo recentGames 9 zip makeListMenu map {
|
||||
case (games, menu) ⇒ html.game.realtime(games, menu)
|
||||
}
|
||||
GameRepo.featuredCandidates map lila.game.Featured.sort map (_ take 9) zip
|
||||
makeListMenu map {
|
||||
case (games, menu) ⇒ html.game.realtime(games, menu)
|
||||
}
|
||||
}
|
||||
|
||||
def all(page: Int) = Open { implicit ctx ⇒
|
||||
|
|
|
@ -47,19 +47,19 @@ final class Featured(
|
|||
|
||||
private def valid(game: Game) = game.isBeingPlayed
|
||||
|
||||
private def feature: Option[Game] = Featured best {
|
||||
private def feature: Option[Game] = Featured sort {
|
||||
GameRepo.featuredCandidates.await filter valid
|
||||
}
|
||||
} lastOption
|
||||
}))
|
||||
}
|
||||
|
||||
object Featured {
|
||||
|
||||
case object GetOne
|
||||
private case object GetOne
|
||||
|
||||
def best(games: List[Game]) = (games sortBy score).lastOption
|
||||
def sort(games: List[Game]): List[Game] = games sortBy score
|
||||
|
||||
def score(game: Game): Float = heuristics map {
|
||||
private def score(game: Game): Float = heuristics map {
|
||||
case (fn, coefficient) ⇒ heuristicBox(fn(game)) * coefficient
|
||||
} sum
|
||||
|
||||
|
@ -75,16 +75,16 @@ object Featured {
|
|||
speedHeuristic -> 1,
|
||||
progressHeuristic -> 0.5f)
|
||||
|
||||
def eloHeuristic(color: Color): Heuristic = game ⇒
|
||||
private def eloHeuristic(color: Color): Heuristic = game ⇒
|
||||
eloBox(game.player(color).elo | 1100)
|
||||
|
||||
def speedHeuristic: Heuristic = game ⇒
|
||||
private def speedHeuristic: Heuristic = game ⇒
|
||||
1 - timeBox(game.estimateTotalTime)
|
||||
|
||||
def progressHeuristic: Heuristic = game ⇒
|
||||
private def progressHeuristic: Heuristic = game ⇒
|
||||
1 - turnBox(game.turns)
|
||||
|
||||
// boxes and reduce to 0..1 range
|
||||
def box(in: Range.Inclusive)(v: Float): Float =
|
||||
private def box(in: Range.Inclusive)(v: Float): Float =
|
||||
(math.max(in.start, math.min(v, in.end)) - in.start) / (in.end - in.start).toFloat
|
||||
}
|
||||
|
|
|
@ -142,18 +142,13 @@ object GameRepo {
|
|||
)(_.asOpt[ID])
|
||||
|
||||
def featuredCandidates: Fu[List[Game]] = $find(
|
||||
Query.playable ++ Query.clock(true) ++ Json.obj(
|
||||
"t" -> $gt(1),
|
||||
Query.playable ++ Query.clock(true) ++ Query.turnsGt(1) ++ Json.obj(
|
||||
createdAt -> $gt($date(DateTime.now - 4.minutes)),
|
||||
updatedAt -> $gt($date(DateTime.now - 15.seconds))
|
||||
))
|
||||
|
||||
def count(query: Query.type ⇒ JsObject): Fu[Int] = $count(query(Query))
|
||||
|
||||
def recentGames(limit: Int): Fu[List[Game]] = $find(
|
||||
$query(Query.started ++ Query.turnsGt(1)) sort Query.sortCreated, limit
|
||||
)
|
||||
|
||||
def nbPerDay(days: Int): Fu[List[Int]] =
|
||||
((days to 1 by -1).toList map { day ⇒
|
||||
val from = DateTime.now.withTimeAtStartOfDay - day.days
|
||||
|
|
Loading…
Reference in a new issue