Skip to content

Commit

Permalink
Merge pull request #35192 from code-dot-org/afe-school-stats-logic
Browse files Browse the repository at this point in the history
AFE eligibility logic
  • Loading branch information
bencodeorg committed Jun 8, 2020
2 parents 6775850 + 10f6117 commit 324ff53
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 7 deletions.
20 changes: 19 additions & 1 deletion dashboard/app/models/school.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,37 @@ def full_address
end.compact.join(' ')
end

def most_recent_school_stats
school_stats_by_year.order(school_year: :desc).first
end

# Determines if this is a high-needs school for the purpose of distributing Maker Toolkit
# discount codes - this is not a definition we apply broadly.
# @return [Boolean] True if high-needs, false otherwise.
def maker_high_needs?
# As of January 2020, "high-needs" is defined as having >= 50% of the student population
# eligible for free-and-reduced lunch programs.
stats = school_stats_by_year.order(school_year: :desc).first
stats = most_recent_school_stats
if stats.nil? || stats.frl_eligible_total.nil? || stats.students_total.nil?
return false
end
stats.frl_eligible_total.to_f / stats.students_total.to_f >= 0.5
end

# Determines if school meets Amazon Fugure Engineer criteria.
# Eligible if the school is any of the following:
# a) title I school,
# b) >40% URM students,
# or c) >40% of students eligible for free and reduced meals.
def afe_high_needs?
stats = most_recent_school_stats
return false if stats.nil?

# To align with maker_high_needs? definition above,
# returning false if we don't have all data for a given school.
stats.title_i_eligible? || (stats.urm_percent || 0) >= 0.4 || (stats.frl_eligible_percent || 0) >= 0.4
end

# Public school ids from NCES are always 12 digits, possibly with
# leading zeros. In the DB, those leading zeros have been stripped out.
# Other school types are less than 12 characters and in the DB they
Expand Down
12 changes: 12 additions & 0 deletions dashboard/app/models/school_stats_by_year.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ def rural_school?
include? community_type
end

# Title I status can be values 1-6, M, or nil.
# Values 1-5 are Title I eligible,
# 6 is ineligible, M=Missing, and nil are unknown.
# See description under TITLEISTAT here:
# https://nces.ed.gov/ccd/Data/txt/sc131alay.txt
def title_i_eligible?
return nil unless title_i_status
return nil if title_i_status == 'M'

%w(1 2 3 4 5).include? title_i_status
end

# returns what percent "count" is of the total student enrollment
def percent_of_students(count)
return nil unless count && students_total
Expand Down
89 changes: 83 additions & 6 deletions dashboard/test/models/school_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class SchoolTest < ActiveSupport::TestCase
refute school.valid?
end

test 'high needs false when no stats data' do
test 'maker high needs false when no stats data' do
school = create :school
refute school.maker_high_needs?
end

test 'high needs false when null students total' do
test 'maker high needs false when null students total' do
school = create :school
school.school_stats_by_year << SchoolStatsByYear.new(
{
Expand All @@ -49,7 +49,7 @@ class SchoolTest < ActiveSupport::TestCase
refute school.maker_high_needs?
end

test 'high needs false when null frl eligible total' do
test 'maker high needs false when null frl eligible total' do
school = create :school
school.school_stats_by_year << SchoolStatsByYear.new(
{
Expand All @@ -62,7 +62,7 @@ class SchoolTest < ActiveSupport::TestCase
refute school.maker_high_needs?
end

test 'high needs false when frl eligible below 50 percent of students' do
test 'maker high needs false when frl eligible below 50 percent of students' do
school = create :school
school.school_stats_by_year << SchoolStatsByYear.new(
{
Expand All @@ -76,7 +76,7 @@ class SchoolTest < ActiveSupport::TestCase
refute school.maker_high_needs?
end

test 'high needs true when frl eligible equal to 50 percent of students' do
test 'maker high needs true when frl eligible equal to 50 percent of students' do
school = create :school
school.school_stats_by_year << SchoolStatsByYear.new(
{
Expand All @@ -90,7 +90,7 @@ class SchoolTest < ActiveSupport::TestCase
assert school.maker_high_needs?
end

test 'high needs true when frl eligible above 50 percent of students' do
test 'maker high needs true when frl eligible above 50 percent of students' do
school = create :school
school.school_stats_by_year << SchoolStatsByYear.new(
{
Expand All @@ -104,6 +104,83 @@ class SchoolTest < ActiveSupport::TestCase
assert school.maker_high_needs?
end

test 'AFE high needs false when no stats data' do
school = create :school
refute school.afe_high_needs?
end

test 'AFE high needs false when null students total' do
school = create :school
school.school_stats_by_year << SchoolStatsByYear.new(
{
school_id: school.id,
school_year: '1998-1999'
}
)
school.save!
refute school.afe_high_needs?
end

test 'AFE high needs true when frl eligible above 40 percent of students' do
school = create :school
school.school_stats_by_year << SchoolStatsByYear.new(
{
school_id: school.id,
school_year: '1998-1999',
students_total: 1000,
frl_eligible_total: 401
}
)
school.save!
assert school.afe_high_needs?
end

test 'AFE high needs true when urm percent above 40 percent of students' do
school = create :school
school.school_stats_by_year << SchoolStatsByYear.new(
{
school_id: school.id,
school_year: '1998-1999',
students_total: 4,
student_bl_count: 2
}
)
school.save!
assert school.afe_high_needs?
end

test 'AFE high needs true when title_i_status is yes' do
school = create :school
school.school_stats_by_year << SchoolStatsByYear.new(
{
school_id: school.id,
school_year: '1998-1999',
title_i_status: '5'
}
)
school.save!
assert school.afe_high_needs?
end

test 'AFE high needs false when no criteria are met' do
school = create :school
school.school_stats_by_year << SchoolStatsByYear.new(
{
school_id: school.id,
school_year: '1998-1999',
students_total: 5,
student_bl_count: 0,
student_am_count: 0,
student_hi_count: 0,
student_hp_count: 0,
frl_eligible_total: 0,
title_i_status: '6'
}
)
school.save!
refute school.afe_high_needs?
end

test 'urm school stats missing counts' do
school = create :school
stats_by_year =
Expand Down

0 comments on commit 324ff53

Please sign in to comment.