Module: Solidstats::PerformanceHelper

Defined in:
app/helpers/solidstats/performance_helper.rb

Overview

LoadLens Performance Helper Provides view helpers for displaying performance metrics

Instance Method Summary collapse

Instance Method Details

#format_percentage(value) ⇒ Object



24
25
26
27
# File 'app/helpers/solidstats/performance_helper.rb', line 24

def format_percentage(value)
  return "0%" if value.nil? || value == 0
  "#{value.round(1)}%"
end

#format_response_time(time_ms) ⇒ Object



19
20
21
22
# File 'app/helpers/solidstats/performance_helper.rb', line 19

def format_response_time(time_ms)
  return "0ms" if time_ms.nil? || time_ms == 0
  "#{time_ms.round(1)}ms"
end

#load_lens_metric_badge(value, threshold_warning, threshold_error, unit = "ms") ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/helpers/solidstats/performance_helper.rb', line 73

def load_lens_metric_badge(value, threshold_warning, threshold_error, unit = "ms")
  formatted_value = "#{value}#{unit}"

  badge_class = if value > threshold_error
                 "badge-error"
  elsif value > threshold_warning
                 "badge-warning"
  else
                 "badge-success"
  end

  (:span, formatted_value, class: "badge #{badge_class}")
end

#load_lens_status_class(avg_response_time, error_rate) ⇒ Object



7
8
9
10
11
# File 'app/helpers/solidstats/performance_helper.rb', line 7

def load_lens_status_class(avg_response_time, error_rate)
  return "text-error" if error_rate > 10
  return "text-warning" if avg_response_time > 1000
  "text-success"
end

#load_lens_status_icon(avg_response_time, error_rate) ⇒ Object



13
14
15
16
17
# File 'app/helpers/solidstats/performance_helper.rb', line 13

def load_lens_status_icon(avg_response_time, error_rate)
  return "alert-circle" if error_rate > 10
  return "alert-triangle" if avg_response_time > 1000
  "check-circle"
end

#performance_trend_indicator(current, previous) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/solidstats/performance_helper.rb', line 59

def performance_trend_indicator(current, previous)
  return "" if current.nil? || previous.nil? || previous == 0

  percentage_change = ((current - previous) / previous.to_f) * 100

  if percentage_change > 5
    (:span, "", class: "text-error", title: "#{percentage_change.round(1)}% slower")
  elsif percentage_change < -5
    (:span, "", class: "text-success", title: "#{percentage_change.abs.round(1)}% faster")
  else
    (:span, "", class: "text-info", title: "Similar performance")
  end
end

#request_status_badge_class(status) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/solidstats/performance_helper.rb', line 29

def request_status_badge_class(status)
  case status.to_i
  when 200..299
    "badge-success"
  when 300..399
    "badge-info"
  when 400..499
    "badge-warning"
  when 500..599
    "badge-error"
  else
    "badge-neutral"
  end
end

#response_time_color_class(time_ms) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/solidstats/performance_helper.rb', line 44

def response_time_color_class(time_ms)
  return "text-base-content" if time_ms.nil? || time_ms == 0

  case time_ms.to_f
  when 0..100
    "text-success"
  when 100..500
    "text-info"
  when 500..1000
    "text-warning"
  else
    "text-error"
  end
end