stat_board 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de0bd3c95825876eee22d01d934b8289212e806ce954a817567f9c5fb3fed2d7
4
- data.tar.gz: 452130740530b8fc1da4d3bb301618fbbf6b16ed29dabbebbe75c0c687d41419
3
+ metadata.gz: 56119a7dfb242c2870891827f9c4f02cef7132a49e0d12ed277f0de62dcf3761
4
+ data.tar.gz: 40c2c2d54dfac7611707ddbaf5102382703f0c3a5ab934388496fbf14ebae2ad
5
5
  SHA512:
6
- metadata.gz: 0013c7c2908001696a1ed86c7286b7ae02dbc9a0481a7c81eb5af49cb5e795afbd52f7c272a9e1c4e8aac4fdfa2af65a074909793b3193aa4722e9ba5879a71d
7
- data.tar.gz: 897ea2ade4d762b3b88dc56137d5a358589e08e5915e23c1bcaf966128b7e17cac79c82116392d3ed293b9512f34dd6a877a757fa8aacce178bfaa5d4868f71e
6
+ metadata.gz: a631aca73ed4e7bcd7dcc870d856a1c392e0af94555444678e639c7dd90e960e52480e8554872cf96622422344d02ebc397f36456b22adc37c13f21d978d160b
7
+ data.tar.gz: 9be14830e8df286e04dedb8f60cbe9320da7cd288e4b63c1344de0ab59661c8508b90589ed49c8283e80554a59e611c3f76466ae2d1ce8c32412c05da047f0eb
data/README.markdown CHANGED
@@ -52,7 +52,7 @@ In `config/initializers/stat_board.rb`:
52
52
  module StatBoard
53
53
  module Reports
54
54
  class DayReport < Report
55
- def name(original_date = nil)
55
+ def name
56
56
  "Last day"
57
57
  end
58
58
 
@@ -1,3 +1,14 @@
1
+ .statboard-filter form {
2
+ display: flex;
3
+ margin: 20px auto;
4
+ width: 500px;
5
+ }
6
+
7
+ .statboard-filter form input {
8
+ margin: 0 10px;
9
+ }
10
+
11
+
1
12
  /*!
2
13
  * Bootstrap v2.2.1
3
14
  *
@@ -1,15 +1,13 @@
1
1
  module StatBoard
2
2
  class ApplicationController < ActionController::Base
3
+ before_action :basic_authenticate, :if => lambda { StatBoard.username && StatBoard.password }
3
4
 
4
5
  private
5
6
 
6
- [:date_steps, :first_day_ever, :resources_by_date].each do |method|
7
- helper_method method
8
- delegate method, :to => :graph_helper
9
- end
10
-
11
- def graph_helper
12
- @graph_helper ||= GraphHelper.new
7
+ def basic_authenticate
8
+ authenticate_or_request_with_http_basic do |name, password|
9
+ name == StatBoard.username && password == StatBoard.password
10
+ end
13
11
  end
14
12
 
15
13
  end
@@ -2,18 +2,46 @@ require_dependency "stat_board/application_controller"
2
2
 
3
3
  module StatBoard
4
4
  class StatsController < ApplicationController
5
- before_action :basic_authenticate, :if => lambda { StatBoard.username && StatBoard.password }
6
5
 
7
6
  def index
8
- @reports = ReportsFinder.all
7
+ @reports = ReportsFinder.all.map do |report_klass|
8
+ report_klass.new(start_at, end_at)
9
+ end
9
10
  end
10
11
 
11
12
  private
12
13
 
13
- def basic_authenticate
14
- authenticate_or_request_with_http_basic do |name, password|
15
- name == StatBoard.username && password == StatBoard.password
14
+ [:date_steps, :resources_by_date].each do |method|
15
+ helper_method method
16
+ delegate method, :to => :graph_helper
17
+ end
18
+
19
+ def graph_helper
20
+ @graph_helper ||= GraphHelper.new(start_at, end_at)
21
+ end
22
+
23
+ def start_at
24
+ @start_at ||= begin
25
+ Date.parse(params[:stats][:start_at])
26
+ rescue
27
+ first_day_ever
16
28
  end
17
29
  end
30
+ helper_method :start_at
31
+
32
+ def end_at
33
+ @end_at ||= Date.parse(params[:stats][:end_at])
34
+ rescue
35
+ Date.today
36
+ end
37
+ helper_method :end_at
38
+
39
+ def first_day_ever
40
+ StatBoard.models.map do |m|
41
+ klass = m.to_s.constantize
42
+ klass.order("created_at ASC").first.try(:created_at) || Time.now
43
+ end.sort.first
44
+ end
45
+ helper_method :first_day_ever
18
46
  end
19
47
  end
@@ -2,7 +2,7 @@
2
2
  <table class="table table-striped">
3
3
  <thead>
4
4
  <tr>
5
- <th colspan="2"><%= report.name(first_day_ever) %></th>
5
+ <th colspan="2"><%= report.name %></th>
6
6
  </tr>
7
7
  </thead>
8
8
 
@@ -3,7 +3,7 @@
3
3
  <%= javascript_include_tag "stat_board/highcharts" %>
4
4
  <script>
5
5
  var pointInterval = <%= date_steps.days * 1000 %>;
6
- var pointStart = <%= first_day_ever.to_i * 1000 %>;
6
+ var pointStart = <%= start_at.to_time.to_i * 1000 %>;
7
7
 
8
8
  Highcharts.chart('container', {
9
9
  title: { text: '' },
@@ -3,6 +3,16 @@
3
3
  <%= render "graph" %>
4
4
  <% end %>
5
5
 
6
+ <div class="statboard-filter">
7
+ <%= form_for :stats, method: :get do |f| %>
8
+ <%= f.date_field :start_at, value: start_at %>
9
+ <%= f.date_field :end_at, value: end_at %>
10
+
11
+ <%= f.submit "Filter", class: "btn btn-primary" %>
12
+ <%= link_to "Clear", {}, class: "btn" %>
13
+ <% end %>
14
+ </div>
15
+
6
16
  <div class="row">
7
17
  <%= render :partial => "chart", :collection => @reports, :as => :report %>
8
18
  </div>
@@ -1,13 +1,10 @@
1
1
  module StatBoard
2
2
  class GraphHelper
3
+ attr_reader :start_at, :end_at
3
4
 
4
- # number of days per interval on the graph's x axis
5
- def date_steps
6
- @date_steps ||= date_range.count / [date_range.count, 50].min
7
- end
8
-
9
- def first_day_ever
10
- @first_day_ever ||= first_day_of_each_model.sort.first
5
+ def initialize(sa, ea)
6
+ @start_at = sa.to_date
7
+ @end_at = ea.to_date
11
8
  end
12
9
 
13
10
  # a string of the array of the count of (klass) objects
@@ -21,15 +18,16 @@ module StatBoard
21
18
  end.to_s
22
19
  end
23
20
 
21
+ # number of days per interval on the graph's x axis
22
+ def date_steps
23
+ @date_steps ||= date_range.count / [date_range.count, 50].min
24
+ end
25
+
24
26
  private
25
27
 
26
28
  # range of dates shown on the graph (array of days)
27
29
  def date_range
28
- @date_range ||= first_day_ever.to_date..Date.today
29
- end
30
-
31
- def first_day_of_each_model
32
- StatBoard.models.map { |m| first_day_of(m) }
30
+ @date_range ||= start_at..end_at
33
31
  end
34
32
 
35
33
  # returns the earliest `created_at` of a given class
@@ -1,12 +1,12 @@
1
1
  module StatBoard
2
2
  module Reports
3
3
  class MonthlyReport < Report
4
- def name(original_date = nil)
4
+ def name
5
5
  "Last 30 days"
6
6
  end
7
7
 
8
8
  def scope(model)
9
- super.where(["created_at > ?", 30.days.ago])
9
+ super.where(["created_at > ? AND created_at < ?", end_date - 30.days, end_date + 1.day])
10
10
  end
11
11
  end
12
12
  end
@@ -1,12 +1,12 @@
1
1
  module StatBoard
2
2
  module Reports
3
3
  class OverallReport < Report
4
- def name(original_date = nil)
5
- if original_date
6
- "Overall (since #{original_date.strftime("%m-%d-%Y")})"
7
- else
8
- "Overall"
9
- end
4
+ def name
5
+ "Overall (#{start_date.strftime("%m-%d-%Y")} - #{end_date.strftime("%m-%d-%Y")})"
6
+ end
7
+
8
+ def scope(model)
9
+ super.where(["created_at > ? AND created_at < ?", start_date, end_date + 1.day])
10
10
  end
11
11
  end
12
12
  end
@@ -1,7 +1,14 @@
1
1
  module StatBoard
2
2
  module Reports
3
3
  class Report
4
- def name(original_date = nil)
4
+ attr_reader :start_date, :end_date
5
+
6
+ def initialize(start_date, end_date)
7
+ @start_date = start_date
8
+ @end_date = end_date
9
+ end
10
+
11
+ def name
5
12
  # define in subclass
6
13
  end
7
14
 
@@ -1,12 +1,12 @@
1
1
  module StatBoard
2
2
  module Reports
3
3
  class WeeklyReport < Report
4
- def name(original_date = nil)
4
+ def name
5
5
  "Last 7 days"
6
6
  end
7
7
 
8
8
  def scope(model)
9
- super.where(["created_at > ?", 1.week.ago])
9
+ super.where(["created_at > ? AND created_at < ?", end_date - 1.week, end_date + 1.day])
10
10
  end
11
11
  end
12
12
  end
@@ -1,14 +1,14 @@
1
1
  module StatBoard
2
2
  class ReportsFinder < Struct.new(:directory)
3
- def reports
3
+ def report_klasses
4
4
  Dir[File.join(directory, "/*_report.rb")].map do |report|
5
- "StatBoard::Reports::#{File.basename(report, ".rb").camelcase}".constantize.new
5
+ "StatBoard::Reports::#{File.basename(report, ".rb").camelcase}".constantize
6
6
  end
7
7
  end
8
8
 
9
9
  def self.all
10
- self.new(File.join(StatBoard::Engine.root, "lib/stat_board/reports")).reports +
11
- self.new(File.join(Rails.root, "lib/stat_board/reports")).reports
10
+ self.new(File.join(StatBoard::Engine.root, "lib/stat_board/reports")).report_klasses +
11
+ self.new(File.join(Rails.root, "lib/stat_board/reports")).report_klasses
12
12
  end
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module StatBoard
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
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: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Eisinger