Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more hacky things in reports

  • Loading branch information...
commit eb715ac127032b30ef75497a3af3dc1738c0f17c 1 parent 249d471
@jrochkind authored
View
51 app/controllers/report_controller.rb
@@ -2,6 +2,8 @@ class ReportController < ApplicationController
def index
@results = fetch_stats
+ @match_up_keys, @match_up_count = fetch_sanity_check_grid
+ @demographic_overview = fetch_demographic_overview
end
protected
@@ -45,4 +47,53 @@ def fetch_stats
return Selection.connection.select_all( sql )
end
+ # again some raw sql, a grid of how often each engine was faced
+ # off against each other engine in a match that resulted in
+ # a a/b/tie selection.
+ def fetch_sanity_check_grid
+ results = Selection.connection.select_all("select option_a, option_b, count(*) as count from selections group by option_a, option_b")
+ # we get back pairings that are A vs B in one row, and B vs A in a different one. Combine em all.
+
+ match_ups = Hash.new do |h, k|
+ h[k] = Hash.new(0)
+ end
+
+ results.each do |row|
+ normal = [row["option_a"], row["option_b"]].sort
+ match_ups[normal.first][normal.last] += row["count"]
+ match_ups[normal.last][normal.first] += row["count"]
+ end
+
+ engines = Selection.connection.
+ select_all("select option_a as engine from selections union select option_b as engine from selections").
+ collect {|row| row["engine"]}
+
+ return engines, match_ups
+
+ end
+
+ def fetch_demographic_overview
+ sql = <<-EOS
+ select demographic_school, demographic_status, count(*) as count
+ from selections
+ group by demographic_school, demographic_status
+
+ union all
+
+ select demographic_school, "TOTAL" as demographic_status, count(*) as count
+ from selections
+ group by demographic_school
+
+ union all
+
+ select "TOTAL" as demographic_school, demographic_status, count(*) as count
+ from selections
+ group by demographic_status
+ EOS
+
+ results = Selection.connection.select_all(sql)
+
+ return results
+ end
+
end
View
48 app/views/report/index.html.erb
@@ -4,7 +4,7 @@
<table class="table table-striped">
<tr>
<th>engine</th>
- <th>total selections</th>
+ <th>total times participating</th>
<th>wins</th>
<th>losses</th>
<th>ties</th>
@@ -23,3 +23,49 @@
<% end %>
</table>
+
+<h2> Match-up count sanity check </h2>
+<table class="table table-striped">
+ <tr>
+ <th>vs.</th>
+ <% @match_up_keys.each do |engine| %>
+ <th><%= engine %> </th>
+ <% end %>
+ <tr>
+
+
+ <% @match_up_keys.each do |engine| %>
+ <tr>
+ <th><%= engine %> </th>
+ <% @match_up_keys.each do |second_engine| %>
+ <td>
+ <% if engine == second_engine %>
+ *
+ <% else %>
+ <%= @match_up_count[engine][second_engine] %>
+ <% end %>
+ </td>
+ <% end %>
+ </tr>
+ <% end %>
+
+
+
+</table>
+
+
+<h2>Participants demographic overview</h2>
+<table class="table table-striped">
+ <tr>
+ <th>School</th><th>Status</th><th>count</th>
+ <tr>
+
+ <% @demographic_overview.each do |row| %>
+ <tr>
+ <td><%= row["demographic_school"] %></td>
+ <td><%= row["demographic_status"] %></td>
+ <td><%= row["count"] %></td>
+ </tr>
+ <% end %>
+
+</table>
Please sign in to comment.
Something went wrong with that request. Please try again.