Class: AhoyCaptain::Stats::VisitDurationQuery

Inherits:
BaseQuery show all
Defined in:
app/queries/ahoy_captain/stats/visit_duration_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
# File 'app/queries/ahoy_captain/stats/visit_duration_query.rb', line 4

def build
  events = event_query
             .reselect("max(#{AhoyCaptain.event.table_name}.time) - min(#{AhoyCaptain.event.table_name}.time) as duration, #{AhoyCaptain.event.table_name}.visit_id")
             .group("#{AhoyCaptain.event.table_name}.visit_id")

  ::Ahoy::Visit
    .select("duration::duration as duration, started_at")
    .from(events, :views_per_visit_table)
    .joins("inner join #{AhoyCaptain.visit.table_name} on #{AhoyCaptain.visit.table_name}.id = views_per_visit_table.visit_id")
end