Skip to content
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

WCA Live Integration Pre Work #2: Add liveResult and liveAttempt models #10685

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

FinnIckler
Copy link
Member

Also confirmed working using my test page.
wca live's result table additionally has

      t.integer :ranking
      t.integer :best, null: false
      t.integer :average, null: false
      t.string :single_record_tag, limit: 255
      t.string :average_record_tag, limit: 255
      t.boolean :advancing, default: false, null: false
      t.boolean :advancing_questionable, default: false, null: false

But I am not sure which one of these we should also use and which one we should just compute on the fly.

@FinnIckler
Copy link
Member Author

FinnIckler commented Feb 5, 2025

I've added the factories and some basic tests. There will be a ton more when validating cutoffs and time limits will be introduced in a future pr

Comment on lines +7 to 8
# params: { results, round_id, user_id, entered_by }
def perform(params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that I neglected to mention this in the other PR, but you can actually do def perform(results, round_id, user_id, entered_by) and Rails will de-serialize the parameters for you

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(that's a feature of ActiveJob specifically, not a general Ruby thing)

event = round.event
format = round.format

r = Result.build({ value1: results[0], value2: results[1] || 0, value3: results[2] || 0, value4: results[3] || 0, value5: results[4] || 0, event_id: event.id, round_type_id: round.round_type_id, format_id: format.id })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using build instead of new here?

Comment on lines +26 to +28
def result_id
id
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alias please


belongs_to :registration

belongs_to :entered_by, class_name: 'User', foreign_key: 'entered_by_id'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Rails is smart enough to infer the foreign_key, as long as it's "name of relation + _id"

DEFAULT_SERIALIZE_OPTIONS = {
only: %w[ranking registration_id round live_attempts round best average single_record_tag average_record_tag advancing advancing_questionable entered_at entered_by_id],
methods: %w[event_id attempts result_id],
include: %w[event live_attempts round],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a heck of a lot of data you're serializing for each and every single scorecard. I won't stand in your way for your PoC experiments, but please think about how to slim this down. Especially for event, just sending along event_id and accessing the static list of WCA events in JS should be enough.

For the round, I'd also argue that a round ID should do, and you keep a lookup somewhere else in your React component.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I only included event here because I thought that would pre-load it from the database (we talked about include vs includes yesterday). event_id is definitely enough

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to figure out why I included round

Comment on lines +8 to +9
t.references :entered_by, type: :integer, null: false, foreign_key: { to_table: :users }
t.datetime :entered_at, null: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it sufficient to keep this information per scorecard?
I'm thinking about FMC and MBLD where you enter results with long gaps in between, and these gaps also make it plausible that individual scores are entered by different people.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also related about the timestamp: I assume this is the time when the scorecard was first inserted, but what if we just change one score later? Where is that being recorded?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking I would just overwrite entered_by and entered_at with the latest person. I think that's how jonatan does it

t.timestamps
end

add_index :live_results, [:registration_id, :round_id], unique: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can just be t.index inside of create_table, but feel free to prove me wrong

@@ -1084,6 +1115,7 @@
t.text "round_results", size: :medium
t.integer "total_number_of_rounds", null: false
t.string "old_type", limit: 1
t.boolean "is_open", default: false, null: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a corresponding migration for this. Potential whoopsie from your other PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that should probably go into the open round pr instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants