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

command line script to add teachers' csd sections to ai-rubrics experiment #57848

Merged
merged 6 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 37 additions & 0 deletions bin/oneoff/ai-rubrics-disable-teacher-sections
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env ruby

$experiment_name = 'ai-rubrics'

$teacher_emails = ARGV[0].split(',').compact.map(&:strip)
raise "Please provide a comma-separated list of teacher emails" if $teacher_emails.empty?

$teacher_emails.each do |email|
raise "Invalid email: #{email.dump}" unless email.include?('@')
end

# this can take up to 60 seconds
require_relative '../../dashboard/config/environment'

def main
num_disabled = 0
$teacher_emails.each do |email|
teacher = User.find_by_email(email)
unless teacher
puts "could not find user with email #{email.dump}"
next
end

sections = teacher.sections_instructed

experiments = SingleSectionExperiment.where(name: $experiment_name, section: sections)
if experiments.empty?
puts "no experiments found for teacher #{email}"
next
end
experiments.destroy_all
num_disabled += 1
end
puts "successfully disabled experiment for #{num_disabled} teachers" if num_disabled > 0
end

main
58 changes: 58 additions & 0 deletions bin/oneoff/ai-rubrics-enable-teacher-sections
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env ruby

$experiment_name = 'ai-rubrics'

# map from CSD course to that course's unit which supports the experiment
$csd_course_unit_map = {
'csd-2023' => 'csd3-2023',
'focus-on-creativity-2023' => 'focus-on-creativity3-2023',
'focus-on-coding-2023' => 'focus-on-coding3-2023',
}

# standalone units that support the experiment
$csd_standalone_units = ['interactive-games-animations-2023']

$teacher_emails = ARGV[0].split(',').compact.map(&:strip)
raise "Please provide a comma-separated list of teacher emails" if $teacher_emails.empty?

$teacher_emails.each do |email|
raise "Invalid email: #{email.dump}" unless email.include?('@')
end

# this can take up to 60 seconds
require_relative '../../dashboard/config/environment'
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is a trick. Add:

ENV['SKIP_I18N_INIT'] = '1'

Before this require. Cuts the time in half roughly in environments with localization enabled like production:

/code-dot-org $ time ruby script.rb
GetSecretValue: development/cdo/slack_bot_token

real    3m57.352s
user    3m37.076s
sys     0m17.138s
/code-dot-org $ vim script_with_skip.rb
/code-dot-org $ time ruby script_with_skip.rb
GetSecretValue: development/cdo/slack_bot_token

real    1m54.238s
user    1m40.048s
sys     0m13.254s

/code-dot-org $ cat script_with_skip.rb
ENV['SKIP_I18N_INIT'] = '1'
require_relative 'dashboard/config/environment'
``

Copy link
Member Author

Choose a reason for hiding this comment

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

great idea! thanks for this!

updated and retested both scripts in the simple case.


# given the course and unit a section is assigned to, assign the unit for which
# the experiment should be enabled
def get_experiment_unit_name(section)
assigned_course = section.unit_group&.name
assigned_unit = section.script&.name
return $csd_course_unit_map[assigned_course] if assigned_course
return assigned_unit if $csd_standalone_units.include?(assigned_unit)
end

def main
num_enabled = 0
$teacher_emails.each do |email|
teacher = User.find_by_email(email)
unless teacher
puts "could not find user with email #{email.dump}"
next
end

sections = teacher.sections_instructed.reject(&:hidden)
already_found_csd_section = false
sections.each do |section|
unit_name = get_experiment_unit_name(section)
next unless unit_name
num_enabled += 1 unless already_found_csd_section
already_found_csd_section = true
unit = Unit.find_by_name!(unit_name)
SingleSectionExperiment.find_or_create_by!(name: $experiment_name, section: section, script: unit)
end
puts "no CSD sections found for teacher #{email}" unless already_found_csd_section
end
puts "successfully enabled experiment for #{num_enabled} teachers" if num_enabled > 0
end

main