From 0d7a8a35a378cae2519a77bcccb6d56ecb727bdf Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Mon, 31 Dec 2012 16:45:33 +0100 Subject: [PATCH] elo chart debugging --- app/user/HistoryRepo.scala | 24 ++++++++++++++++-------- app/user/UserRepo.scala | 4 ++-- todo | 1 + 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/user/HistoryRepo.scala b/app/user/HistoryRepo.scala index 3c6d3c4913..1d1d8bfc25 100644 --- a/app/user/HistoryRepo.scala +++ b/app/user/HistoryRepo.scala @@ -26,13 +26,21 @@ final class HistoryRepo(collection: MongoCollection) { ~collection.findOne( DBObject("_id" -> username.toLowerCase) ).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)) - }).flatten sortBy (_._1) + (history.as[MongoDBList]("entries").toList collect { + case elem: com.mongodb.BasicDBList ⇒ try { + 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)) + } + catch { + case (err: Exception) ⇒ { + println("ERR while parsing %s history: %s(%s)".format(username, err.getClass, err.getMessage)) + none + } + } + }).flatten sortBy (_._1) ) - } except { err ⇒ putStrLn("ERR while parsing user history: " + err.getMessage) inject Nil } + } } diff --git a/app/user/UserRepo.scala b/app/user/UserRepo.scala index 2d6e17ad14..5f449a716a 100644 --- a/app/user/UserRepo.scala +++ b/app/user/UserRepo.scala @@ -167,14 +167,14 @@ class UserRepo(collection: MongoCollection) val countEnabled: IO[Int] = io { count(enabledQuery).toInt } - def usernamesLike(username: String): IO[List[String]] = io { + def usernamesLike(username: String, max: Int = 10): IO[List[String]] = io { val escaped = """^([\w-]*).*$""".r.replaceAllIn(normalize(username), _ group 1) val regex = "^" + escaped + ".*$" collection.find( DBObject("_id" -> regex.r), DBObject("username" -> 1)) .sort(DBObject("_id" -> 1)) - .limit(10) + .limit(max) .toList .map(_.getAs[String]("username")) .flatten diff --git a/todo b/todo index 7ba9bd3ec8..5ea1cb269a 100644 --- a/todo +++ b/todo @@ -56,3 +56,4 @@ traduction intégrale block user creation from an IP mute IP add elo filter to the lobby +elo chart bug http://en.lichess.org/@/amir8869154