Class: Sentiero::Web::Views::VitalsView
- Inherits:
-
AnalyzerView
- Object
- BaseView
- AnalyzerView
- Sentiero::Web::Views::VitalsView
- 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
Instance Method Summary collapse
- #dominant_rating(ratings) ⇒ Object
- #page_rating_mix(page) ⇒ Object
- #rating_class(rating) ⇒ Object
- #rating_colors ⇒ Object
- #slowest(page) ⇒ Object
- #sorted_pages ⇒ Object
- #template ⇒ Object
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 () = .max_by { |, count| [count, ] }&.first |
#page_rating_mix(page) ⇒ Object
28 29 30 31 32 |
# File 'lib/sentiero/web/views/vitals_view.rb', line 28 def (page) .keys.to_h do || [, page[:metrics].sum { |_metric, m| m[:ratings].fetch(, 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 () case when "good" then "badge-success" when "needs-improvement" then "badge-warning" when "poor" then "badge-danger" else "badge-neutral" end end |
#rating_colors ⇒ Object
26 |
# File 'lib/sentiero/web/views/vitals_view.rb', line 26 def = 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_pages ⇒ Object
13 |
# File 'lib/sentiero/web/views/vitals_view.rb', line 13 def sorted_pages = pages.sort_by { |url, page| [-page[:sample_count], url] } |
#template ⇒ Object
11 |
# File 'lib/sentiero/web/views/vitals_view.rb', line 11 def template = "analytics_vitals.html.erb" |