Class: Sentiero::Web::Views::EngagementView

Inherits:
BaseView
  • Object
show all
Defined in:
lib/sentiero/web/views/engagement_view.rb

Constant Summary

Constants inherited from BaseView

BaseView::TEMPLATES_DIR, BaseView::TEMPLATE_CACHE

Constants included from Escaping

Escaping::HTML_UNSAFE_IN_SCRIPT, Escaping::HTML_UNSAFE_IN_SCRIPT_PATTERN

Instance Attribute Summary collapse

Attributes inherited from BaseView

#base_path, #csrf_token

Instance Method Summary collapse

Methods inherited from BaseView

#built_asset, compiled_template, #escape_js, #h, #range_pairs, #render, #render_layout, #render_partial, #render_session_row

Methods included from Formatting

#format_duration, #format_vital, #parse_browser, #parse_device

Methods included from Escaping

#escape_html, #escape_js_string, #escape_json

Constructor Details

#initialize(sessions:, distribution:, scanned:, was_truncated:, sort:, since:, until_str:) ⇒ EngagementView

Returns a new instance of EngagementView.



10
11
12
13
14
15
16
17
18
19
# File 'lib/sentiero/web/views/engagement_view.rb', line 10

def initialize(sessions:, distribution:, scanned:, was_truncated:, sort:, since:, until_str:)
  super()
  @sessions = sessions
  @distribution = distribution
  @scanned = scanned
  @was_truncated = was_truncated
  @sort = sort
  @since = since
  @until_str = until_str
end

Instance Attribute Details

#distributionObject (readonly)

Returns the value of attribute distribution.



21
22
23
# File 'lib/sentiero/web/views/engagement_view.rb', line 21

def distribution
  @distribution
end

#scannedObject (readonly)

Returns the value of attribute scanned.



21
22
23
# File 'lib/sentiero/web/views/engagement_view.rb', line 21

def scanned
  @scanned
end

#sessionsObject (readonly)

Returns the value of attribute sessions.



21
22
23
# File 'lib/sentiero/web/views/engagement_view.rb', line 21

def sessions
  @sessions
end

#sinceObject (readonly)

Returns the value of attribute since.



21
22
23
# File 'lib/sentiero/web/views/engagement_view.rb', line 21

def since
  @since
end

#sortObject (readonly)

Returns the value of attribute sort.



21
22
23
# File 'lib/sentiero/web/views/engagement_view.rb', line 21

def sort
  @sort
end

#until_strObject (readonly)

Returns the value of attribute until_str.



21
22
23
# File 'lib/sentiero/web/views/engagement_view.rb', line 21

def until_str
  @until_str
end

#was_truncatedObject (readonly)

Returns the value of attribute was_truncated.



21
22
23
# File 'lib/sentiero/web/views/engagement_view.rb', line 21

def was_truncated
  @was_truncated
end

Instance Method Details

#axis_yObject



36
# File 'lib/sentiero/web/views/engagement_view.rb', line 36

def axis_y = svg_height - 24

#badge_class(score) ⇒ Object



45
46
47
48
49
50
# File 'lib/sentiero/web/views/engagement_view.rb', line 45

def badge_class(score)
  if score >= 60 then "badge badge-danger"
  elsif score >= 30 then "badge badge-warning"
  else "text-gray-400"
  end
end

#bar_gapObject



35
# File 'lib/sentiero/web/views/engagement_view.rb', line 35

def bar_gap = 12

#bar_h(count) ⇒ Object



41
# File 'lib/sentiero/web/views/engagement_view.rb', line 41

def bar_h(count) = (count.to_f / max_count * (axis_y - chart_top)).round(1)

#bar_widthObject



39
# File 'lib/sentiero/web/views/engagement_view.rb', line 39

def bar_width = (svg_width - bar_gap * (bin_count + 1)) / bin_count

#bar_x(i) ⇒ Object



42
# File 'lib/sentiero/web/views/engagement_view.rb', line 42

def bar_x(i) = bar_gap + i * (bar_width + bar_gap)

#bar_y(count) ⇒ Object



43
# File 'lib/sentiero/web/views/engagement_view.rb', line 43

def bar_y(count) = (axis_y - bar_h(count)).round(1)

#bin_countObject



38
# File 'lib/sentiero/web/views/engagement_view.rb', line 38

def bin_count = distribution.size

#chart_topObject



37
# File 'lib/sentiero/web/views/engagement_view.rb', line 37

def chart_top = 12

#chips(signals) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/sentiero/web/views/engagement_view.rb', line 52

def chips(signals)
  chips = []
  chips << "rage&times;#{signals[:rage_clicks]}" if signals[:rage_clicks].to_i > 0
  chips << "dead&times;#{signals[:dead_clicks]}" if signals[:dead_clicks].to_i > 0
  chips << "churn&times;#{signals[:nav_churn]}" if signals[:nav_churn].to_i > 0
  chips << "idle #{(signals[:idle_ratio].to_f * 100).round}%" if signals[:idle_ratio].to_f > 0
  chips << "thrash&times;#{signals[:thrashing_scroll]}" if signals[:thrashing_scroll].to_i > 0
  chips << "bounce" if signals[:quick_bounce]
  chips << "refill&times;#{signals[:form_refills]}" if signals[:form_refills].to_i > 0
  chips << "err-abandon" if signals[:error_abandonment]
  chips
end

#max_countObject



40
# File 'lib/sentiero/web/views/engagement_view.rb', line 40

def max_count = [distribution.values.max, 1].max


29
30
31
# File 'lib/sentiero/web/views/engagement_view.rb', line 29

def sort_link(column)
  "#{base_path}/analytics/engagement?" + Rack::Utils.build_query(range_pairs.merge("sort" => column))
end

#sorted_sessionsObject



25
26
27
# File 'lib/sentiero/web/views/engagement_view.rb', line 25

def sorted_sessions
  (sort == "duration") ? sessions.sort_by { |row| [-row[:duration_ms], row[:session_id]] } : sessions
end

#svg_heightObject



34
# File 'lib/sentiero/web/views/engagement_view.rb', line 34

def svg_height = 140

#svg_widthObject



33
# File 'lib/sentiero/web/views/engagement_view.rb', line 33

def svg_width = 360

#templateObject



23
# File 'lib/sentiero/web/views/engagement_view.rb', line 23

def template = "analytics_engagement.html.erb"