mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
added tasks to find stray responses and skipped questions
This commit is contained in:
parent
0a7b537256
commit
4bf61fb7b1
1 changed files with 207 additions and 0 deletions
|
|
@ -199,4 +199,211 @@ namespace :one_off do
|
|||
SurveyItemResponse.where(response_id: 'R_27fKhVfyeKGMF5q').delete_all
|
||||
SurveyItemResponse.where(response_id: 'R_2cjPX1Ngxr2Hc4c').delete_all
|
||||
end
|
||||
desc "Generate CSV report of teacher survey item responses"
|
||||
task teacher_survey_questions_csv: :environment do
|
||||
headers = ['School ID', 'Academic Year', 'Survey Item', 'Count','Percentage_diff']
|
||||
output_rows = []
|
||||
counts={}
|
||||
avg=0
|
||||
School.all.each do |sc|
|
||||
AcademicYear.all.each do |ay|
|
||||
sum=0
|
||||
nof_si=0
|
||||
threshold = Respondent.where(school: sc, academic_year: ay).pluck(:total_teachers)
|
||||
SurveyItem.teacher_survey_items.all.each do |si|
|
||||
c = SurveyItemResponse.where(school: sc, academic_year: ay, survey_item: si).group(:school_id).count
|
||||
if c.any? && (c.values.first >= 10 || c.values.first > threshold/4)
|
||||
counts[[sc.id, ay.id, si.id]] = c
|
||||
sum+=c.values.first
|
||||
nof_si+=1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
avg = sum.to_f/ nof_si
|
||||
counts.each do |key, value|
|
||||
if key[0] == sc.id && key[1] == ay.id
|
||||
count = value.values.first
|
||||
percentage_diff = ((count-avg) / avg) * 100
|
||||
counts[key] = { count: count, percentage_diff: percentage_diff }
|
||||
end
|
||||
end
|
||||
end end
|
||||
|
||||
counts.each do |key, value|
|
||||
output_rows << [School.where(id:key[0]).pluck(:name) , AcademicYear.where(id:key[1]).pluck(:range) , SurveyItem.where(id:key[2]).pluck(:survey_item_id), SurveyItem.where(id:key[2]).pluck(:prompt), value[:count], value[:percentage_diff]]
|
||||
end
|
||||
|
||||
file = File.new('teacher_survey_questions.csv', 'w')
|
||||
CSV.open(file, 'w', write_headers: true, headers: headers) do |csv|
|
||||
output_rows.each do |row|
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
|
||||
file.close
|
||||
puts "CSV report of teacher survey item responses with removed stray responses.csv"
|
||||
end
|
||||
|
||||
|
||||
desc "Generate CSV report of short survey item responses"
|
||||
task short_survey_questions_csv: :environment do
|
||||
headers = ['School ID', 'Academic Year', 'Survey Item', 'Count','Percentage_diff']
|
||||
output_rows = []
|
||||
counts={}
|
||||
avg=0
|
||||
temp=0
|
||||
count_response_grades_not_in_grades=0
|
||||
School.all.each do |sc|
|
||||
if Respondent.where(school: sc).any?
|
||||
grades_count=Respondent.where(school:sc).first.counts_by_grade
|
||||
grades= grades_count.keys
|
||||
AcademicYear.all.each do |ay|
|
||||
sum=0
|
||||
nof_si=0
|
||||
threshold=0
|
||||
threshold = Respondent.where(school: sc, academic_year: ay).pluck(:total_students)
|
||||
SurveyItem.short_form_items.all.each do |si|
|
||||
c = SurveyItemResponse.where(school: sc, academic_year: ay, survey_item: si).group(:school_id).count
|
||||
response_grades = SurveyItemResponse.where(school: sc, academic_year: ay, survey_item: si).pluck(:grade)
|
||||
count_response_grades_not_in_grades = response_grades.count { |grade| !grades.include?(grade) }
|
||||
if !count_response_grades_not_in_grades.nil? && c.any?
|
||||
c[c.keys.first] = c.values.first - count_response_grades_not_in_grades
|
||||
end
|
||||
|
||||
if threshold.any?
|
||||
if c.any? && (c.values.first >= 10 || c.values.first > threshold.first/4)
|
||||
counts[[sc.id, ay.id, si.id]] = c
|
||||
sum+=c.values.first
|
||||
nof_si+=1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
avg = sum.to_f/ nof_si
|
||||
counts.each do |key, value|
|
||||
if key[0] == sc.id && key[1] == ay.id
|
||||
count = value.values.first
|
||||
percentage_diff = ((count-avg) / avg) * 100
|
||||
counts[key] = { count: count, percentage_diff: percentage_diff }
|
||||
end
|
||||
end
|
||||
end end end
|
||||
|
||||
counts.each do |key, value|
|
||||
output_rows << [School.where(id:key[0]).pluck(:name) , AcademicYear.where(id:key[1]).pluck(:range) , SurveyItem.where(id:key[2]).pluck(:survey_item_id), SurveyItem.where(id:key[2]).pluck(:prompt), value[:count], value[:percentage_diff]]
|
||||
end
|
||||
|
||||
file = File.new('short_survey_questions.csv', 'w')
|
||||
CSV.open(file, 'w', write_headers: true, headers: headers) do |csv|
|
||||
output_rows.each do |row|
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
|
||||
file.close
|
||||
puts "CSV report of short survey item responses with removed stray responses.csv"
|
||||
end
|
||||
|
||||
|
||||
desc "Generate CSV report of early_education_surveysitem responses"
|
||||
task early_education_survey_questions_csv: :environment do
|
||||
headers = ['School ID', 'Academic Year', 'Survey Item', 'Count','Percentage_diff']
|
||||
output_rows = []
|
||||
counts={}
|
||||
avg=0
|
||||
temp=0
|
||||
count_response_grades_not_in_grades=0
|
||||
School.all.each do |sc|
|
||||
if Respondent.where(school: sc).any?
|
||||
grades_count=Respondent.where(school:sc).first.counts_by_grade
|
||||
grades= grades_count.keys
|
||||
AcademicYear.all.each do |ay|
|
||||
sum=0
|
||||
nof_si=0
|
||||
threshold=0
|
||||
threshold = Respondent.where(school: sc, academic_year: ay).pluck(:total_students)
|
||||
SurveyItem.early_education_surveys.all.each do |si|
|
||||
c = SurveyItemResponse.where(school: sc, academic_year: ay, survey_item: si).group(:school_id).count
|
||||
response_grades = SurveyItemResponse.where(school: sc, academic_year: ay, survey_item: si).pluck(:grade)
|
||||
count_response_grades_not_in_grades = response_grades.count { |grade| !grades.include?(grade) }
|
||||
if !count_response_grades_not_in_grades.nil? && c.any?
|
||||
c[c.keys.first] = c.values.first - count_response_grades_not_in_grades
|
||||
end
|
||||
|
||||
if threshold.any?
|
||||
if c.any? && (c.values.first >= 10 || c.values.first > threshold.first/4)
|
||||
counts[[sc.id, ay.id, si.id]] = c
|
||||
sum+=c.values.first
|
||||
nof_si+=1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
avg = sum.to_f/ nof_si
|
||||
counts.each do |key, value|
|
||||
if key[0] == sc.id && key[1] == ay.id
|
||||
count = value.values.first
|
||||
percentage_diff = ((count-avg) / avg) * 100
|
||||
counts[key] = { count: count, percentage_diff: percentage_diff }
|
||||
end
|
||||
end
|
||||
end end end
|
||||
|
||||
counts.each do |key, value|
|
||||
output_rows << [School.where(id:key[0]).pluck(:name) , AcademicYear.where(id:key[1]).pluck(:range) , SurveyItem.where(id:key[2]).pluck(:survey_item_id), SurveyItem.where(id:key[2]).pluck(:prompt), value[:count], value[:percentage_diff]]
|
||||
end
|
||||
|
||||
file = File.new('early_education_surveys_questions.csv', 'w')
|
||||
CSV.open(file, 'w', write_headers: true, headers: headers) do |csv|
|
||||
output_rows.each do |row|
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
|
||||
file.close
|
||||
puts "CSV report of early_education_surveys items with removed stray responses.csv"
|
||||
end
|
||||
|
||||
|
||||
desc "Generate CSV report of survey item responses"
|
||||
task stray_responses: :environment do
|
||||
|
||||
headers = ['School ID', 'Academic Year', 'Survey Item', 'Count','SurveyItemResponse ids']
|
||||
|
||||
|
||||
output_rows = []
|
||||
sir_ids=[]
|
||||
|
||||
|
||||
School.all.each do |sc|
|
||||
AcademicYear.all.each do |ay|
|
||||
SurveyItem.all.each do |si|
|
||||
count = SurveyItemResponse.where(school: sc, academic_year: ay, survey_item: si).count
|
||||
sir_ids= SurveyItemResponse.where(school: sc, academic_year: ay, survey_item: si).pluck(:response_id)
|
||||
|
||||
if count > 0 && count < 10
|
||||
|
||||
output_rows << [sc.name, ay.range, si.survey_item_id, count,sir_ids]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
file = File.new('stray_responses.csv', 'w')
|
||||
|
||||
CSV.open(file, 'w', write_headers: true, headers: headers) do |csv|
|
||||
output_rows.each do |row|
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
file.close
|
||||
|
||||
puts "CSV report of survey item responses created in stray_responses.csv"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue