You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

55 lines
1.9 KiB

module Admin::AnalyticsHelper
# Colours a bar by what the answer does to the player's score, so a stage
# reads at a glance: green = they made the good call, red = they didn't.
def answer_tone(node)
case node.template
when "good_answer" then "positive"
when "bad_answer" then "negative"
when "chance" then "neutral"
end
end
def band_tone(band)
{ best: "positive", balanced: "neutral", worst: "negative" }[band.to_sym]
end
# Labels a row of the Countries breakdown. Everything outside the headcount
# list is collapsed into one bucket by GameAnalytics#by_country, and that
# bucket has no entry under `countries:` -- so name it here rather than
# letting the default fall through and print "OTHER".
def country_breakdown_label(key)
return "Other" if key.to_s == GameAnalytics::OTHER_COUNTRY_KEY
t("countries.#{key}", default: key.to_s.upcase)
end
# Labels a row of the Languages breakdown. `players.locale` stores the raw
# locale code, which is not much use at a glance -- so name it. Uses
# `language_names` (English exonyms: "Danish", "Chinese") rather than
# `languages` (native names: "Dansk", "\u4e2d\u6587"), which is what the player-facing
# menu shows; this dashboard reads better in one language.
def language_breakdown_label(key)
t("language_names.#{key}", default: key.to_s)
end
# Labels a row of the Devices breakdown. The stored values are already the
# words we want, so this is just capitalisation -- it exists so the panel
# matches the other two breakdowns rather than printing a raw column value.
def device_breakdown_label(key)
key.to_s.capitalize
end
def format_duration(seconds)
return "" if seconds.blank? || seconds.to_i.zero?
seconds = seconds.to_i
minutes, seconds = seconds.divmod(60)
minutes.zero? ? "#{seconds}s" : "#{minutes}m #{seconds}s"
end
end