fix puzzle timeline & chart

This commit is contained in:
Thibault Duplessis 2016-11-07 19:12:55 +01:00
parent 5acbcebaec
commit 267deae978
4 changed files with 10 additions and 12 deletions

View file

@ -63,7 +63,7 @@ object JsData extends lila.Steroids {
Json.obj(
"rating" -> i.user.perfs.puzzle.intRating,
"history" -> i.history.map { r =>
Json.arr(r.puzzleId, r.ratingDiff)
Json.arr(r.puzzleId, r.ratingDiff, r.rating)
}
)
})

View file

@ -19,7 +19,7 @@ case class Round(
object Round {
case class Mini(puzzleId: Int, ratingDiff: Int)
case class Mini(puzzleId: Int, ratingDiff: Int, rating: Int)
object BSONFields {
val puzzleId = "p"
@ -59,6 +59,7 @@ object Round {
import BSONFields._
def read(doc: Bdoc): Mini = Mini(
puzzleId = doc.getAs[Int](puzzleId) err "RoundMini no puzzleId",
rating = doc.getAs[Int](rating) err "RoundMini no rating",
ratingDiff = doc.getAs[Int](ratingDiff) err "RoundMini no ratingDiff")
}
}

View file

@ -29,9 +29,11 @@ object UserInfos {
$doc(
"_id" -> false,
Round.BSONFields.puzzleId -> true,
Round.BSONFields.ratingDiff -> true
Round.BSONFields.ratingDiff -> true,
Round.BSONFields.rating -> true
)).sort($sort desc Round.BSONFields.date)
.cursor[Round.Mini]()
.gather[List](historySize atLeast chartSize)
.map(_.reverse)
}
}

View file

@ -22,14 +22,10 @@ function renderUserInfos(ctrl) {
if (hash == ctx.hash) return;
ctx.hash = hash;
var dark = document.body.classList.contains('dark');
var slots = new Array(historySize + 1);
var rating = d.user.rating;
slots[historySize] = rating;
for (var i = 0; i < historySize; i++) {
if (d.user.history[i]) rating += d.user.history[i][1];
slots[historySize - 1 - i] = rating;
}
jQuery(el).sparkline(slots, {
var points = d.user.history.map(function(r) {
return r[2] + r[1];
});
jQuery(el).sparkline(points, {
type: 'line',
width: '213px',
height: '80px',
@ -252,7 +248,6 @@ function renderHistory(ctrl) {
var d = ctrl.data;
var slots = [];
for (var i = 0; i < historySize; i++) slots[i] = d.user.history[i] || null;
slots.reverse();
return m('div.history', [
m('div.timeline', [
slots.map(function(s) {