Class: AhoyCaptain::PropertiesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ahoy_captain/properties_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#period

Methods included from Rangeable

#period

Methods included from CompareMode

#compare_mode?, #comparison_mode, included

Instance Method Details

#indexObject



7
8
# File 'app/controllers/ahoy_captain/properties_controller.rb', line 7

def index
end

#showObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/ahoy_captain/properties_controller.rb', line 10

def show
  value = Base64.urlsafe_decode64(params[:id])

  @properties = event_query
    .select(
      "COALESCE(properties->>'#{value}', '(none)') AS label",
      "COUNT(*) AS events_count",
      "COUNT(DISTINCT visit_id) AS unique_visitors_count",
      "(COUNT(DISTINCT visit_id)/COUNT(*)::numeric) * 100 as percentage"
    )
    .group("COALESCE(properties->>'#{value}', '(none)')")
    .order(Arel.sql "COUNT(*) desc")
end