Permalink
Browse files

Flot and jStat distribution graphs in profile

  • Loading branch information...
1 parent 4cc4d53 commit e9499c79fd7e2b74410a5002393ee0bb96cdc865 @proglottis committed Jan 26, 2013
View
@@ -44,6 +44,7 @@ gem 'kaminari'
gem 'glicko2'
gem 'whenever', :require => false
gem 'exception_notification'
+gem 'flot-rails'
group :test, :development do
gem 'minitest-rails'
View
@@ -74,6 +74,8 @@ GEM
faraday_middleware (0.9.0)
faraday (>= 0.7.4, < 0.9)
ffi (1.3.1)
+ flot-rails (0.0.2)
+ jquery-rails
glicko2 (0.1.1)
guard (1.6.1)
listen (>= 0.6.0)
@@ -258,6 +260,7 @@ DEPENDENCIES
dalli
exception_notification
factory_girl_rails (~> 4.0)
+ flot-rails
glicko2
guard-minitest
jquery-rails
@@ -1,4 +1,5 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
+
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
@@ -13,4 +14,7 @@
//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
+//= require jquery.flot
+//= require jquery.flot.resize
+//= require jstat-1.0.0
//= require_tree .
@@ -0,0 +1,42 @@
+jQuery ->
+ percentageFormatter = (x) -> x * 100.0 + "%"
+
+ $('.tournament.plot').each (i, element) ->
+ element_id = $(element).attr('id')
+ data = $.parseJSON($(element).attr('data-ratings'))
+ options = {
+ series: {
+ lines: { show: true }
+ },
+ yaxis: {
+ min: 0.0,
+ max: 0.0,
+ tickFormatter: percentageFormatter
+ },
+ xaxis: {
+ min: 1000.0,
+ max: 1000.0
+ }
+ }
+ plot_data = $.map(data, (rating, i) ->
+ distribution = new NormalDistribution(rating['rating'], rating['rating_deviation'])
+ range = distribution.getRange()
+ range_points = range.getPoints()
+ options.xaxis.min = Math.min(options.xaxis.min, range_points[0])
+ options.xaxis.max = Math.max(options.xaxis.max, range_points[range_points.length - 1])
+ pdfs = distribution.density(range)
+ options.yaxis.max = Math.max(options.yaxis.max, jstat.max(pdfs) * 1.1)
+ data = []
+ $.each(pdfs, (i) ->
+ data.push([range_points[i], pdfs[i]])
+ )
+ return {
+ data: data,
+ hoverable: true,
+ clickable: false,
+ label: rating['user_name']
+ }
+ )
+ plot = new Plot(element_id + ' .plot', options)
+ plot.setData(plot_data)
+ plot.render()
@@ -6,11 +6,10 @@
<h1><%= @user.name %></h1>
</div>
-<ul>
-<%= content_tag_for :li, @tournaments do |tournament| %>
+<%= div_for @tournaments do |tournament| %>
<%= link_to tournament.name, tournament_path(tournament) %>
+ <%= div_for tournament, :class => "plot span9", :style => "height:100px;", :'data-ratings' => tournament.glicko2_ratings.where(:user_id => [current_user.id, @user.id]).map {|rating| {:rating => rating.rating, :rating_deviation => rating.rating_deviation, :user_name => rating.user.name}}.to_json do %><% end %>
<% end %>
-</ul>
<%= page_entries_info @games, :entry_name => 'game' %>
<%= div_for @games, :class => 'media' do |game| %>
Oops, something went wrong.

0 comments on commit e9499c7

Please sign in to comment.