Commit f294743

mo khan <mo@mokhan.ca>
2015-02-05 05:40:04
add charts.
1 parent 35b0887
Changed files (5)
app/controllers/agents/events_controller.rb
@@ -3,7 +3,7 @@ module Agents
     before_action :load_agent
 
     def index
-      @events = Event.all.order(created_at: :desc)
+      @events = @agent.events.order(created_at: :desc)
     end
 
     def new
app/views/agents/events/index.html.erb
@@ -31,4 +31,14 @@
       </tbody>
     </table>
   </div>
+
+  <div class="small-12 columns">
+    <h2>Events per minute</h2>
+    <%= line_chart @agent.events.group_by_minute(:created_at).count %>
+  </div>
+
+  <div class="small-12 columns">
+    <h2>Events by category</h2>
+    <%= pie_chart @agent.events.group(:name).count %>
+  </div>
 </div>
app/views/layouts/application.html.erb
@@ -9,6 +9,7 @@
     <%= stylesheet_link_tag    "application" %>
     <%= javascript_include_tag "vendor/modernizr" %>
     <%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
+    <%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
     <%= csrf_meta_tags %>
   </head>
 
Gemfile
@@ -37,6 +37,8 @@ gem 'bunny'
 gem 'sneakers'
 gem 'foreman'
 gem 'foundation-rails'
+gem 'chartkick'
+gem 'groupdate'
 
 group :development, :test do
   # Call 'byebug' anywhere in the code to stop execution and get a debugger console
Gemfile.lock
@@ -49,6 +49,7 @@ GEM
       slop (~> 3.6)
     celluloid (0.16.0)
       timers (~> 4.0.0)
+    chartkick (1.3.2)
     coffee-rails (4.1.0)
       coffee-script (>= 2.2.0)
       railties (>= 4.0.0, < 5.0)
@@ -73,6 +74,8 @@ GEM
       sass (>= 3.3.0, < 3.5)
     globalid (0.3.0)
       activesupport (>= 4.1.0)
+    groupdate (2.4.0)
+      activesupport (>= 3)
     hike (1.2.3)
     hitimes (1.2.2)
     i18n (0.7.0)
@@ -187,9 +190,11 @@ PLATFORMS
 DEPENDENCIES
   bunny
   byebug
+  chartkick
   coffee-rails (~> 4.1.0)
   foreman
   foundation-rails
+  groupdate
   jbuilder (~> 2.0)
   jquery-rails
   listen