Class: AhoyCaptain::Stats::ViewsPerVisitQuery

Inherits:
BaseQuery show all
Defined in:
app/queries/ahoy_captain/stats/views_per_visit_query.rb

Instance Attribute Summary

Attributes inherited from ApplicationQuery

#params

Instance Method Summary collapse

Methods included from LazyComparableQuery

#with_lazy_comparison

Methods included from ComparableQuery

#with_comparison

Methods inherited from ApplicationQuery

call, inherited, #initialize, #inspect

Constructor Details

This class inherits a constructor from AhoyCaptain::ApplicationQuery

Instance Method Details

#buildObject



4
5
6
7
8
9
10
11
12
13
14
# File 'app/queries/ahoy_captain/stats/views_per_visit_query.rb', line 4

def build
  events = event_query
             .joins(:visit)
             .select("#{::AhoyCaptain.visit.table_name}.started_at as started_at, count(#{AhoyCaptain.event.table_name}.name) / count(distinct #{AhoyCaptain.event.table_name}.visit_id) as views_per_visit")
             .where(name: AhoyCaptain.config.event[:view_name])
             .group("#{AhoyCaptain.visit.table_name}.started_at, #{AhoyCaptain.event.table_name}.visit_id")

  ::Ahoy::Visit
               .select("views_per_visit as views_per_visit")
               .from(events, :views_per_visit_table)
end