%= content_for :title, "Leaderboard" %> <%= turbo_frame_tag 'main' do %> <%= turbo_stream.append 'flash', partial: 'layouts/flash' %>
Demo data is on.
DemoActivity invents players on every cache refresh, so the tomato counts
below are fake. Set DemoActivity::ENABLED = false and wipe the players table
before go-live.
This is the payload served by GET /api/v1/leaderboard — the banner reads it,
not the players table directly. The endpoint caches for
<%= distance_of_time_in_words(LeaderboardPayload::TTL) %>, so these are the numbers
consumers are actually being served right now.
Nothing is published at the moment. The cache has expired and no one has called the endpoint since. Below is a preview of what the next call will publish — badges are sampled per refresh, so the ones that go out will be a different pick.
<% end %>No badges in this payload.
<% else %>Score blends total tomatoes against tomatoes per employee, so a big country cannot win on headcount alone. Countries with no headcount on file fall back to their impact score rather than being penalised — those rows are marked.
<% max_score = @leaderboard.map { |row| row[:score].to_i }.max.to_i %>A country's score is a blend of two numbers, so a big country cannot win on headcount alone and a small one cannot win on a single enthusiastic office.
tomatoes ÷ highest tomato count × 100(tomatoes ÷ employees) ÷ highest ratio × 100config/country_headcounts.yml. This is
the “what share of you turned up” axis, so a 60-person country can beat
a 19,000-person one.
impact × <%= LeaderboardScore::IMPACT_WEIGHT %> + efficiency × <%= LeaderboardScore::EFFICIENCY_WEIGHT %>,
rounded to a whole number. Change the split in
LeaderboardScore::IMPACT_WEIGHT — raising efficiency leans further
toward fairness across team sizes.
Right now, <%= country_flag(example[:country_code]) %> <%= leaderboard_country_name(example[:country_code]) %>: <%= number_with_delimiter(example[:tomatoes]) %> <%= "tomato".pluralize(example[:tomatoes]) %> against a best of <%= number_with_delimiter(max_tomatoes.to_i) %> gives an impact of <%= impact.round(1) %>; <% if example[:per_employee] %> <%= example[:per_employee] %> per employee against a best of <%= max_per_emp.round(2) %> gives an efficiency of <%= efficiency.round(1) %>. <% else %> with no headcount on file, efficiency falls back to the impact score (<%= efficiency.round(1) %>). <% end %> Blended, that lands on <%= example[:score] %>.
<% end %>Two details worth knowing: every country we hold a name for is listed even with zero tomatoes, so the banner can always name anyone; and ties are broken alphabetically by country code, not randomly, so the order is stable between refreshes.
<%= JSON.pretty_generate(
leaderboard: @leaderboard,
badges: @badges,
updated_at: @updated_at&.iso8601
) %>