Skip to content

Commit

Permalink
blind implementation of players move times pie chart
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 29, 2012
1 parent feaaf4f commit c7d9397
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 5 deletions.
36 changes: 36 additions & 0 deletions app/analyse/TimePie.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package lila
package analyse

import game.{ DbPlayer, Pov }

import com.codahale.jerkson.Json

final class TimePie(val pov: Pov) {

import pov._

val columns = Json generate List(
"string" :: "Move time" :: Nil,
"number" :: "Moves" :: Nil)

def rows = Json generate {

val steps = (0 to 5) ++ (6 to 12 by 2) ++ (15 to 30 by 3) ++ (35 to 60 by 5)

val ranges = steps zip (steps drop 1) map { case (a, b) Range(a, b) }

val moveTimes = player.moveTimeList

def nbMoves(range: Range) = moveTimes count range.contains

def nameRange(range: Range) = {
import range._
if (min == max) (min < 2).fold("%d second", "%d seconds") format min
else "%d to %d seconds".format(min, max)
}

ranges zip (ranges map nbMoves) collect {
case (range, nb) if nb > 0 List(nameRange(range), nb)
}
}
}
4 changes: 3 additions & 1 deletion app/controllers/Analyse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import lila._
import views._
import analyse._
import game.Pov
import round.AnalysisAvailable

import play.api.mvc._
Expand Down Expand Up @@ -61,7 +62,8 @@ object Analyse extends LilaController {
IOptionOk(gameRepo game id) { game
html.analyse.stats(
game = game,
timeChart = new TimeChart(game))
timeChart = new TimeChart(game),
timePies = Pov(game) map { new TimePie(_) })
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/game/Pov.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ case class Pov(game: DbGame, color: Color) {

object Pov {

def apply(game: DbGame): List[Pov] = game.players.map { apply(game, _) }

def apply(game: DbGame, player: DbPlayer) = new Pov(game, player.color)

def apply(game: DbGame, playerId: String): Option[Pov] =
Expand Down
2 changes: 1 addition & 1 deletion app/templating/AssetHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import play.api.templates.Html

trait AssetHelper {

val assetVersion = 11
val assetVersion = 12

def cssTag(name: String) = css("stylesheets/" + name)

Expand Down
9 changes: 8 additions & 1 deletion app/views/analyse/stats.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(game: DbGame, timeChart: lila.analyse.TimeChart)(implicit ctx: Context)
@(game: DbGame, timeChart: lila.analyse.TimeChart, timePies: List[lila.analyse.TimePie])(implicit ctx: Context)

@moreCss = {
@cssTag("gamestats.css")
Expand All @@ -24,5 +24,12 @@ <h1 class="title">
data-title="Time per move evolution"
data-columns="@timeChart.columns"
data-rows="@timeChart.rows"></div>
@timePies.map { pie =>
<div
class="move-times"
data-title="@userIdToUsername(pie.pov.player.userId)"
data-columns="@pie.columns"
data-rows="@pie.rows"></div>
}
</div>
}
14 changes: 14 additions & 0 deletions public/javascripts/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ function drawCharts() {
});
});

$('div.move-times').each(function() {
var data = elemToData(this);
var chart = new google.visualization.PieChart(this);
chart.draw(data, {
width: 312,
height: 200,
titlePosition: 'none',
legend: {textStyle: textcolor},
chartArea:{left:"0%",width:"100%",height:"100%"},
is3D: true,
backgroundColor: bg
});
});

$('div.adv_chart').each(function() {
var data = elemToData(this);
var chart = new google.visualization.AreaChart(this);
Expand Down
2 changes: 0 additions & 2 deletions todo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ start chess960 after both player move http:https://fr.lichess.org/forum/lichess-feedba
chess960 confirmation http:https://fr.lichess.org/forum/lichess-feedback/separate-960-lobby?page=1#7
use POST instead of GET where it makes sense
guess friend list
use twitter tooltip instead of tipsy http:https://twitter.github.com/bootstrap/javascript.html#tooltip
volume control
takeback play 2 times ?? http:https://en.lichess.org/analyse/nfjchnmo/black move 45
movetimes chart
show lobby chat to anon (and rated games?) or show empty chat
Expand Down

0 comments on commit c7d9397

Please sign in to comment.