Permalink
Browse files

Adding Stats section. For now, only a simple pie chart is there.

1 parent 25632a6 commit fe05a511a36d7b057cdfc266e499013caed86aab @andmej committed Oct 9, 2010
@@ -0,0 +1,4 @@
+class StatsController < ApplicationController
+ def index
+ end
+end
@@ -0,0 +1,15 @@
+module StatsHelper
+ def pie_chart_for_solutions
+ count = {}
+ Solution.all.each do |solution|
+ count[solution.user] ||= 0
+ count[solution.user] += 1
+ end
+
+ total = Solution.count
+ data = count.collect { |user, number| number }
+ labels = count.collect { |user, number| "#{user.name} (#{total == 0 ? 0 : (100.0 * number / total).round}%)" }
+
+ Gchart.pie(:data => data, :labels => labels, :size => '695x431', :theme => :thirty7signals)
+ end
+end
@@ -22,6 +22,7 @@
<%= link_to "Judges", judges_path %> |
<%= link_to "Problems", problems_path %> |
<%= link_to "Users", users_path %> |
+ <%= link_to "Stats", stats_path %> |
<% if logged_in? %>
<%= link_to "Logout", logout_path, :method => :delete %> |
@@ -0,0 +1,9 @@
+<% title "Stats" %>
+
+<div class="list_element">
+ <h3>
+ Percentage of solutions by each user
+ </h3>
+
+ <%= image_tag(pie_chart_for_solutions, :alt => "Distribution of solutions by user") %>
+</div>
@@ -9,6 +9,8 @@
Rails::Initializer.run do |config|
config.time_zone = 'Bogota'
+ config.gem "googlecharts"
+
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
config.action_controller.session = {
View
@@ -3,26 +3,20 @@
map.login "login", :controller => "user_sessions", :action => "new"
map.logout "logout", :controller => "user_sessions", :action => "destroy"
-
map.signup "signup", :controller => "users", :action => "new"
map.resources :solutions, :except => [:show, :index, :new]
map.resources :users, :member => [ :edit_password ]
-
map.resources :user_sessions
-
map.resources :judges do |judge|
judge.resources :problems, :only => :new
end
-
map.resources :problems, :except => :new do |problem|
problem.resources :solutions, :only => :new
end
-
+ map.resources :stats
map.root :controller => "home", :action => "index"
-
map.about "/about", :controller => "home", :action => "about"
- map.connect "/about", :controller => "home", :action => "about"
# Uncomment these route and go to /home/test_mail to test the SMTP server.
# This sends a message to andmej@gmail.com (Change it in /controllers/home_controller.rb)
@@ -1,5 +1,7 @@
one:
- explanation: MyText
+ explanation: "This is a very nice solution to a very nice problem."
+ user_id: 1
two:
- explanation: MyText
+ explanation: "This one is not that cute but who cares. After all, this is a test!"
+ user_id: 2
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class StatsHelperTest < ActionView::TestCase
+ def test_pie_chart_for_solutions
+ s = pie_chart_for_solutions
+ assert s =~ /http:\/\/chart.apis.google.com\/chart/
+ end
+end

0 comments on commit fe05a51

Please sign in to comment.