Class: Lookout::PropertiesController
Instance Method Summary
collapse
#period
Methods included from Rangeable
#period
#compare_mode?, #comparison_mode, included
Instance Method Details
#index ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'app/controllers/lookout/properties_controller.rb', line 7
def index
if @options.any?
url_key = @options.find { |key, value| value == 'url' }&.first
default_key = url_key || @options.keys.first
redirect_to property_path(id: default_key, **request.query_parameters), status: :see_other
end
end
|
#show ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/controllers/lookout/properties_controller.rb', line 18
def show
value = Base64.urlsafe_decode64(params[:id])
= Lookout::DatabaseAdapter.("properties", value)
coalesce_expr = "COALESCE(#{json_extract}, '(none)')"
percentage_calc = if Lookout::DatabaseAdapter.postgresql?
"(COUNT(DISTINCT visit_id)/COUNT(*)::numeric) * 100"
else
"(CAST(COUNT(DISTINCT visit_id) AS REAL) / COUNT(*)) * 100"
end
@properties = event_query
.select(
"#{coalesce_expr} AS label",
"COUNT(*) AS events_count",
"COUNT(DISTINCT visit_id) AS unique_visitors_count",
"#{percentage_calc} as percentage"
)
.group(coalesce_expr)
.order(Arel.sql "COUNT(*) desc")
end
|