From 670f08bd389055c4aaf0cb00c46037000fbf421b Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Mon, 31 Dec 2012 14:16:18 +0100 Subject: [PATCH] show opponent elo in user history chart --- app/user/EloChart.scala | 8 +++++--- app/user/HistoryRepo.scala | 12 ++++++------ todo | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/user/EloChart.scala b/app/user/EloChart.scala index 1536975e14..c9d326f05f 100644 --- a/app/user/EloChart.scala +++ b/app/user/EloChart.scala @@ -38,8 +38,8 @@ final class EloChart(rawElos: List[(Int, Int, Option[Int])]) { val opValues = elos map (_._3) elos.zipWithIndex map { case ((ts, elo, op), i) ⇒ (ts, elo, - opValues.slice(i - opMedian, i + opMedian).flatten |> { vs ⇒ - vs.nonEmpty option (vs.sum / vs.size) + opValues.slice(i - opMedian, i + opMedian).flatten |> { vs ⇒ + vs.nonEmpty option (vs.sum / vs.size) }, eloValues.slice(i - eloMedian, i + eloMedian) |> { vs ⇒ vs.sum / vs.size } ) @@ -60,6 +60,8 @@ object EloChart { def apply(historyRepo: HistoryRepo)(user: User): IO[Option[EloChart]] = historyRepo userElos user.username map { elos ⇒ - (elos.size > 1) option { new EloChart(elos) } + (elos.size > 1) option { + new EloChart((user.createdAt.getSeconds.toInt, User.STARTING_ELO, None) :: elos) + } } } diff --git a/app/user/HistoryRepo.scala b/app/user/HistoryRepo.scala index 8ba2e3d6f0..9559afd8f9 100644 --- a/app/user/HistoryRepo.scala +++ b/app/user/HistoryRepo.scala @@ -15,8 +15,8 @@ final class HistoryRepo(collection: MongoCollection) { collection.update( DBObject("_id" -> userId), $push("entries" -> opponentElo.fold( - DBList(DateTime.now, elo, _), - DBList(DateTime.now, elo)) + DBList(DateTime.now.getSeconds.toInt, elo, _), + DBList(DateTime.now.getSeconds.toInt, elo)) ), multi = false, upsert = true) @@ -28,10 +28,10 @@ final class HistoryRepo(collection: MongoCollection) { ).map(history ⇒ (history.as[MongoDBList]("entries").toList collect { case elem: com.mongodb.BasicDBList ⇒ for { - ts ← elem.getAs[Double](0) - elo ← elem.getAs[Double](1) - op = if (elem.size > 2) elem.getAs[Double](2) else none - } yield (ts.toInt, elo.toInt, op map (_.toInt)) + ts ← elem.getAs[Int](0) + elo ← elem.getAs[Int](1) + op = if (elem.size > 2) elem.getAs[Int](2) else None + } yield (ts, elo, op) }).flatten sortBy (_._1) ) } except { err ⇒ putStrLn("ERR while parsing user history: " + err.getMessage) inject Nil } diff --git a/todo b/todo index 5e5e4228da..7ba9bd3ec8 100644 --- a/todo +++ b/todo @@ -55,3 +55,4 @@ dark bug http://en.lichess.org/games/search traduction intégrale block user creation from an IP mute IP +add elo filter to the lobby