show opponent elo in user history chart

This commit is contained in:
Thibault Duplessis 2012-12-31 14:16:18 +01:00
parent e1daf04112
commit 670f08bd38
3 changed files with 12 additions and 9 deletions

View file

@ -38,8 +38,8 @@ final class EloChart(rawElos: List[(Int, Int, Option[Int])]) {
val opValues = elos map (_._3) val opValues = elos map (_._3)
elos.zipWithIndex map { elos.zipWithIndex map {
case ((ts, elo, op), i) (ts, elo, case ((ts, elo, op), i) (ts, elo,
opValues.slice(i - opMedian, i + opMedian).flatten |> { vs opValues.slice(i - opMedian, i + opMedian).flatten |> { vs
vs.nonEmpty option (vs.sum / vs.size) vs.nonEmpty option (vs.sum / vs.size)
}, },
eloValues.slice(i - eloMedian, i + eloMedian) |> { vs 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]] = def apply(historyRepo: HistoryRepo)(user: User): IO[Option[EloChart]] =
historyRepo userElos user.username map { elos 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)
}
} }
} }

View file

@ -15,8 +15,8 @@ final class HistoryRepo(collection: MongoCollection) {
collection.update( collection.update(
DBObject("_id" -> userId), DBObject("_id" -> userId),
$push("entries" -> opponentElo.fold( $push("entries" -> opponentElo.fold(
DBList(DateTime.now, elo, _), DBList(DateTime.now.getSeconds.toInt, elo, _),
DBList(DateTime.now, elo)) DBList(DateTime.now.getSeconds.toInt, elo))
), ),
multi = false, multi = false,
upsert = true) upsert = true)
@ -28,10 +28,10 @@ final class HistoryRepo(collection: MongoCollection) {
).map(history ).map(history
(history.as[MongoDBList]("entries").toList collect { (history.as[MongoDBList]("entries").toList collect {
case elem: com.mongodb.BasicDBList for { case elem: com.mongodb.BasicDBList for {
ts elem.getAs[Double](0) ts elem.getAs[Int](0)
elo elem.getAs[Double](1) elo elem.getAs[Int](1)
op = if (elem.size > 2) elem.getAs[Double](2) else none op = if (elem.size > 2) elem.getAs[Int](2) else None
} yield (ts.toInt, elo.toInt, op map (_.toInt)) } yield (ts, elo, op)
}).flatten sortBy (_._1) }).flatten sortBy (_._1)
) )
} except { err putStrLn("ERR while parsing user history: " + err.getMessage) inject Nil } } except { err putStrLn("ERR while parsing user history: " + err.getMessage) inject Nil }

1
todo
View file

@ -55,3 +55,4 @@ dark bug http://en.lichess.org/games/search
traduction intégrale traduction intégrale
block user creation from an IP block user creation from an IP
mute IP mute IP
add elo filter to the lobby