stat_board 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -35,10 +35,19 @@ In `config/initializers/stat_board.rb`:
35
35
  StatBoard.username = "user"
36
36
  StatBoard.password = "pass"
37
37
 
38
+ ## Issues
39
+
40
+ * Models can be specified as strings rather than constants
41
+ if you encounter loading order issues.
42
+ * If you're using the Asset Pipeline, you'll need to add
43
+ `stat_board/bootstrap.css` to your precompile paths.
44
+
38
45
  ## Contributing
39
46
 
40
47
  Happily accepting contributions to improve StatBoard. To contribute, fork, add your thing, add some specs, and send a pleasantly worded pull request.
41
48
 
49
+ In order to setup the databases locally, you'll need to: `bundle exec rake db:migrate app:db:test:prepare`
50
+
42
51
  * * *
43
52
 
44
53
  StatBoard is released under the [MIT License][mit]. See MIT-LICENSE for further details.
@@ -1,4 +1,39 @@
1
1
  module StatBoard
2
2
  class ApplicationController < ActionController::Base
3
+
4
+ private
5
+
6
+ helper_method :date_steps, :first_day_ever, :resources_by_date
7
+
8
+ def date_steps
9
+ @date_steps ||= date_range.count / [date_range.count, 50].min
10
+ end
11
+
12
+ def first_day_ever
13
+ @first_day_ever ||= first_day_of_each_model.sort.first
14
+ end
15
+
16
+ def resources_by_date(klass_name)
17
+ klass = klass_name.to_s.constantize
18
+ created_ats = klass.pluck(:created_at).map(&:to_date)
19
+
20
+ date_range.step(date_steps).map do |date|
21
+ created_ats.count{|c_a| c_a < date}
22
+ end.to_s
23
+ end
24
+
25
+ def first_day_of_each_model
26
+ StatBoard.models.map { |m| first_day_of(m) }
27
+ end
28
+
29
+ def first_day_of(klass_name)
30
+ klass = klass_name.to_s.constantize
31
+ klass.order("created_at ASC").first.try(:created_at) || Time.now
32
+ end
33
+
34
+ def date_range
35
+ @date_range ||= first_day_ever.to_date..Date.today
36
+ end
37
+
3
38
  end
4
39
  end
@@ -3,6 +3,8 @@
3
3
  <head>
4
4
  <title><%= StatBoard.title || "StatBoard" %></title>
5
5
  <%= stylesheet_link_tag "stat_board/bootstrap", :media => "all" %>
6
+ <%= javascript_include_tag "application" %>
7
+
6
8
  <%= csrf_meta_tags %>
7
9
  </head>
8
10
  <body>
@@ -0,0 +1,32 @@
1
+ <div id="container"></div>
2
+
3
+ <%= javascript_include_tag "highcharts" %>
4
+ <script>
5
+ var $container = $("#container")
6
+ var pointInterval = <%= date_steps.days * 1000 %>;
7
+ var pointStart = <%= first_day_ever.to_i * 1000 %>;
8
+
9
+ new Highcharts.Chart({
10
+ chart: {
11
+ backgroundColor: '#FFEFD5',
12
+ height: 500,
13
+ renderTo: 'container'
14
+ },
15
+ title: { text: '' },
16
+ xAxis: { type: 'datetime' },
17
+ yAxis: {
18
+ title: { text: 'Count' },
19
+ min: 0
20
+ },
21
+ series: [
22
+ <% StatBoard.models.each do |model| %>
23
+ {
24
+ name: "<%= model.to_s.pluralize %>",
25
+ pointInterval: pointInterval,
26
+ pointStart: pointStart,
27
+ data: <%= resources_by_date(model.to_s) %>
28
+ },
29
+ <% end %>
30
+ ]
31
+ });
32
+ </script>
@@ -2,6 +2,9 @@
2
2
  <div class="row">
3
3
  <%= render :partial => "chart", :collection => @reports, :as => :report %>
4
4
  </div>
5
+
6
+ <%= render "graph" %>
7
+
5
8
  <% else %>
6
9
  Please specify some models by setting <code>StatBoard.models</code>
7
10
  (in <code>config/initializers/stat_board.rb</code>, for example).
@@ -1,11 +1,5 @@
1
1
  module StatBoard
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace StatBoard
4
-
5
- if Rails.version > "3.1"
6
- initializer "StatBoard precompile hook" do |app|
7
- app.config.assets.precompile += %w(stat_board/bootstrap.css)
8
- end
9
- end
10
4
  end
11
5
  end
@@ -2,11 +2,11 @@ module StatBoard
2
2
  module Reports
3
3
  class MonthlyReport < Report
4
4
  def name
5
- "This Month"
5
+ "Last 30 days"
6
6
  end
7
7
 
8
8
  def scope(model)
9
- super.where(["created_at > ?", 1.month.ago])
9
+ super.where(["created_at > ?", 30.days.ago])
10
10
  end
11
11
  end
12
12
  end
@@ -2,7 +2,7 @@ module StatBoard
2
2
  module Reports
3
3
  class WeeklyReport < Report
4
4
  def name
5
- "This Week"
5
+ "Last 7 days"
6
6
  end
7
7
 
8
8
  def scope(model)
@@ -1,3 +1,3 @@
1
1
  module StatBoard
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stat_board
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-29 00:00:00.000000000 Z
12
+ date: 2013-11-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: highcharts-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: sqlite3
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -60,7 +76,7 @@ dependencies:
60
76
  - !ruby/object:Gem::Version
61
77
  version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
- name: capybara
79
+ name: pry
64
80
  requirement: !ruby/object:Gem::Requirement
65
81
  none: false
66
82
  requirements:
@@ -75,6 +91,70 @@ dependencies:
75
91
  - - ! '>='
76
92
  - !ruby/object:Gem::Version
77
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: launchy
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: capybara
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.1.4
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.1.4
126
+ - !ruby/object:Gem::Dependency
127
+ name: capybara-webkit
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 0.13.0
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 0.13.0
142
+ - !ruby/object:Gem::Dependency
143
+ name: database_cleaner
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 0.9.1
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 0.9.1
78
158
  description: Simple dashboard of records created this week, this month, and all time,
79
159
  mountable as a Rails Engine.
80
160
  email:
@@ -88,6 +168,7 @@ files:
88
168
  - app/controllers/stat_board/stats_controller.rb
89
169
  - app/views/layouts/stat_board/application.html.erb
90
170
  - app/views/stat_board/stats/_chart.html.erb
171
+ - app/views/stat_board/stats/_graph.html.erb
91
172
  - app/views/stat_board/stats/index.html.erb
92
173
  - config/routes.rb
93
174
  - lib/stat_board/engine.rb
@@ -122,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
203
  version: '0'
123
204
  requirements: []
124
205
  rubyforge_project:
125
- rubygems_version: 1.8.24
206
+ rubygems_version: 1.8.25
126
207
  signing_key:
127
208
  specification_version: 3
128
209
  summary: Simple dashboard of records created this week, this month, and all time,