mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-09 07:28:41 -07:00
import students
This commit is contained in:
parent
8c7767d0b9
commit
12e4e3f177
28 changed files with 11093 additions and 10843 deletions
|
|
@ -183,10 +183,11 @@ class Measure < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def sufficient_student_data?(school:, academic_year:)
|
||||
return @sufficient_student_data ||= false unless includes_student_survey_items?
|
||||
return @sufficient_student_data ||= false if no_student_responses_exist?(school:, academic_year:)
|
||||
false unless includes_student_survey_items?
|
||||
false if no_student_responses_exist?(school:, academic_year:)
|
||||
|
||||
@sufficient_student_data ||= subcategory.response_rate(school:, academic_year:).meets_student_threshold?
|
||||
# this gets memoized on first run so check to make sure
|
||||
subcategory.response_rate(school:, academic_year:).meets_student_threshold?
|
||||
end
|
||||
|
||||
def sufficient_teacher_data?(school:, academic_year:)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
class Race < ApplicationRecord
|
||||
include FriendlyId
|
||||
has_many :student_races
|
||||
has_many :students, through: :student_races
|
||||
friendly_id :designation, use: [:slugged]
|
||||
end
|
||||
|
|
|
|||
7
app/models/student.rb
Normal file
7
app/models/student.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
class Student < ApplicationRecord
|
||||
has_many :survey_item_responses
|
||||
has_many :student_races
|
||||
has_many :races, through: :student_races
|
||||
|
||||
encrypts :lasid, deterministic: true
|
||||
end
|
||||
4
app/models/student_race.rb
Normal file
4
app/models/student_race.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
class StudentRace < ApplicationRecord
|
||||
belongs_to :student
|
||||
belongs_to :race
|
||||
end
|
||||
|
|
@ -7,6 +7,8 @@ class SurveyItemResponse < ActiveRecord::Base
|
|||
belongs_to :academic_year
|
||||
belongs_to :school
|
||||
belongs_to :survey_item, counter_cache: true
|
||||
belongs_to :student, foreign_key: :student_id, optional: true
|
||||
|
||||
has_one :measure, through: :survey_item
|
||||
|
||||
scope :exclude_boston, lambda {
|
||||
|
|
|
|||
74
app/services/student_loader.rb
Normal file
74
app/services/student_loader.rb
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# SurveyItemResponse.where(student: StudentRace.where(race: Race.find_by_qualtrics_code(8)).limit(10).map(&:student)).count
|
||||
require 'csv'
|
||||
|
||||
class StudentLoader
|
||||
def self.load_data(filepath:)
|
||||
File.open(filepath) do |file|
|
||||
headers = file.first
|
||||
|
||||
students = []
|
||||
file.lazy.each_slice(1000) do |lines|
|
||||
CSV.parse(lines.join, headers:).map do |row|
|
||||
# students << process_row(row:)
|
||||
process_row(row:)
|
||||
end
|
||||
end
|
||||
# Student.import students.compact.flatten.to_set.to_a, batch_size: 1000,
|
||||
# on_duplicate_key_update: { conflict_target: [:id] }
|
||||
end
|
||||
end
|
||||
|
||||
def self.process_row(row:)
|
||||
race_codes = row['RACE'] || row['What is your race/ethnicity?(Please select all that apply) - Selected Choice'] || '99'
|
||||
race_codes = race_codes.split(',').map(&:to_i) || []
|
||||
races = process_races(codes: race_codes)
|
||||
response_id = row['ResponseId'] || row['Responseid'] || row['ResponseID'] ||
|
||||
row['Response ID'] || row['Response id'] || row['Response Id']
|
||||
lasid = row['LASID'] || row['lasid']
|
||||
return nil if student_exists?(response_id:)
|
||||
|
||||
student = create_student(response_id:, lasid:, races:)
|
||||
|
||||
assign_student_to_responses(response_id:, student:)
|
||||
student
|
||||
end
|
||||
|
||||
def self.student_exists?(response_id:)
|
||||
Student.find_by_response_id(response_id).present?
|
||||
end
|
||||
|
||||
def self.assign_student_to_responses(response_id:, student:)
|
||||
survey_responses = SurveyItemResponse.where(response_id:)
|
||||
survey_responses.each do |response|
|
||||
response.student = student
|
||||
response.save
|
||||
end
|
||||
|
||||
# SurveyItemResponse.import survey_responses, on_duplicate_key_update: { conflict_target: [:id], columns: [:student] }
|
||||
end
|
||||
|
||||
def self.create_student(response_id:, lasid:, races:)
|
||||
student = Student.new(response_id:)
|
||||
races.each do |race|
|
||||
student.races << race
|
||||
end
|
||||
student.lasid = lasid
|
||||
student.save
|
||||
student
|
||||
end
|
||||
|
||||
def self.process_races(codes:)
|
||||
codes = codes.map do |code|
|
||||
code = 99 if [6, 7].include?(code)
|
||||
Race.find_by_qualtrics_code(code)
|
||||
end
|
||||
remove_unknown_race_if_other_races_present(races: codes.to_set)
|
||||
end
|
||||
|
||||
def self.remove_unknown_race_if_other_races_present(races:)
|
||||
races.delete(Race.find_by_qualtrics_code(99)) if races.length > 1
|
||||
races
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue