@ -16,12 +16,12 @@ module Report
# Convert they keys in this hash to a hash where the key is the grade
# Convert they keys in this hash to a hash where the key is the grade
# and the value is a set of sufficient survey IDs
# and the value is a set of sufficient survey IDs
survey_ids_to_grades = { }
survey_ids_to_grades = { }
:: SurveyItemResponse . student_survey_items_with_responses_by_grade (
school : schools ,
sufficient_responses_by_grade_and_survey_item_id = :: SurveyItemResponse . where ( school : schools , academic_year : academic_years , survey_item_id : use_student_survey_items ) . where . not ( grade : nil ) . having ( " count(*) >= ? " , 10 ) . group (
academic_year: academic_years
:grade, :survey_item_id
) . select do | key , _value |
) . count
use_student_survey_items . include? ( key [ 1 ] )
en d. each do | key , count |
sufficient_responses_by_grade_and_survey_item_i d. each do | key , count |
# key[1] is survey item ID
# key[1] is survey item ID
# key[0] is grade
# key[0] is grade
survey_ids_to_grades [ key [ 1 ] ] || = Set . new
survey_ids_to_grades [ key [ 1 ] ] || = Set . new
@ -39,13 +39,14 @@ module Report
" Academic Year "
" Academic Year "
]
]
grades = :: SurveyItemResponse . where ( school : schools ,
grades = [ ]
academic_year : academic_years )
schools . each do | school |
. where . not ( grade : nil )
academic_years . each do | academic_year |
. pluck ( :grade )
grades . concat ( school . grades ( academic_year : ) )
. reject { | grade | grade == - 1 } # ignore preschool
end
. uniq
end
. sort
grades = grades . uniq . reject { | grade | grade == - 1 } . reject ( & :nil? ) # remove preschool and nil grades
grades . each do | value |
grades . each do | value |
if value == 0
if value == 0
headers . append ( " Kindergarten " )
headers . append ( " Kindergarten " )
@ -62,7 +63,7 @@ module Report
academic_years . each do | academic_year |
academic_years . each do | academic_year |
schools . each do | school |
schools . each do | school |
# for each survey item id
# for each survey item id
survey_ids_to_grades . each do | id , school_grades |
survey_ids_to_grades . sort_by { | id , _value | :: SurveyItem . find ( id ) . prompt } . each do | id , school_grades |
school_grades = school_grades . reject ( & :nil? )
school_grades = school_grades . reject ( & :nil? )
row = [ ]
row = [ ]
survey_item = survey_item_for_id ( id )
survey_item = survey_item_for_id ( id )
@ -112,7 +113,11 @@ module Report
data << row
data << row
end
end
# Next up is teacher data
# Next up is teacher data
:: SurveyItemResponse . teacher_survey_items_with_sufficient_responses ( school : , academic_year : ) . keys . each do | key | # each key is a survey item id
# each key is a survey item id
:: SurveyItemResponse . teacher_survey_items_with_sufficient_responses ( school : ,
academic_year : ) . keys . sort_by do | id |
:: SurveyItem . find ( id ) . prompt
end . each do | key |
row = [ ]
row = [ ]
survey_item = survey_item_for_id ( key )
survey_item = survey_item_for_id ( key )
row . concat ( survey_item_info ( survey_item : ) )
row . concat ( survey_item_info ( survey_item : ) )