Skip to content

Commit d4abb0e

Browse files
authored
Merge pull request #1864 from openstax/sparfa_admin
Sparfa admin settings
2 parents f54afaa + 2b55e6c commit d4abb0e

File tree

14 files changed

+129
-126
lines changed

14 files changed

+129
-126
lines changed

app/routines/create_course.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ def exec(name:, is_preview:, is_test:, is_college: nil, is_concept_coach: nil, t
7575
default_open_time: default_open_time,
7676
default_due_time: default_due_time,
7777
estimated_student_count: estimated_student_count,
78-
biglearn_student_clues_algorithm_name: Settings::Biglearn.student_clues_algorithm_name,
79-
biglearn_teacher_clues_algorithm_name: Settings::Biglearn.teacher_clues_algorithm_name,
80-
biglearn_assignment_spes_algorithm_name: Settings::Biglearn.assignment_spes_algorithm_name,
81-
biglearn_assignment_pes_algorithm_name: Settings::Biglearn.assignment_pes_algorithm_name,
82-
biglearn_practice_worst_areas_algorithm_name: \
83-
Settings::Biglearn.practice_worst_areas_algorithm_name,
8478
homework_score_weight: homework_score_weight,
8579
homework_progress_weight: homework_progress_weight,
8680
reading_score_weight: reading_score_weight,

app/subsystems/course_profile/models/course.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ class CourseProfile::Models::Course < ApplicationRecord
4646
enum term: [ :legacy, :demo, :spring, :summer, :fall, :winter, :preview ]
4747

4848
validates :time_zone, presence: true, uniqueness: true
49-
validates :name, :term, :year, :starts_at, :ends_at,
50-
:biglearn_student_clues_algorithm_name,
51-
:biglearn_teacher_clues_algorithm_name,
52-
:biglearn_assignment_spes_algorithm_name,
53-
:biglearn_assignment_pes_algorithm_name,
54-
:biglearn_practice_worst_areas_algorithm_name,
55-
presence: true
49+
validates :name, :term, :year, :starts_at, :ends_at, presence: true
5650
validates :homework_score_weight,
5751
:homework_progress_weight,
5852
:reading_score_weight,

config/initializers/02-settings.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ class Settings::Db::Store < RailsSettings::CachedSettings
1919
Settings::Db.store.defaults[:active_nomad_onboarding_salesforce_campaign_id] = ''
2020
Settings::Db.store.defaults[:find_tutor_course_period_report_id] = ''
2121

22-
Settings::Db.store.defaults[:biglearn_student_clues_algorithm_name] = 'biglearn_sparfa'
23-
Settings::Db.store.defaults[:biglearn_teacher_clues_algorithm_name] = 'biglearn_sparfa'
22+
Settings::Db.store.defaults[:biglearn_student_clues_algorithm_name] = :biglearn_sparfa
23+
Settings::Db.store.defaults[:biglearn_teacher_clues_algorithm_name] = :biglearn_sparfa
2424
Settings::Db.store.defaults[:biglearn_assignment_spes_algorithm_name] = \
25-
'student_driven_biglearn_sparfa'
26-
Settings::Db.store.defaults[:biglearn_assignment_pes_algorithm_name] = 'biglearn_sparfa'
27-
Settings::Db.store.defaults[:biglearn_practice_worst_areas_algorithm_name] = 'biglearn_sparfa'
25+
:student_driven_biglearn_sparfa
26+
Settings::Db.store.defaults[:biglearn_assignment_pes_algorithm_name] = :biglearn_sparfa
27+
Settings::Db.store.defaults[:biglearn_practice_worst_areas_algorithm_name] = :biglearn_sparfa
2828

2929
Settings::Db.store.defaults[:default_is_lms_enabling_allowed] = false
3030

config/initializers/rails_settings_ui.rb

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,27 @@ def main_app_route_method?(method, include_private_methods = false)
1414
end
1515
end
1616

17-
#= Application-specific
18-
#
19-
# # You can specify a controller for RailsSettingsUi::ApplicationController to inherit from:
20-
RailsSettingsUi.parent_controller = 'Admin::BaseController' # default: '::ApplicationController'
21-
#
22-
# # Render RailsSettingsUi inside a custom layout (set to 'application' to use app layout, default is RailsSettingsUi's own layout)
23-
24-
RailsSettingsUi.settings_class = "Settings::Db::Store"
17+
RailsSettingsUi.setup do |config|
18+
# Specify a controller for RailsSettingsUi::ApplicationController to inherit from:
19+
config.parent_controller = 'Admin::BaseController' # default: '::ApplicationController'
20+
21+
config.settings_class = "Settings::Db::Store"
22+
23+
config.settings_displayed_as_select_tag = [
24+
:biglearn_student_clues_algorithm_name,
25+
:biglearn_teacher_clues_algorithm_name,
26+
:biglearn_assignment_spes_algorithm_name,
27+
:biglearn_assignment_pes_algorithm_name,
28+
:biglearn_practice_worst_areas_algorithm_name
29+
]
30+
end
2531

2632
Rails.application.config.to_prepare do
2733
# If you use a *custom layout*, make route helpers available to RailsSettingsUi:
2834
RailsSettingsUi.inline_main_app_routes!
2935
RailsSettingsUi::ApplicationController.module_eval do
36+
# Render RailsSettingsUi inside a custom layout
37+
# (set to 'application' to use app layout, default is RailsSettingsUi's own layout)
3038
layout 'admin'
3139
end
3240

config/locales/en.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,31 @@ en:
3636
help_block: 'In the format HH:MM'
3737
biglearn_student_clues_algorithm_name:
3838
name: 'Biglearn algorithm for calculating Student CLUes'
39-
help_block: 'This setting can also be changed on a per-course basis. Changing it here will only affect new courses.'
39+
labels:
40+
SPARFA: biglearn_sparfa
41+
Local Query: biglearn_local_query
4042
biglearn_teacher_clues_algorithm_name:
4143
name: 'Biglearn algorithm for calculating Teacher CLUes'
42-
help_block: 'This setting can also be changed on a per-course basis. Changing it here will only affect new courses.'
44+
labels:
45+
SPARFA: biglearn_sparfa
46+
Local Query: biglearn_local_query
4347
biglearn_assignment_spes_algorithm_name:
4448
name: 'Biglearn algorithm for choosing Spaced Practice exercises'
45-
help_block: 'This setting can also be changed on a per-course basis. Changing it here will only affect new courses.'
49+
labels:
50+
Student-Driven SPARFA: student_driven_biglearn_sparfa
51+
Instructor-Driven SPARFA: instructor_driven_biglearn_sparfa
52+
Student-Driven Local Query: student_driven_biglearn_local_query
53+
Instructor-Driven Local Query: instructor_driven_biglearn_local_query
4654
biglearn_assignment_pes_algorithm_name:
4755
name: 'Biglearn algorithm for choosing Personalized exercises'
48-
help_block: 'This setting can also be changed on a per-course basis. Changing it here will only affect new courses.'
56+
labels:
57+
SPARFA: biglearn_sparfa
58+
Local Query: biglearn_local_query
4959
biglearn_practice_worst_areas_algorithm_name:
5060
name: 'Biglearn algorithm for choosing exercises for Practice Worst Topics'
51-
help_block: 'This setting can also be changed on a per-course basis. Changing it here will only affect new courses.'
61+
labels:
62+
SPARFA: biglearn_sparfa
63+
Local Query: biglearn_local_query
5264
default_due_time:
5365
name: 'Default task due time'
5466
help_block: 'In the format HH:MM'

db/migrate/20170307230726_add_biglearn_algorithm_names_to_course_profile_courses.rb

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,29 @@ def up
66
add_column :course_profile_courses, :biglearn_assignment_pes_algorithm_name, :string
77
add_column :course_profile_courses, :biglearn_practice_worst_areas_algorithm_name, :string
88

9-
change_column_null :course_profile_courses,
10-
:biglearn_student_clues_algorithm_name,
11-
false,
12-
Settings::Biglearn.student_clues_algorithm_name
13-
change_column_null :course_profile_courses,
14-
:biglearn_teacher_clues_algorithm_name,
15-
false,
16-
Settings::Biglearn.teacher_clues_algorithm_name
17-
change_column_null :course_profile_courses,
18-
:biglearn_assignment_spes_algorithm_name,
19-
false,
20-
Settings::Biglearn.assignment_spes_algorithm_name
21-
change_column_null :course_profile_courses,
22-
:biglearn_assignment_pes_algorithm_name,
23-
false,
24-
Settings::Biglearn.assignment_pes_algorithm_name
25-
change_column_null :course_profile_courses,
26-
:biglearn_practice_worst_areas_algorithm_name,
27-
false,
28-
Settings::Biglearn.practice_worst_areas_algorithm_name
29-
30-
# Remove local_query_with_ from the default biglearn client, since those are no longer valid
31-
biglearn_client = Settings::Db.store.biglearn_client
32-
Settings::Db.store.biglearn_client = biglearn_client.to_s.sub('local_query_with_', '').to_sym
33-
end
34-
35-
def down
36-
remove_column :course_profile_courses, :biglearn_practice_worst_areas_algorithm_name, :string
37-
remove_column :course_profile_courses, :biglearn_assignment_pes_algorithm_name, :string
38-
remove_column :course_profile_courses, :biglearn_assignment_spes_algorithm_name, :string
39-
remove_column :course_profile_courses, :biglearn_teacher_clues_algorithm_name, :string
40-
remove_column :course_profile_courses, :biglearn_student_clues_algorithm_name, :string
9+
reversible do |dir|
10+
dir.up do
11+
change_column_null :course_profile_courses,
12+
:biglearn_student_clues_algorithm_name,
13+
false,
14+
Settings::Biglearn.student_clues_algorithm_name
15+
change_column_null :course_profile_courses,
16+
:biglearn_teacher_clues_algorithm_name,
17+
false,
18+
Settings::Biglearn.teacher_clues_algorithm_name
19+
change_column_null :course_profile_courses,
20+
:biglearn_assignment_spes_algorithm_name,
21+
false,
22+
Settings::Biglearn.assignment_spes_algorithm_name
23+
change_column_null :course_profile_courses,
24+
:biglearn_assignment_pes_algorithm_name,
25+
false,
26+
Settings::Biglearn.assignment_pes_algorithm_name
27+
change_column_null :course_profile_courses,
28+
:biglearn_practice_worst_areas_algorithm_name,
29+
false,
30+
Settings::Biglearn.practice_worst_areas_algorithm_name
31+
end
32+
end
4133
end
4234
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class AllowNullBiglearnAlgorithmNames < ActiveRecord::Migration
2+
def change
3+
change_column_null :course_profile_courses, :biglearn_student_clues_algorithm_name, true
4+
change_column_null :course_profile_courses, :biglearn_teacher_clues_algorithm_name, true
5+
change_column_null :course_profile_courses, :biglearn_assignment_spes_algorithm_name, true
6+
change_column_null :course_profile_courses, :biglearn_assignment_pes_algorithm_name, true
7+
change_column_null :course_profile_courses, :biglearn_practice_worst_areas_algorithm_name, true
8+
9+
reversible do |dir|
10+
dir.up do
11+
CourseProfile::Models::Course.update_all(
12+
biglearn_student_clues_algorithm_name: nil,
13+
biglearn_teacher_clues_algorithm_name: nil,
14+
biglearn_assignment_spes_algorithm_name: nil,
15+
biglearn_assignment_pes_algorithm_name: nil,
16+
biglearn_practice_worst_areas_algorithm_name: nil
17+
)
18+
end
19+
20+
dir.down do
21+
CourseProfile::Models::Course.update_all(
22+
biglearn_student_clues_algorithm_name: Settings::Biglearn.student_clues_algorithm_name,
23+
biglearn_teacher_clues_algorithm_name: Settings::Biglearn.teacher_clues_algorithm_name,
24+
biglearn_assignment_spes_algorithm_name: \
25+
Settings::Biglearn.assignment_spes_algorithm_name,
26+
biglearn_assignment_pes_algorithm_name: \
27+
Settings::Biglearn.assignment_pes_algorithm_name,
28+
biglearn_practice_worst_areas_algorithm_name: \
29+
Settings::Biglearn.practice_worst_areas_algorithm_name
30+
)
31+
end
32+
end
33+
end
34+
end

db/schema.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20190411181631) do
14+
ActiveRecord::Schema.define(version: 20190506190532) do
1515

1616
# These are extensions that must be enabled in order to support this database
1717
enable_extension "plpgsql"
@@ -357,11 +357,11 @@
357357
t.boolean "is_excluded_from_salesforce", default: false, null: false
358358
t.uuid "uuid", default: "gen_random_uuid()", null: false
359359
t.integer "sequence_number", default: 0, null: false
360-
t.string "biglearn_student_clues_algorithm_name", null: false
361-
t.string "biglearn_teacher_clues_algorithm_name", null: false
362-
t.string "biglearn_assignment_spes_algorithm_name", null: false
363-
t.string "biglearn_assignment_pes_algorithm_name", null: false
364-
t.string "biglearn_practice_worst_areas_algorithm_name", null: false
360+
t.string "biglearn_student_clues_algorithm_name"
361+
t.string "biglearn_teacher_clues_algorithm_name"
362+
t.string "biglearn_assignment_spes_algorithm_name"
363+
t.string "biglearn_assignment_pes_algorithm_name"
364+
t.string "biglearn_practice_worst_areas_algorithm_name"
365365
t.boolean "is_test", default: false, null: false
366366
t.boolean "does_cost", default: false, null: false
367367
t.integer "estimated_student_count"

lib/openstax/biglearn/api/real_client.rb

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,13 @@ def fetch_assignment_pes(requests)
471471
task = request.fetch(:task)
472472
course = task.taskings.first.role.student.course
473473
max_num_exercises = request[:max_num_exercises]
474+
algorithm_name = course.biglearn_assignment_pes_algorithm_name ||
475+
Settings::Biglearn.assignment_pes_algorithm_name.to_s
474476

475477
{
476478
request_uuid: request.fetch(:request_uuid),
477479
assignment_uuid: task.uuid,
478-
algorithm_name: course.biglearn_assignment_pes_algorithm_name
480+
algorithm_name: algorithm_name
479481
}.tap do |biglearn_request|
480482
biglearn_request[:max_num_exercises] = max_num_exercises unless max_num_exercises.nil?
481483
end
@@ -491,11 +493,13 @@ def fetch_assignment_spes(requests)
491493
task = request.fetch(:task)
492494
course = task.taskings.first.role.student.course
493495
max_num_exercises = request[:max_num_exercises]
496+
algorithm_name = course.biglearn_assignment_spes_algorithm_name ||
497+
Settings::Biglearn.assignment_spes_algorithm_name.to_s
494498

495499
{
496500
request_uuid: request.fetch(:request_uuid),
497501
assignment_uuid: task.uuid,
498-
algorithm_name: course.biglearn_assignment_spes_algorithm_name
502+
algorithm_name: algorithm_name
499503
}.tap do |biglearn_request|
500504
biglearn_request[:max_num_exercises] = max_num_exercises unless max_num_exercises.nil?
501505
end
@@ -511,11 +515,13 @@ def fetch_practice_worst_areas_exercises(requests)
511515
student = request.fetch(:student)
512516
course = student.course
513517
max_num_exercises = request[:max_num_exercises]
518+
algorithm_name = course.biglearn_practice_worst_areas_algorithm_name ||
519+
Settings::Biglearn.practice_worst_areas_algorithm_name.to_s
514520

515521
{
516522
request_uuid: request.fetch(:request_uuid),
517523
student_uuid: student.uuid,
518-
algorithm_name: course.biglearn_practice_worst_areas_algorithm_name
524+
algorithm_name: algorithm_name
519525
}.tap do |biglearn_request|
520526
biglearn_request[:max_num_exercises] = max_num_exercises unless max_num_exercises.nil?
521527
end
@@ -530,12 +536,14 @@ def fetch_student_clues(requests)
530536
biglearn_requests = requests.map do |request|
531537
student = request.fetch(:student)
532538
course = student.course
539+
algorithm_name = course.biglearn_student_clues_algorithm_name ||
540+
Settings::Biglearn.student_clues_algorithm_name.to_s
533541

534542
{
535543
request_uuid: request.fetch(:request_uuid),
536544
student_uuid: student.uuid,
537545
book_container_uuid: request.fetch(:book_container).tutor_uuid,
538-
algorithm_name: course.biglearn_student_clues_algorithm_name
546+
algorithm_name: algorithm_name
539547
}
540548
end
541549

@@ -548,12 +556,14 @@ def fetch_teacher_clues(requests)
548556
biglearn_requests = requests.map do |request|
549557
course_container = request.fetch(:course_container)
550558
course = course_container.course
559+
algorithm_name = course.biglearn_teacher_clues_algorithm_name ||
560+
Settings::Biglearn.teacher_clues_algorithm_name.to_s
551561

552562
{
553563
request_uuid: request.fetch(:request_uuid),
554564
course_container_uuid: course_container.uuid,
555565
book_container_uuid: request.fetch(:book_container).tutor_uuid,
556-
algorithm_name: course.biglearn_teacher_clues_algorithm_name
566+
algorithm_name: algorithm_name
557567
}
558568
end
559569

@@ -563,10 +573,6 @@ def fetch_teacher_clues(requests)
563573

564574
protected
565575

566-
def algorithm_name
567-
Settings::Biglearn.algorithm_name
568-
end
569-
570576
def absolutize_url(url)
571577
Addressable::URI.join @server_url, url.to_s
572578
end

lib/settings/biglearn.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,25 @@
11
module Settings
22
module Biglearn
33

4-
# This code can be called when creating a database (before the settings table is created).
5-
# In that case, the setting has never been set, so the correct value is the default value.
64
class << self
75

86
def student_clues_algorithm_name
9-
return Settings::Db.store.defaults[:biglearn_student_clues_algorithm_name] \
10-
unless ActiveRecord::Base.connection.table_exists? 'settings'
11-
127
Settings::Db.store.biglearn_student_clues_algorithm_name
138
end
149

1510
def teacher_clues_algorithm_name
16-
return Settings::Db.store.defaults[:biglearn_teacher_clues_algorithm_name] \
17-
unless ActiveRecord::Base.connection.table_exists? 'settings'
18-
1911
Settings::Db.store.biglearn_teacher_clues_algorithm_name
2012
end
2113

2214
def assignment_spes_algorithm_name
23-
return Settings::Db.store.defaults[:biglearn_assignment_spes_algorithm_name] \
24-
unless ActiveRecord::Base.connection.table_exists? 'settings'
25-
2615
Settings::Db.store.biglearn_assignment_spes_algorithm_name
2716
end
2817

2918
def assignment_pes_algorithm_name
30-
return Settings::Db.store.defaults[:biglearn_assignment_pes_algorithm_name] \
31-
unless ActiveRecord::Base.connection.table_exists? 'settings'
32-
3319
Settings::Db.store.biglearn_assignment_pes_algorithm_name
3420
end
3521

3622
def practice_worst_areas_algorithm_name
37-
return Settings::Db.store.defaults[:biglearn_practice_worst_areas_algorithm_name] \
38-
unless ActiveRecord::Base.connection.table_exists? 'settings'
39-
4023
Settings::Db.store.biglearn_practice_worst_areas_algorithm_name
4124
end
4225

spec/factories/course_profile/courses.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@
1818

1919
uuid { SecureRandom.uuid }
2020

21-
sequence_number { rand(1000) + 1 }
22-
biglearn_student_clues_algorithm_name { Faker::Hacker.abbreviation }
23-
biglearn_teacher_clues_algorithm_name { Faker::Hacker.abbreviation }
24-
biglearn_assignment_spes_algorithm_name { Faker::Hacker.abbreviation }
25-
biglearn_assignment_pes_algorithm_name { Faker::Hacker.abbreviation }
26-
biglearn_practice_worst_areas_algorithm_name { Faker::Hacker.abbreviation }
21+
sequence_number { rand(1000) + 1 }
2722

2823
is_lms_enabling_allowed { is_lms_enabled == true ? true : false }
2924

0 commit comments

Comments
 (0)