Module: Flightdeck::MetricsHelper

Defined in:
app/helpers/flightdeck/metrics_helper.rb

Constant Summary collapse

TREND_GLYPHS =
{ up: "", down: "", flat: "" }.freeze

Instance Method Summary collapse

Instance Method Details

#fd_chart_poll_msObject



8
# File 'app/helpers/flightdeck/metrics_helper.rb', line 8

def fd_chart_poll_ms = (Flightdeck.config.chart_poll_interval.to_f * 1000).round

#fd_clock_nowObject



24
# File 'app/helpers/flightdeck/metrics_helper.rb', line 24

def fd_clock_now = "#{Time.current.in_time_zone(fd_display_zone).strftime("%H:%M:%S")} #{fd_zone_label}"

#fd_delta_class(tile) ⇒ Object

Colour follows whether the movement is good news, not which way the arrow points: more failures is an "up" arrow but bad news.



37
38
39
40
41
# File 'app/helpers/flightdeck/metrics_helper.rb', line 37

def fd_delta_class(tile)
  return "flat" if tile.trend.to_sym == :flat

  tile.good ? "up" : "down"
end

#fd_depth_share(depth, max) ⇒ Object



43
44
45
46
47
# File 'app/helpers/flightdeck/metrics_helper.rb', line 43

def fd_depth_share(depth, max)
  return 0 if max.to_i.zero?

  [ (depth.to_f / max * 100).round, 100 ].min
end

#fd_display_zoneObject

--- topbar clock ---------------------------------------------------------

Rendered server-side so the clock is right before JavaScript runs, and driven by an offset so it keeps showing the configured display timezone rather than the viewer's.



20
21
22
# File 'app/helpers/flightdeck/metrics_helper.rb', line 20

def fd_display_zone
  ActiveSupport::TimeZone[Flightdeck.config.display_timezone] || ActiveSupport::TimeZone["UTC"]
end

#fd_poll_msObject



7
# File 'app/helpers/flightdeck/metrics_helper.rb', line 7

def fd_poll_ms = (Flightdeck.config.poll_interval.to_f * 1000).round

#fd_poll_secondsObject



10
# File 'app/helpers/flightdeck/metrics_helper.rb', line 10

def fd_poll_seconds = Flightdeck.config.poll_interval.to_i

#fd_trend_glyph(trend) ⇒ Object



12
# File 'app/helpers/flightdeck/metrics_helper.rb', line 12

def fd_trend_glyph(trend) = TREND_GLYPHS.fetch(trend.to_sym, TREND_GLYPHS[:flat])

#fd_zone_labelObject



26
27
28
29
# File 'app/helpers/flightdeck/metrics_helper.rb', line 26

def fd_zone_label
  zone = fd_display_zone
  zone.name == "UTC" ? "UTC" : Time.current.in_time_zone(zone).strftime("%Z")
end

#fd_zone_offset_secondsObject



31
32
33
# File 'app/helpers/flightdeck/metrics_helper.rb', line 31

def fd_zone_offset_seconds
  fd_display_zone.now.utc_offset
end