Class: Analytic::Dashboard
- Inherits:
-
Object
- Object
- Analytic::Dashboard
- Defined in:
- app/models/analytic/dashboard.rb
Constant Summary collapse
- PAGES_LIMIT =
8
Instance Attribute Summary collapse
- #period ⇒ String readonly
Instance Method Summary collapse
- #current ⇒ Period
- #duration ⇒ Interval
-
#initialize(period: nil) ⇒ Dashboard
constructor
A new instance of Dashboard.
- #name ⇒ String
- #prior ⇒ Period
- #range ⇒ Range<Time>
- #range? ⇒ Boolean
- #sessions ⇒ Stat
- #sessions_chart ⇒ Chart
- #views ⇒ Stat
- #views_chart ⇒ Chart
- #visitors ⇒ Stat
- #visitors_chart ⇒ Chart
Constructor Details
#initialize(period: nil) ⇒ Dashboard
Returns a new instance of Dashboard.
11 12 13 |
# File 'app/models/analytic/dashboard.rb', line 11 def initialize(period: nil) @period = period end |
Instance Attribute Details
#period ⇒ String (readonly)
8 9 10 |
# File 'app/models/analytic/dashboard.rb', line 8 def period @period end |
Instance Method Details
#current ⇒ Period
67 68 69 |
# File 'app/models/analytic/dashboard.rb', line 67 def current @current ||= Period.new(range:) end |
#duration ⇒ Interval
90 91 92 93 94 95 96 97 98 |
# File 'app/models/analytic/dashboard.rb', line 90 def duration @duration ||= case @period when '24h' then 24.hours when '7d' then 7.days when '4w' then 4.weeks when '12m' then 12.months end end |
#name ⇒ String
58 59 60 61 62 63 64 |
# File 'app/models/analytic/dashboard.rb', line 58 def name if @period "#{@period.capitalize} | Dashboard" else 'Dashboard' end end |
#prior ⇒ Period
72 73 74 75 76 77 |
# File 'app/models/analytic/dashboard.rb', line 72 def prior return unless range? return @prior if defined?(@prior) @prior ||= Period.new(range: ((range.min - duration)..(range.max - duration))) end |
#range ⇒ Range<Time>
85 86 87 |
# File 'app/models/analytic/dashboard.rb', line 85 def range (now - duration)..now if range? end |
#range? ⇒ Boolean
80 81 82 |
# File 'app/models/analytic/dashboard.rb', line 80 def range? @period.present? end |
#sessions ⇒ Stat
34 35 36 37 38 39 40 |
# File 'app/models/analytic/dashboard.rb', line 34 def sessions Stat.new( current: current.distinct_sessions_count, prior: prior&.distinct_sessions_count, name: 'Sessions' ) end |
#sessions_chart ⇒ Chart
53 54 55 |
# File 'app/models/analytic/dashboard.rb', line 53 def sessions_chart Chart.new(scope: Analytic::Event.by_day.distinct_sessions_count) end |
#views ⇒ Stat
16 17 18 19 20 21 22 |
# File 'app/models/analytic/dashboard.rb', line 16 def views Stat.new( current: current.count, prior: prior&.count, name: 'Views' ) end |
#views_chart ⇒ Chart
43 44 45 |
# File 'app/models/analytic/dashboard.rb', line 43 def views_chart Chart.new(scope: Analytic::Event.by_day.count) end |