Skip to content

Commit

Permalink
Merge pull request #12612 from empirical-org/develop
Browse files Browse the repository at this point in the history
Remove unused organization data from Vitally (#12585)
  • Loading branch information
cissyxyu authored Nov 28, 2024
2 parents c08a00c + 2d6287a commit ceeebc7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,12 @@ def diagnostic_rollups
school_year_end = school_year_start + 1.year
last_school_year_start = school_year_start - 1.year

diagnostics_assigned_this_year = diagnostics_assigned_between_count(school_year_start, school_year_end)
diagnostics_assigned_last_year = diagnostics_assigned_between_count(last_school_year_start, school_year_start)
diagnostics_completed_this_year = diagnostics_completed_between(school_year_start, school_year_end)
diagnostics_completed_last_year = diagnostics_completed_between(last_school_year_start, school_year_start)
percent_completed_this_year = diagnostics_assigned_this_year > 0 ? (1.0 * diagnostics_completed_this_year / diagnostics_assigned_this_year) : 0.0
percent_completed_last_year = diagnostics_assigned_last_year > 0 ? (1.0 * diagnostics_completed_last_year / diagnostics_assigned_last_year) : 0.0

live_pre_diagnostic_ids = Activity::PRE_TEST_DIAGNOSTIC_IDS
live_post_diagnostic_ids = Activity.where(id: live_pre_diagnostic_ids).pluck(:follow_up_activity_id)
all_pre_diagnostic_ids = Activity.where(activity_classification_id: ActivityClassification.diagnostic&.id).where.not(follow_up_activity: nil).pluck(:id)
all_post_diagnostic_ids = Activity.where(id: all_pre_diagnostic_ids).pluck(:follow_up_activity_id)

{
diagnostics_assigned_this_year: diagnostics_assigned_this_year,
diagnostics_assigned_last_year: diagnostics_assigned_last_year,
diagnostics_completed_this_year: diagnostics_completed_this_year,
diagnostics_completed_last_year: diagnostics_completed_last_year,
percent_diagnostics_completed_this_year: percent_completed_this_year,
percent_diagnostics_completed_last_year: percent_completed_last_year,
pre_diagnostics_assigned_this_year: subset_diagnostics_assigned_between_count(live_pre_diagnostic_ids, school_year_start, school_year_end),
pre_diagnostics_completed_this_year: subset_diagnostics_completed_between_count(live_pre_diagnostic_ids, school_year_start, school_year_end),
post_diagnostics_assigned_this_year: subset_diagnostics_assigned_between_count(live_post_diagnostic_ids, school_year_start, school_year_end),
Expand Down Expand Up @@ -141,22 +128,6 @@ def subscription_rollups
}
end

def diagnostics_assigned_between_count(start, stop)
district.schools.select('array_length(classroom_units.assigned_student_ids, 1) AS assigned_students')
.joins(users: {
unscoped_classrooms_i_teach: {
classroom_units: {
unit_activities: {
activity: :classification
}
}
}
}).where(classification: { key: ActivityClassification::DIAGNOSTIC_KEY })
.where(classroom_units: { created_at: start..stop })
.where('classrooms_teachers.role = ?', ClassroomsTeacher::ROLE_TYPES[:owner])
.map(&:assigned_students).reject(&:blank?).sum
end

def subset_diagnostics_assigned_between_count(diagnostic_ids, start, stop)
district.schools.select('array_length(classroom_units.assigned_student_ids, 1) AS assigned_students')
.joins(users: {
Expand All @@ -173,21 +144,6 @@ def subset_diagnostics_assigned_between_count(diagnostic_ids, start, stop)
.map(&:assigned_students).reject(&:blank?).sum
end

def diagnostics_completed_between(start, stop)
district.schools.joins(users: {
unscoped_classrooms_i_teach: {
classroom_units: {
activity_sessions: {
activity: :classification
}
}
}
}).where(classification: { key: ActivityClassification::DIAGNOSTIC_KEY })
.where('classrooms_teachers.role = ?', ClassroomsTeacher::ROLE_TYPES[:owner])
.where(activity_sessions: { completed_at: start..stop })
.count
end

def subset_diagnostics_completed_between_count(diagnostic_ids, start, stop)
district.schools.joins(users: {
unscoped_classrooms_i_teach: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
phone: district.phone,
total_students: district.total_students,
total_schools: district.total_schools,
diagnostics_assigned_this_year: 0,
diagnostics_assigned_last_year: 0,
diagnostics_completed_this_year: 0,
diagnostics_completed_last_year: 0,
pre_diagnostics_assigned_this_year: 0,
pre_diagnostics_completed_this_year: 0,
post_diagnostics_assigned_this_year: 0,
Expand All @@ -57,8 +53,6 @@
evidence_activities_completed_last_year: 0,
evidence_activities_completed_per_student_this_year: 0,
evidence_activities_completed_per_student_last_year: 0,
percent_diagnostics_completed_this_year: 0.0,
percent_diagnostics_completed_last_year: 0.0,
earliest_premium_start_date: described_class::VITALLY_NOT_APPLICABLE,
current_premium_start_date: described_class::VITALLY_NOT_APPLICABLE,
premium_expiry_date: described_class::VITALLY_NOT_APPLICABLE,
Expand All @@ -82,58 +76,6 @@
end

context 'diagnostic assignment rollups' do
let!(:classroom_unit) { create(:classroom_unit, classroom: classroom1, unit: unit, assigned_student_ids: [student1.id, student2.id]) }

it 'should roll up diagnostic data when diagnostics are assigned, but not completed' do
expect(described_class.new(district).data[:traits]).to include(
diagnostics_assigned_this_year: 2,
diagnostics_completed_this_year: 0,
diagnostics_assigned_last_year: 0
)
end

it 'should roll up diagnostic data when diagnostics are assigned last year' do
classroom_unit.update(created_at: 1.year.ago)

expect(described_class.new(district).data[:traits]).to include(
diagnostics_assigned_this_year: 0,
diagnostics_assigned_last_year: 2
)
end

it 'should roll up diagnostic data across multiple classrooms' do
school2 = create(:school, district: district)
teacher2 = create(:teacher, school: school2)
classroom2 = create(:classroom)
create(:classrooms_teacher, user: teacher2, classroom: classroom2)
student3 = create(:student)
create(:classroom_unit, classroom: classroom2, unit: unit, assigned_student_ids: [student2.id, student3.id])

expect(described_class.new(district).data[:traits]).to include(
diagnostics_assigned_this_year: 4
)
end

it 'should ignore assigned activities that are not diagnostics' do
classification = create(:connect)
diagnostic.update(classification: classification)

expect(described_class.new(district).data[:traits]).to include(
diagnostics_assigned_last_year: 0
)
end

it 'should roll up data for archived classrooms' do
classroom2 = create(:classroom, visible: false)
create(:classrooms_teacher, user: teacher1, classroom: classroom2)
student3 = create(:student)
create(:classroom_unit, classroom: classroom2, unit: unit, assigned_student_ids: [student2.id, student3.id])

expect(described_class.new(district).data[:traits]).to include(
diagnostics_assigned_this_year: 4
)
end

context 'pre diagnostics' do
let!(:post_diagnostic) { create(:diagnostic_activity) }
let!(:pre_diagnostic) { create(:diagnostic_activity, id: Activity::PRE_TEST_DIAGNOSTIC_IDS[0], follow_up_activity_id: post_diagnostic.id) }
Expand Down Expand Up @@ -211,80 +153,6 @@
end
end

context 'diagnostic completion rollups' do
let!(:classroom_unit) { create(:classroom_unit, classroom: classroom1, unit: unit, assigned_student_ids: [student1.id, student2.id]) }
let!(:activity_session1) { create(:activity_session, activity: diagnostic, classroom_unit: classroom_unit, user: student1, completed_at: Time.current) }
let!(:activity_session2) { create(:activity_session, activity: diagnostic, classroom_unit: classroom_unit, user: student2, completed_at: Time.current) }

it 'should roll up diagnostic completions this year' do
expect(described_class.new(district).data[:traits]).to include(
diagnostics_completed_this_year: 2,
diagnostics_completed_last_year: 0
)
end

it 'should roll up diagnostic completions from last year' do
activity_session1.update(completed_at: 1.year.ago)
activity_session2.update(completed_at: 1.year.ago)

expect(described_class.new(district).data[:traits]).to include(
diagnostics_completed_this_year: 0,
diagnostics_completed_last_year: 2
)
end

it 'should not count activity_session records that are not completed' do
activity_session1.update(completed_at: nil, state: 'started')
activity_session2.update(completed_at: nil, state: 'started')

expect(described_class.new(district).data[:traits]).to include(
diagnostics_completed_this_year: 0
)
end

it 'should roll up data across multiple schools' do
school2 = create(:school, district: district)
teacher2 = create(:teacher, school: school2)
classroom2 = create(:classroom)
student3 = create(:student)
create(:classrooms_teacher, user: teacher2, classroom: classroom2)
classroom_unit2 = create(:classroom_unit, classroom: classroom2, unit: unit, assigned_student_ids: [student2.id, student3.id])

create(:activity_session, activity: diagnostic, classroom_unit: classroom_unit2, user: student2, completed_at: Time.current)

expect(described_class.new(district).data[:traits]).to include(
diagnostics_completed_this_year: 3
)
end

it 'should not count activity_sessions for non-diagnostic activities' do
classification = create(:connect)
diagnostic.update(classification: classification)

expect(described_class.new(district).data[:traits]).to include(
diagnostics_completed_this_year: 0
)
end
end

context 'diagnostic completion percentage rollups' do
it 'should calculate completion percentages' do
student2 = create(:student, student_in_classroom: [classroom1])
classroom_unit1 = create(:classroom_unit, classroom: classroom1, unit: unit, assigned_student_ids: [student1.id, student2.id])
create(:activity_session, activity: diagnostic, classroom_unit: classroom_unit1, user: student1, completed_at: Time.current)

expect(described_class.new(district).data[:traits]).to include(
percent_diagnostics_completed_this_year: 0.5
)
end

it 'should set the completion rate to 0.0 if no activities were assigned' do
expect(described_class.new(district).data[:traits]).to include(
percent_diagnostics_completed_this_year: 0.0
)
end
end

context 'evidence rollups' do
before do
teacher = create(:user, role: 'teacher')
Expand Down

0 comments on commit ceeebc7

Please sign in to comment.