Class: Sentiero::Web::Views::VitalsView

Inherits:
AnalyzerView show all
Defined in:
lib/sentiero/web/views/vitals_view.rb

Constant Summary collapse

RATING_COLORS =
{"good" => "#16a34a", "needs-improvement" => "#d97706", "poor" => "#dc2626"}.freeze

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

Attributes inherited from AnalyzerView

#pages, #since, #until_str, #was_truncated

Attributes inherited from BaseView

#base_path, #csrf_token

Instance Method Summary collapse

Methods inherited from AnalyzerView

#initialize, #page_report_href

Methods inherited from BaseView

#built_asset, compiled_template, #escape_js, #h, #initialize, #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

This class inherits a constructor from Sentiero::Web::Views::AnalyzerView

Instance Method Details

#dominant_rating(ratings) ⇒ Object



15
# File 'lib/sentiero/web/views/vitals_view.rb', line 15

def dominant_rating(ratings) = ratings.max_by { |rating, count| [count, rating] }&.first

#page_rating_mix(page) ⇒ Object



28
29
30
31
32
# File 'lib/sentiero/web/views/vitals_view.rb', line 28

def page_rating_mix(page)
  rating_colors.keys.to_h do |rating|
    [rating, page[:metrics].sum { |_metric, m| m[:ratings].fetch(rating, 0) }]
  end
end

#rating_class(rating) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/sentiero/web/views/vitals_view.rb', line 17

def rating_class(rating)
  case rating
  when "good" then "badge-success"
  when "needs-improvement" then "badge-warning"
  when "poor" then "badge-danger"
  else "badge-neutral"
  end
end

#rating_colorsObject



26
# File 'lib/sentiero/web/views/vitals_view.rb', line 26

def rating_colors = RATING_COLORS

#slowest(page) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/sentiero/web/views/vitals_view.rb', line 34

def slowest(page)
  %w[LCP INP CLS].each do |metric|
    worst = page[:metrics].dig(metric, :worst)
    return worst if worst
  end
  page[:metrics].each_value { |m| return m[:worst] if m[:worst] }
  nil
end

#sorted_pagesObject



13
# File 'lib/sentiero/web/views/vitals_view.rb', line 13

def sorted_pages = pages.sort_by { |url, page| [-page[:sample_count], url] }

#templateObject



11
# File 'lib/sentiero/web/views/vitals_view.rb', line 11

def template = "analytics_vitals.html.erb"