Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query naming #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Stats
class ViewsPerVisitsController < BaseController
# @todo: make me a window func
def index
@stats = AhoyCaptain::Stats::ViewsPerVisitQuery.call(params).group_by_period(selected_interval, 'views_per_visit_table.started_at').average(:views_per_visit)
@stats = AhoyCaptain::Stats::CountViewsPerVisitQuery.call(params).group_by_period(selected_interval, 'views_per_visit_table.started_at').average(:views_per_visit)
if range[1]
(range[0].to_date..range[1].to_date).to_a.each do |date|
unless @stats.key?(date.to_date)
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/ahoy_captain/dashboard_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def total_pageviews
def views_per_visit
cached(:views_per_visit) do
begin
result = Stats::AverageViewsPerVisitQuery.call(params).count(:id)
result = Stats::ViewsPerVisitQuery.call(params).count(:id)
count = (result.values.sum.to_f / result.size).round(2)
if count.nan?
return "0"
Expand Down
13 changes: 0 additions & 13 deletions app/queries/ahoy_captain/stats/average_views_per_visit_query.rb

This file was deleted.

17 changes: 17 additions & 0 deletions app/queries/ahoy_captain/stats/count_views_per_visit_query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module AhoyCaptain
module Stats
class CountViewsPerVisitQuery < ApplicationQuery
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
end
end
end
14 changes: 5 additions & 9 deletions app/queries/ahoy_captain/stats/views_per_visit_query.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
module AhoyCaptain
module Stats
# pls fix
class ViewsPerVisitQuery < ApplicationQuery
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)
event_query
.joins(:visit)
.where(name: "$view")
.group("#{AhoyCaptain.visit.table_name}.id")
end
end
end
Expand Down