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
Workshop report improvements #32799
Workshop report improvements #32799
Conversation
dashboard/app/models/pd/workshop.rb
Outdated
@@ -580,6 +580,34 @@ def attending_teachers | |||
sessions.flat_map(&:attendances).flat_map(&:teacher).uniq | |||
end | |||
|
|||
# Get all teachers who have attended all sessions of this workshop. | |||
def teachers_attending_all_sessions(cdo_scholarship=false) |
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.
I might rename this parameter to something like filter_on_scholarship so it's clear false gives you all the teachers and true gives you just those with scholarships. The current name could be interpreted as false=teachers without scholarships
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.
Good idea, thanks!
dashboard/app/models/pd/workshop.rb
Outdated
# Filter attendances to only scholarship teachers | ||
if cdo_scholarship | ||
teachers_attending.select! do |teacher| | ||
Pd::ScholarshipInfo.exists?( |
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.
I don't think this check is sufficient. We have Pd::ScholarshipInfo
rows where scholarship_status
is 'no'
, which doesn't seem to match what you're querying for here. In fact, I think all applications get a ScholarshipInfo
now?
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.
Second concern here - we're nesting a second ActiveRecord query inside a loop, so we'll run the exists?
once for every teacher in the workshop. It would be better to add a join
to the teachers_attending
relation so we're not adding a query... but that could be follow-up work. Let's make sure this is working as designed first.
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.
You're totally right re: check not being sufficient, will update. Apologies for the oversight.
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.
Updated with appropriate check, and changed to be a single ActiveRecord query.
] | ||
|
||
# Return only teachers who attended all sessions | ||
attendance_count_by_teacher.select {|_, attendances| attendances == sessions.count}.keys |
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 fact, this whole thing is quite the query optimization challenge! Since this is just for payments I think you could merge this as-is, but it might be worth revisiting as a good exercise in query optimization within ActiveRecord. Ask Will about his query-counting unit tests sometime.
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.
I know right, it's hairy! I'll do some research on optimizing queries here tomorrow and share with y'all to review.
dashboard/app/models/pd/workshop.rb
Outdated
@@ -580,6 +580,34 @@ def attending_teachers | |||
sessions.flat_map(&:attendances).flat_map(&:teacher).uniq | |||
end | |||
|
|||
# Get all teachers who have attended all sessions of this workshop. | |||
def teachers_attending_all_sessions(cdo_scholarship=false) |
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.
This whole method might be a good candidate for a Query object (read linked doc and ask Elijah for details).
…hop-summary-report-updates Updates to workshop summary report (resuscitated from #32799)
PLC-609: Update workshop report spreadsheet to facilitate payments processing
Testing story
Updates existing tests, and adds a new test for the workshop method that returns all attendees who attended all sessions.
Reviewer Checklist: