mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 13:38:18 -08:00
WIP: bubble up averages for language calculations. Make sure n-size only counts responses for a given measure. Update tests
This commit is contained in:
parent
6b2d51c331
commit
3eda7beb59
7 changed files with 37 additions and 29 deletions
|
|
@ -9,7 +9,7 @@ class Language < ApplicationRecord
|
|||
return "Unknown" if language.blank?
|
||||
|
||||
case language
|
||||
in /^1$|^1[^0]/i
|
||||
in /^1$/i
|
||||
"English"
|
||||
in /^2$/i
|
||||
"Portuguese"
|
||||
|
|
|
|||
|
|
@ -51,6 +51,10 @@ class Measure < ActiveRecord::Base
|
|||
@student_scales ||= scales.student_scales
|
||||
end
|
||||
|
||||
def parent_scales
|
||||
@parent_scales ||= scales.parent_scales
|
||||
end
|
||||
|
||||
def includes_teacher_survey_items?
|
||||
@includes_teacher_survey_items ||= teacher_survey_items.length.positive?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -51,14 +51,10 @@ class SurveyItemResponse < ActiveRecord::Base
|
|||
).where("student_races.race_id": race.id).group(:survey_item).having("count(*) >= 10").average(:likert_score)
|
||||
}
|
||||
|
||||
scope :averages_for_language, lambda { |survey_items, school, academic_year, language|
|
||||
# SurveyItemResponse.where(survey_item: survey_items, school:,
|
||||
# academic_year:, language:, grade: school.grades(academic_year:)).group(:survey_item).having("count(*) >= 10").average(:likert_score)
|
||||
#
|
||||
#
|
||||
# Parent.joins(:languages).where(languages: {designation: "Spanish"})
|
||||
# SurveyItemResponse.joins([parent: :languages]).where(languages: {designation: "English"}).first
|
||||
scope :averages_for_language, lambda { |survey_items, school, academic_year, designations|
|
||||
SurveyItemResponse.joins([parent: :languages]).where(languages: { designation: designations }, survey_item: survey_items, school:, academic_year:).group(:survey_item).average(:likert_score)
|
||||
}
|
||||
|
||||
def self.grouped_responses(school:, academic_year:)
|
||||
@grouped_responses ||= Hash.new do |memo, (school, academic_year)|
|
||||
memo[[school, academic_year]] =
|
||||
|
|
|
|||
|
|
@ -28,12 +28,13 @@ module Analyze
|
|||
end
|
||||
|
||||
def n_size(measure:, school:, academic_year:)
|
||||
SurveyItemResponse.joins([parent: :languages]).where(languages: { designation: designations }, school:, academic_year:).select(:parent_id).distinct.count
|
||||
SurveyItemResponse.joins([parent: :languages]).where(languages: { designation: designations }, survey_item: measure.parent_survey_items, school:, academic_year:).select(:parent_id).distinct.count
|
||||
end
|
||||
|
||||
def score(measure:, school:, academic_year:)
|
||||
average = SurveyItemResponse.joins([parent: :languages]).where(languages: { designation: designations }, school:, academic_year:).average(:likert_score)
|
||||
|
||||
averages = SurveyItemResponse.averages_for_language(measure.parent_survey_items, school, academic_year,
|
||||
designations)
|
||||
average = bubble_up_averages(measure:, averages:).round(2)
|
||||
Score.new(average:,
|
||||
meets_teacher_threshold: false,
|
||||
meets_student_threshold: true,
|
||||
|
|
@ -43,6 +44,14 @@ module Analyze
|
|||
def designations
|
||||
language.map(&:designation)
|
||||
end
|
||||
|
||||
def bubble_up_averages(measure:, averages:)
|
||||
measure.parent_scales.map do |scale|
|
||||
scale.survey_items.map do |survey_item|
|
||||
averages[survey_item]
|
||||
end.remove_blanks.average
|
||||
end.remove_blanks.average
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -98,8 +98,8 @@ module Analyze
|
|||
def groups
|
||||
@groups ||=
|
||||
begin
|
||||
selectable_groups = graph.class.name.demodulize.first(4)
|
||||
graphs.select { |graph| graph.class.name.demodulize.first(4) == selectable_groups }.map(&:group)
|
||||
first_char_of_class_name = graph.class.name.demodulize.first
|
||||
graphs.select { |graph| graph.class.name.demodulize.first == first_char_of_class_name }.map(&:group)
|
||||
.reject { |group| group.name.nil? }
|
||||
.sort_by { |group| group.name }
|
||||
.uniq
|
||||
|
|
|
|||
10
spec/fixtures/demographic_glossary.csv
vendored
10
spec/fixtures/demographic_glossary.csv
vendored
|
|
@ -1,10 +1,10 @@
|
|||
ELL Value,ELL Type,ELL Headers,Sped Value,Sped Type,Sped Headers,Income Value,Income Type,Income Headers,Language Value,Language Type
|
||||
EL student not 1st year,ELL,EL Student First Year,A,Special Education,Special Ed Status,Free Lunch,Economically Disadvantaged – Y,Low Income,1,English
|
||||
"EL student, not 1st year",ELL,Raw ELL,active,Special Education,Raw SPED,Reduced Lunch,Economically Disadvantaged – Y,Raw Income,10,English
|
||||
EL student 1st year,ELL,ELL- SIS,1,Special Education,SPED- SIS,LowIncome,Economically Disadvantaged – Y,SES- SIS,2,Portuguese
|
||||
"EL student, 1st year",ELL,DirectCert,Special Education,Special Education,SPED,Low Income,Economically Disadvantaged – Y,EconDisadvantaged,3,Spanish
|
||||
EL - Early Child. or PK,ELL,ELL,Referred,Not Special Education,,Reduced price lunch,Economically Disadvantaged – Y,Income SIS,99,Unknown
|
||||
1,ELL,English Learner,Ineligible,Not Special Education,,TRUE,Economically Disadvantaged – Y,SES ,100,Unknown
|
||||
"EL student, not 1st year",ELL,Raw ELL,active,Special Education,Raw SPED,Reduced Lunch,Economically Disadvantaged – Y,Raw Income,2,Portuguese
|
||||
EL student 1st year,ELL,ELL- SIS,1,Special Education,SPED- SIS,LowIncome,Economically Disadvantaged – Y,SES- SIS,3,Spanish
|
||||
"EL student, 1st year",ELL,DirectCert,Special Education,Special Education,SPED,Low Income,Economically Disadvantaged – Y,EconDisadvantaged,99,Prefer not to disclose
|
||||
EL - Early Child. or PK,ELL,ELL,Referred,Not Special Education,,Reduced price lunch,Economically Disadvantaged – Y,Income SIS,100,Prefer to self-describe
|
||||
1,ELL,English Learner,Ineligible,Not Special Education,,TRUE,Economically Disadvantaged – Y,SES ,,
|
||||
lep student 1st year,ELL,ELL Status- SIS,I,Not Special Education,,1,Economically Disadvantaged – Y,DirectCert,,
|
||||
lep student not 1st year,ELL,,exited,Not Special Education,,Not Eligible,Economically Disadvantaged – N,,,
|
||||
LEP Not1stYr,ELL,,0,Not Special Education,,FALSE,Economically Disadvantaged – N,,,
|
||||
|
|
|
|||
|
|
|
@ -366,38 +366,37 @@ describe Analyze::Presenter do
|
|||
|
||||
context ".group" do
|
||||
context "when no parameters are provided" do
|
||||
it "returns the first item in the list of groups" do
|
||||
params = {}
|
||||
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
|
||||
expect(presenter.group.slug).to eq presenter.groups.first.slug
|
||||
it "returns no groups when no params are defined" do
|
||||
presenter = Analyze::Presenter.new(params: {}, school:, academic_year:)
|
||||
expect(presenter.groups).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
context "when a group is provided in the params hash" do
|
||||
it "returns the group with the given slug" do
|
||||
params = { group: "gender" }
|
||||
params = { group: "gender", graph: "students-by-gender" }
|
||||
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
|
||||
expect(presenter.group.slug).to eq "gender"
|
||||
|
||||
params = { group: "grade" }
|
||||
params = { group: "grade", graph: "students-by-grade" }
|
||||
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
|
||||
expect(presenter.group.slug).to eq "grade"
|
||||
|
||||
params = { group: "race" }
|
||||
params = { group: "race", graph: "students-by-race" }
|
||||
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
|
||||
expect(presenter.group.slug).to eq "race"
|
||||
|
||||
params = { group: "income" }
|
||||
params = { group: "income", graph: "students-by-income" }
|
||||
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
|
||||
expect(presenter.group.slug).to eq "income"
|
||||
end
|
||||
end
|
||||
|
||||
context "when a parameter that does not match a group is provided" do
|
||||
it "returns the first item in the list of groups" do
|
||||
params = { group: "invalid group" }
|
||||
it "returns nil when invalid parameters are given" do
|
||||
params = { group: "invalid group", graph: "invalid graph" }
|
||||
presenter = Analyze::Presenter.new(params:, school:, academic_year:)
|
||||
expect(presenter.group.slug).to eq presenter.groups.first.slug
|
||||
expect(presenter.group).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue