-
Notifications
You must be signed in to change notification settings - Fork 479
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
Changes from 14 commits
067a1ed
c6a21e9
6611cb2
9503892
39556e7
d182680
55551b9
192352c
b905ef6
0ac0230
6a10f0d
08c2c71
76fbfd8
6468e50
bfe00cf
1b2df0a
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 |
---|---|---|
|
@@ -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 commentThe 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). |
||
teachers_attending = sessions.flat_map(&:attendances).flat_map(&:teacher) | ||
|
||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this check is sufficient. We have 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. Second concern here - we're nesting a second ActiveRecord query inside a loop, so we'll run the 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. Updated with appropriate check, and changed to be a single ActiveRecord query. |
||
{ | ||
user: teacher, | ||
application_year: school_year, | ||
course: course_key | ||
} | ||
) | ||
end | ||
end | ||
|
||
# Get number of sessions attended by teacher | ||
attendance_count_by_teacher = Hash[ | ||
teachers_attending.uniq.map do |teacher| | ||
[teacher, teachers_attending.count(teacher)] | ||
end | ||
] | ||
|
||
# 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 commentThe 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 commentThe 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. |
||
end | ||
|
||
def local_summer? | ||
subject == SUBJECT_SUMMER_WORKSHOP | ||
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.
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!