Skip to content

Commit

Permalink
Restore casual ranking (#716)
Browse files Browse the repository at this point in the history
* Restore casual scores

* Show users with non-zero scores on the ladder of insanity

* Adjust test
  • Loading branch information
pil0u authored Dec 1, 2024
1 parent 86cad0a commit bfabddd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/components/header/nav_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<%= render NavTabComponent.new(link: { name: "patrons", path: patrons_path }) %>
<%= render NavTabComponent.new(link: { name: "squads", path: scores_squads_path }) %>
<%= render NavTabComponent.new(link: { name: "faq", path: faq_path }) %>
<%= render NavTabComponent.new(link: { name: "scores", path: scores_solo_path }) %>
<%= render NavTabComponent.new(link: { name: "stats", path: stats_path }) %>
<%= link_to destroy_user_session_path, class: "hover:text-wagon-red", data: { turbo: false } do %>
<%= inline_svg_tag "icons/power.svg", class: "w-5 h-5 inline-block" %>
Expand Down
4 changes: 2 additions & 2 deletions app/domains/scores/insanity_scores.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def compute
points
.group_by { |p| p[:user_id] }
.reverse_merge(default_points)
.map do |user_id, user_points|
.filter_map do |user_id, user_points|
total_score = user_points.sum { |point| point[:score] }
day_score = user_points.select { |point| point[:day] == Aoc.latest_day }
.sum { |point| point[:score] }

{ user_id:, score: total_score, current_day_score: day_score }
{ user_id:, score: total_score, current_day_score: day_score } if total_score > 0
end
end
end
Expand Down
21 changes: 13 additions & 8 deletions app/views/scores/solo.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<%= render Scores::NavComponent.new %>

<%= render PageTitleComponent.new(title: "Solo scoreboard") %>

<p class="my-4">
You earn between <code class="strong">25</code> and <code class="strong">50</code> points for each <em>challenge</em>
you solve. <%= link_to "More info", faq_path, class: "link-explicit link-internal" %>.
</p>

<div class="my-4">
<p>
If you solve a puzzle in the first 24 hours after its release, you get a score of <code class="strong">50</code>.
</p>
<p>
After 24 hours, the score decreases by <code class="strong">1</code>/hour, down to a minimum of
<code class="strong">25</code>.
</p>
<p>
Even if you solve a puzzle 2 weeks after release, you still get <code class="strong">25</code> points.
</p>
</div>
<table class="block overflow-x-auto whitespace-nowrap w-full">
<thead>
<tr class="border-b border-aoc-gray-darker">
Expand All @@ -22,6 +27,6 @@
</thead>

<tbody>
<%= render Scores::UserRowComponent.with_collection(@participants, user: current_user, extended: true, colorize_hardcore: true) %>
<%= render Scores::UserRowComponent.with_collection(@participants, user: current_user, extended: true) %>
</tbody>
</table>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def omniauth_callbacks(provider)
get "/faq", to: "pages#faq"
get "/stats", to: "pages#stats"
get "/scores/insanity", to: "scores#insanity"
get "/scores/solo", to: "scores#solo"

# Routes for unauthenticated users
unauthenticated do
Expand Down Expand Up @@ -88,7 +89,6 @@ def omniauth_callbacks(provider)
get "/admin", to: "pages#admin"
post "/impersonate", to: "users#impersonate", as: :impersonate

get "/scores/solo", to: "scores#solo"
get "/scores/campuses", to: "scores#campuses"
get "/participation", to: "pages#participation"

Expand Down
4 changes: 2 additions & 2 deletions spec/domains/scores/insanity_scores_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
context "when a user has no points" do
let!(:user_3) { create(:user, id: 3, entered_hardcore: true) }

it "includes them, with 0 points" do
expect(described_class.get).to include(
it "excludes them" do
expect(described_class.get).not_to include(
hash_including(score: 0, user_id: 3)
)
end
Expand Down

0 comments on commit bfabddd

Please sign in to comment.