Skip to content

Commit a7ea921

Browse files
authored
Merge pull request #12651 from empirical-org/develop
Release 2024-12-11
2 parents 1e52588 + 36e65ec commit a7ea921

File tree

10 files changed

+117
-19
lines changed

10 files changed

+117
-19
lines changed

services/QuillLMS/app/models/activity.rb

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class Activity < ApplicationRecord
105105
scope :alpha_user, -> { where("'#{ALPHA}' = ANY(activities.flags) OR '#{BETA}' = ANY(activities.flags) OR '#{GAMMA}' = ANY(activities.flags) OR '#{PRODUCTION}' = ANY(activities.flags)") }
106106

107107
scope :with_classification, -> { includes(:classification).joins(:classification) }
108+
scope :diagnostic, -> { where(classification: ActivityClassification.diagnostic) }
108109
scope :evidence, -> { where(classification: ActivityClassification.evidence) }
109110
scope :evidence_beta1, -> { where(flags: [Flags::EVIDENCE_BETA1]) }
110111
scope :evidence_beta2, -> { where(flags: [Flags::EVIDENCE_BETA2]) }

services/QuillLMS/app/models/concerns/translatable.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ module Translatable
5959
class_attribute :default_translatable_field, default: nil
6060
end
6161

62-
def create_translation_mappings
63-
create_translation_mappings_with_text(translatable_text:)
64-
end
65-
66-
def create_translation_mappings_with_text(translatable_text:, field_name: default_translatable_field)
62+
def create_translation_mappings(field_name: default_translatable_field)
6763
return unless translatable_text.is_a?(String) && translatable_text.present?
68-
return unless translation_mappings.joins(:english_text)
64+
return if translation_mappings.joins(:english_text)
6965
.where(field_name:)
7066
.where(english_text: { text: translatable_text })
71-
.empty?
67+
.exists?
7268

73-
clean_deprecated_translations(translatable_text:, field_name:)
69+
destroy_deprecated_translations(translatable_text:, field_name:)
7470

71+
create_translation_mappings_with_text(translatable_text:)
72+
end
73+
74+
def create_translation_mappings_with_text(translatable_text:, field_name: default_translatable_field)
7575
english_text = EnglishText.find_or_create_by(text: translatable_text)
7676
translation_mappings.create(english_text:, field_name:)
7777
end
@@ -130,7 +130,7 @@ def open_ai_prompt(locale:)
130130
data[default_translatable_field]
131131
end
132132

133-
private def clean_deprecated_translations(translatable_text:, field_name:)
133+
private def destroy_deprecated_translations(translatable_text:, field_name:)
134134
translation_mappings.joins(:english_text)
135135
.where(field_name:)
136136
.where.not(english_text: { text: translatable_text })

services/QuillLMS/app/models/student_learning_sequence_activity.rb

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class StudentLearningSequenceActivity < ApplicationRecord
2525
belongs_to :classroom_unit
2626
belongs_to :student_learning_sequence
2727

28+
delegate :user, to: :student_learning_sequence
29+
2830
validates :activity_id, presence: true
2931
validates :classroom_unit_id, presence: true
3032
validates :student_learning_sequence_id, presence: true

services/QuillLMS/app/services/student_learning_sequences/find_initial_activity.rb

+29-8
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,46 @@ def run
1313
return unless activity_id && classroom_unit_id
1414
return activity if pre_diagnostic?
1515

16-
for_post_diagnostic || for_recommended_activity
16+
for_post_diagnostic || for_pre_recommendation || for_post_recommendation
1717
end
1818

1919
private def activity = @activity ||= Activity.find_by(id: activity_id)
2020
private def classroom_unit = @classroom_unit ||= ClassroomUnit.find(classroom_unit_id)
2121

2222
private def pre_diagnostic? = activity.is_pre_diagnostic?
23-
private def for_post_diagnostic = Activity.find_by(follow_up_activity_id: activity_id)
23+
private def for_post_diagnostic = Activity.diagnostic.find_by(follow_up_activity_id: activity_id)
2424

25-
private def for_recommended_activity
25+
private def for_pre_recommendation
2626
Activity.joins(recommendations: {
2727
unit_template: {
2828
unit_unscoped: :classroom_units
2929
}
30-
}).find_by(recommendations: {
31-
unit_template: {
32-
units: {
33-
classroom_units: {
34-
id: classroom_unit_id
30+
}).where.not(follow_up_activity_id: nil)
31+
.find_by(recommendations: {
32+
unit_template: {
33+
units: {
34+
classroom_units: {
35+
id: classroom_unit_id
36+
}
37+
}
38+
}
39+
})
40+
end
41+
42+
private def for_post_recommendation
43+
Activity.joins(follow_up_activity: {
44+
recommendations: {
45+
unit_template: {
46+
unit_unscoped: :classroom_units
47+
}
48+
}
49+
}).find_by(follow_up_activity: {
50+
recommendations: {
51+
unit_template: {
52+
units: {
53+
classroom_units: {
54+
id: classroom_unit_id
55+
}
3556
}
3657
}
3758
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
module StudentLearningSequences
4+
module Backfill
5+
class PostRecommendationAssignmentWorker < BaseWorker
6+
def run_backfill
7+
backfill_classroom_units(recommendation_classroom_units)
8+
end
9+
10+
def recommendation_classroom_units
11+
ClassroomUnit.joins(unit_unscoped: { unit_template: :recommendations })
12+
.where(unit: {
13+
unit_template: {
14+
recommendations: {
15+
activity_id: post_diagnostic_activity_ids
16+
}
17+
}
18+
})
19+
end
20+
end
21+
end
22+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
module StudentLearningSequences
4+
module Backfill
5+
class PostRecommendationCompletionWorker < BaseWorker
6+
def run_backfill
7+
backfill_activity_sessions(recommendation_activity_sessions)
8+
end
9+
10+
def recommendation_activity_sessions
11+
ActivitySession.unscoped.joins(classroom_unit: {
12+
unit_unscoped: {
13+
unit_template: :recommendations
14+
}
15+
}).where(classroom_unit: {
16+
unit: {
17+
unit_template: {
18+
recommendations: {
19+
activity_id: post_diagnostic_activity_ids
20+
}
21+
}
22+
}
23+
})
24+
end
25+
end
26+
end
27+
end

services/QuillLMS/app/workers/student_learning_sequences/backfill/recommendation_assignment_worker.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def run_backfill
88
end
99

1010
def recommendation_classroom_units
11-
ClassroomUnit.joins(unit: { unit_template: :recommendations })
11+
ClassroomUnit.joins(unit_unscoped: { unit_template: :recommendations })
1212
.where(unit: {
1313
unit_template: {
1414
recommendations: {

services/QuillLMS/spec/services/student_learning_sequences/find_initial_activity_spec.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module StudentLearningSequences
3434
it { expect(subject).to eq(pre_diagnostic) }
3535
end
3636

37-
context 'activity is part of a recommendation' do
37+
context 'activity is part of a pre diagnostic recommendation' do
3838
let(:pre_diagnostic) { create(:pre_diagnostic_activity) }
3939
let!(:recommendation) { create(:recommendation, activity: pre_diagnostic, unit_template:) }
4040

@@ -56,5 +56,19 @@ module StudentLearningSequences
5656
end
5757
end
5858
end
59+
60+
context 'activity is part of a post diagnostic recommendation' do
61+
let(:pre_diagnostic) { create(:pre_diagnostic_activity) }
62+
let(:post_diagnostic) { pre_diagnostic.follow_up_activity }
63+
let!(:recommendation) { create(:recommendation, activity: post_diagnostic, unit_template:) }
64+
65+
it { expect(subject).to eq(pre_diagnostic) }
66+
67+
context 'even when the recommendation is a follow-up, handling an edge case that did not come up with pre diagnostic recommendations' do
68+
let!(:precursor_activity) { create(:connect_activity, follow_up_activity: activity) }
69+
70+
it { expect(subject).to eq(pre_diagnostic) }
71+
end
72+
end
5973
end
6074
end

services/QuillLMS/spec/services/student_learning_sequences/handle_assignment_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ module StudentLearningSequences
104104
.and not_change(StudentLearningSequenceActivity, :count)
105105
end
106106
end
107+
108+
context 'handle assigning post-diagnostic recommendations' do
109+
let(:recommended_activity) { create(:activity) }
110+
let(:unit_template) { create(:unit_template, activities: [recommended_activity]) }
111+
let(:unit) { create(:unit, unit_template:, activities: [recommended_activity]) }
112+
let(:classroom_unit) { create(:classroom_unit, classroom:, unit:, assigned_student_ids: [student_id]) }
113+
let!(:recommendation) { create(:recommendation, activity: post_diagnostic, unit_template:) }
114+
115+
it { expect { subject }.to not_change(StudentLearningSequence, :count) }
116+
it { expect { subject }.to change(StudentLearningSequenceActivity, :count).by(1) }
117+
end
107118
end
108119
end
109120
end

0 commit comments

Comments
 (0)