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 +4 -4
- data/README.markdown +1 -1
- data/app/assets/stylesheets/stat_board/bootstrap.css +11 -0
- data/app/controllers/stat_board/application_controller.rb +5 -7
- data/app/controllers/stat_board/stats_controller.rb +33 -5
- data/app/views/stat_board/stats/_chart.html.erb +1 -1
- data/app/views/stat_board/stats/_graph.html.erb +1 -1
- data/app/views/stat_board/stats/index.html.erb +10 -0
- data/lib/stat_board/graph_helper.rb +10 -12
- data/lib/stat_board/reports/monthly_report.rb +2 -2
- data/lib/stat_board/reports/overall_report.rb +6 -6
- data/lib/stat_board/reports/report.rb +8 -1
- data/lib/stat_board/reports/weekly_report.rb +2 -2
- data/lib/stat_board/reports_finder.rb +4 -4
- data/lib/stat_board/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56119a7dfb242c2870891827f9c4f02cef7132a49e0d12ed277f0de62dcf3761
|
4
|
+
data.tar.gz: 40c2c2d54dfac7611707ddbaf5102382703f0c3a5ab934388496fbf14ebae2ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a631aca73ed4e7bcd7dcc870d856a1c392e0af94555444678e639c7dd90e960e52480e8554872cf96622422344d02ebc397f36456b22adc37c13f21d978d160b
|
7
|
+
data.tar.gz: 9be14830e8df286e04dedb8f60cbe9320da7cd288e4b63c1344de0ab59661c8508b90589ed49c8283e80554a59e611c3f76466ae2d1ce8c32412c05da047f0eb
|
data/README.markdown
CHANGED
@@ -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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
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
|
@@ -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 = <%=
|
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
|
-
|
5
|
-
|
6
|
-
@
|
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 ||=
|
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
|
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.
|
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
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
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
|
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.
|
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
|
3
|
+
def report_klasses
|
4
4
|
Dir[File.join(directory, "/*_report.rb")].map do |report|
|
5
|
-
"StatBoard::Reports::#{File.basename(report, ".rb").camelcase}".constantize
|
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")).
|
11
|
-
self.new(File.join(Rails.root, "lib/stat_board/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
|
data/lib/stat_board/version.rb
CHANGED