-
Notifications
You must be signed in to change notification settings - Fork 200
Add locked_by and quit_by columns to live_results #13297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ed0e172
53955ca
a554da9
40f9fb9
22c1688
1483bfb
316ffc4
29870df
af4c8b4
6570c7c
1bd4751
52ccd17
43bacc7
6b3452f
2467eac
e53e62f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,10 @@ def format | |
| has_many :wcif_extensions, as: :extendable, dependent: :delete_all | ||
|
|
||
| has_many :live_results, -> { order(:global_pos) } | ||
| has_many :live_competitors, through: :live_results, source: :registration | ||
| has_many :live_results_without_quitters, | ||
| -> { without_quitters.order(:global_pos) }, | ||
| class_name: "LiveResult" | ||
|
Comment on lines
+47
to
+49
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, it feels like this shouldn't be a separate relation. Why does
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because I use it in a scope one line down in the |
||
| has_many :live_competitors, through: :live_results_without_quitters, source: :registration | ||
| has_many :results | ||
| has_many :scrambles | ||
|
|
||
|
|
@@ -182,6 +185,13 @@ def advancing_registrations | |
| end | ||
| end | ||
|
|
||
| def open_and_lock_previous(current_user) | ||
| init_round | ||
| return 0 if number == 1 || linked_round.present? | ||
|
Comment on lines
+189
to
+190
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you ignoring the return value of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return value is how many results where locked and it's 0 if there is no previous round to lock
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you returning early in case of a linked round? The linked round's individual rounds would all need to be locked, and returning early feels a bit premature...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is about locking the previous round as the title suggests. Linked Rounds do not have previous rounds |
||
|
|
||
| previous_round.lock_results(current_user) | ||
| end | ||
|
|
||
| def init_round | ||
| empty_results = advancing_registrations.map do |r| | ||
| { registration_id: r.id, round_id: id, average: 0, best: 0, last_attempt_entered_at: current_time_from_proper_timezone } | ||
|
|
@@ -193,18 +203,18 @@ def total_competitors | |
| live_competitors.count | ||
| end | ||
|
|
||
| def recompute_live_columns | ||
| def recompute_live_columns(skip_advancing: false) | ||
| recompute_local_pos | ||
| recompute_global_pos | ||
| recompute_advancing | ||
| recompute_advancing unless skip_advancing | ||
| end | ||
|
|
||
| def recompute_advancing | ||
| has_linked_round = linked_round.present? | ||
| advancement_determining_results = has_linked_round ? linked_round.live_results : live_results | ||
|
|
||
| # Only ranked results can be considered for advancing. | ||
| round_results = advancement_determining_results.where.not(global_pos: nil) | ||
| # Only ranked results that are not locked can be considered for advancing. | ||
| round_results = advancement_determining_results.where.not(global_pos: nil).where(locked_by_id: nil) | ||
| round_results.update_all(advancing: false, advancing_questionable: false) | ||
|
|
||
| missing_attempts = total_competitors - round_results.count | ||
|
|
@@ -353,6 +363,25 @@ def self.wcif_to_round_attributes(event, wcif, round_number, total_rounds) | |
| } | ||
| end | ||
|
|
||
| def lock_results(locking_user) | ||
| results_to_lock = linked_round.present? ? linked_round.live_results : live_results | ||
|
|
||
| results_to_lock.update_all(locked_by_id: locking_user.id) | ||
| end | ||
|
|
||
| def quit_from_round!(registration_id, quitting_user) | ||
| result = live_results.find_by!(registration_id: registration_id) | ||
|
|
||
| is_quit = result.mark_as_quit(quitting_user) | ||
|
|
||
| return is_quit ? 1 : 0 if number == 1 || linked_round.present? | ||
|
|
||
| # We need to also quit the result from the previous round so advancement can be correctly shown | ||
| previous_round_results = previous_round.linked_round.present? ? previous_round.linked_round.live_results : previous_round.live_results | ||
|
|
||
| previous_round_results.where(registration_id: registration_id).map { it.mark_as_quit(quitting_user) }.count { it == true } | ||
| end | ||
|
|
||
| def wcif_id | ||
| "#{self.event_id}-r#{self.number}" | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddLockedByAndQuitBy < ActiveRecord::Migration[8.1] | ||
| def change | ||
| change_table :live_results, bulk: true do |t| | ||
| t.references :quit_by, type: :integer, foreign_key: { to_table: :users } | ||
| t.references :locked_by, type: :integer, foreign_key: { to_table: :users } | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case do you need the second
or(where.not(best: 0))part?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sidenote:
.or(not_empty)should workThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do still want to show quitters for previous rounds.
Currently when someone is quit from round 2 who advanced from round 1 I mark them as quit in round 2 and 1, but I still want to show them in round 1. There is a case to be made to only mark them as quit in round 1 as those results will already be locked so only flipping the advancing will be necessary?