Add Overall Response Rate

pull/2/head
rebuilt 3 years ago
parent bb6d31ecf1
commit a785c69c44

@ -89,6 +89,26 @@
width: 20px;
}
.overall-response-rate-row {
width: 55%;
display: flex;
flex-direction: row;
justify-content: space-between;
margin-top: -23px;
}
.overall-response-rate-container {
padding: 0.4em 0.7em;
width: 48%;
display: flex;
justify-content: space-between;
align-items: center;
color: $gray-1;
@extend .bg-color-gray-3;
@extend .border-radius-8;
@extend .font-size-14
}
@media only screen and (min-width: 768px){
.measure-row-label {
width: 170px;

@ -7,6 +7,10 @@ class OverviewController < SqmApplicationController
def index
@variance_chart_row_presenters = measures.map(&method(:presenter_for_measure))
@category_presenters = Category.sorted.map { |category| CategoryPresenter.new(category:) }
@student_response_rate_presenter = ResponseRatePresenter.new(focus: :student, school: @school,
academic_year: @academic_year)
@teacher_response_rate_presenter = ResponseRatePresenter.new(focus: :teacher, school: @school,
academic_year: @academic_year)
end
private

@ -0,0 +1,45 @@
class ResponseRatePresenter
attr_reader :focus, :academic_year, :school, :survey_items
def initialize(focus:, academic_year:, school:)
@focus = focus
@academic_year = academic_year
@school = school
@survey_items = SurveyItem.student_survey_items if focus == :student
@survey_items = SurveyItem.teacher_survey_items if focus == :teacher
end
def date
SurveyItemResponse.where(survey_item: survey_items, school:).order(updated_at: :DESC).first&.updated_at || Date.new
end
def percentage
cap_at_100(actual_count.to_f / respondents_count.to_f * 100).round
end
def color
# Problem: the color (either $gold or $purple) is determined by the scss variable, but the
# percentage is decided by the presenter. Therefore the class style must be generated
# within this file and not the scss file.
# TODO: Fix this.
percentage > 75 ? "#49416D" : "#FFC857"
end
private
def cap_at_100(value)
value > 100 ? 100 : value
end
def actual_count
SurveyItemResponse.where(school:, academic_year:,
survey_item: survey_items).select(:response_id).distinct.count
end
def respondents_count
respondents = Respondent.find_by(school:, academic_year:)
count = respondents.total_students if focus == :student
count = respondents.total_teachers if focus == :teacher
count
end
end

@ -68,7 +68,7 @@ class SurveyResponsesDataLoader
likert_score = row.likert_score(survey_item_id: survey_item.survey_item_id) || next
unless likert_score.valid_likert_score?
puts "Response ID: #{row.response_id}, Likert score: #{likert_score} rejected" unless likert_score == 'NA'
puts "Response ID: #{row.response_id}, Likert score: #{likert_score} rejected" unless likert_score == "NA"
next
end
response = row.survey_item_response(survey_item:)
@ -96,7 +96,7 @@ class SurveyResponsesDataLoader
def self.get_survey_item_ids_from_headers(headers:)
CSV.parse(headers).first
.filter(&:present?)
.filter { |header| header.start_with? 't-', 's-' }
.filter { |header| header.start_with? "t-", "s-" }
end
private_class_method :process_row

@ -0,0 +1,8 @@
<div class="overall-response-rate-container">
<div>Response Rates as of <%= response_rate_presenter.date.to_date.strftime("%m/%d/%y") %> </div>
<div style="display: flex; justify-content:space-between; width: 100px;">
<div><%= response_rate_presenter.focus.capitalize %> </div>
<%= render partial: "response_rate_graphic", locals: {response_rate_presenter: response_rate_presenter}, cached: true %>
<div><%= response_rate_presenter.percentage %>% </div>
</div>
</div>

@ -0,0 +1,35 @@
<style>
/*
For some reason, none of the sizing in the pie class works, and it always
fills 100% of the containing frame, so the size has to be dictated by .prog
*/
.prog {
width: 16px;
height: 16px;
position: relative;
border: 1px solid black;
border-radius: 50%;
margin-top: 0.2em;
}
.pie {
aspect-ratio: 1;
display: inline-grid;
place-content: center;
margin: 5px;
font-size: 25px;
font-weight: bold;
font-family: sans-serif;
}
#response-rate-pie-<%= response_rate_presenter.focus %>:before{
content: "";
position: absolute;
border-radius: 50%;
inset: 0;
background: conic-gradient(<%= response_rate_presenter.color %> calc(<%= response_rate_presenter.percentage %>*1%),#0000 0);
}
</style>
<div class="prog">
<div id="response-rate-pie-<%= response_rate_presenter.focus %>" class="pie"></div>
</div>

@ -81,6 +81,12 @@
</div>
</div>
<%= render partial: "quality_framework_indicators", locals: { category_presenters: @category_presenters }, cached: true %>
<div class="overall-response-rate-row">
<%= render partial: "response_rate", locals: {response_rate_presenter: @student_response_rate_presenter}, cached: true %>
<%= render partial: "response_rate", locals: {response_rate_presenter: @teacher_response_rate_presenter}, cached: true %>
</div>
</div>
<div class="card">
<h2 class="sub-header-2 mb-4">Distance From Benchmark</h2>

@ -6,4 +6,3 @@ Start Date,End Date,Response Type,IP Address,Progress,Duration (in seconds),Fini
2021-03-31 9:51:39,2021-03-31 10:01:36,0,73.47.153.77,100,596,1,2021-03-31T10:01:36,student_survey_response_5,567890,,,,,42.65820313,-71.30580139,anonymous,EN,3,2,1500505,6,15,109,3710,7,1,,2,2,2,,,,,,,,,,3,3,4,3,3,3,3,4,3,4,3,4,4,5,4,3,4,3,5,2,2,3,,,,,,,,,,,,1,,2,5,1,3,3,2,4,3,5,4,,,,,,,,,,,,5,4,3,4,4,4,4,4,4,,,,,,,2,,2,,EN,,,Social Studies teacher,,"1,2,3,4,5,8,6,7",888,7,4,Free Lunch,Economically Disadvantaged Y
2021-03-31 9:51:39,2021-03-31 10:01:36,0,73.47.153.77,100,596,1,2021-03-31T10:01:36,student_survey_response_6,,,,,,42.65820313,-71.30580139,anonymous,EN,3,2,1500505,6,15,109,3710,7,1,,2,2,2,,,,,,,,,,3,3,4,3,3,3,3,4,3,4,3,4,4,5,4,3,4,3,5,2,2,3,,,,,,,,,,,,1,,2,5,1,3,3,2,4,3,5,4,,,,,,,,,,,,5,4,3,4,4,4,4,4,4,,,,,,,2,,2,,EN,,,Social Studies teacher,,"1,2,3,4,5,8",888,3,NA,Not Eligible,Economically Disadvantaged N
2021-03-31 9:51:39,2021-03-31 10:01:36,0,73.47.153.77,100,596,1,2021-03-31T10:01:36,student_survey_response_7,,,,,,42.65820313,-71.30580139,anonymous,EN,3,2,1500505,6,15,109,3710,7,1,,2,2,2,,,,,,,,,,3,3,4,3,3,3,3,4,3,4,3,4,4,5,4,3,4,3,5,2,2,3,,,,,,,,,,,,1,,2,5,1,3,3,2,4,3,5,4,,,,,,,,,,,,5,4,3,4,4,4,4,4,4,,,,,,,2,,2,,EN,,,Social Studies teacher,,,,4,,Reduced Lunch,Economically Disadvantaged Y
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"1,2,3,4,5,8",,,,,

1 Start Date End Date Response Type IP Address Progress Duration (in seconds) Finished RecordedDate ResponseId LASID Recipient Last Name Recipient First Name Recipient Email External Data Reference Location Latitude Location Longitude Distribution Channel User Language district school DESE ID #N/A #N/A #N/A #N/A #N/A #N/A #N/A s-emsa-q1 s-emsa-q2 s-emsa-q3 s-tint-q1 s-tint-q2 #N/A s-tint-q4 s-tint-q5 s-acpr-q1 s-acpr-q2 s-acpr-q3 s-acpr-q4 #N/A #N/A s-cure-q3 s-cure-q4 #N/A s-sten-q2 s-sten-q3 s-sper-q1 s-sper-q2 s-sper-q3 s-sper-q4 s-civp-q1 s-civp-q2 s-civp-q3 s-civp-q4 s-grmi-q1 #N/A #N/A s-grmi-q4 s-appa-q1 s-appa-q2 #N/A s-peff-q1 s-peff-q2 s-peff-q3 s-peff-q4 s-peff-q5 s-peff-q6 s-sbel-q1 s-sbel-q2 s-sbel-q3 s-sbel-q4 s-sbel-q5 s-phys-q1 s-phys-q1-1 s-phys-q2 s-phys-q3 s-phys-q4 s-vale-q1 s-vale-q2 s-vale-q3 s-vale-q4 s-acst-q1 s-acst-q2 s-acst-q3 s-acst-q4 s-acst-q5 s-grit-q1 s-grit-q2 s-grit-q3 s-grit-q4 #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A race What is your race/ethnicity?(Please select all that apply) - Selected Choice grade gender Raw Income Income
6 2021-03-31 9:51:39 2021-03-31 10:01:36 0 73.47.153.77 100 596 1 2021-03-31T10:01:36 student_survey_response_5 567890 42.65820313 -71.30580139 anonymous EN 3 2 1500505 6 15 109 3710 7 1 2 2 2 3 3 4 3 3 3 3 4 3 4 3 4 4 5 4 3 4 3 5 2 2 3 1 2 5 1 3 3 2 4 3 5 4 5 4 3 4 4 4 4 4 4 2 2 EN Social Studies teacher 1,2,3,4,5,8,6,7 888 7 4 Free Lunch Economically Disadvantaged – Y
7 2021-03-31 9:51:39 2021-03-31 10:01:36 0 73.47.153.77 100 596 1 2021-03-31T10:01:36 student_survey_response_6 42.65820313 -71.30580139 anonymous EN 3 2 1500505 6 15 109 3710 7 1 2 2 2 3 3 4 3 3 3 3 4 3 4 3 4 4 5 4 3 4 3 5 2 2 3 1 2 5 1 3 3 2 4 3 5 4 5 4 3 4 4 4 4 4 4 2 2 EN Social Studies teacher 1,2,3,4,5,8 888 3 NA Not Eligible Economically Disadvantaged – N
8 2021-03-31 9:51:39 2021-03-31 10:01:36 0 73.47.153.77 100 596 1 2021-03-31T10:01:36 student_survey_response_7 42.65820313 -71.30580139 anonymous EN 3 2 1500505 6 15 109 3710 7 1 2 2 2 3 3 4 3 3 3 3 4 3 4 3 4 4 5 4 3 4 3 5 2 2 3 1 2 5 1 3 3 2 4 3 5 4 5 4 3 4 4 4 4 4 4 2 2 EN Social Studies teacher 4 Reduced Lunch Economically Disadvantaged – Y
1,2,3,4,5,8

@ -0,0 +1,160 @@
require "rails_helper"
describe ResponseRatePresenter do
let(:academic_year) { create(:academic_year, range: "2022-23") }
let(:school) { create(:school, name: "A school") }
let(:respondents) { create(:respondent, school:, academic_year:, total_students: 40, total_teachers: 40) }
let(:wrong_school) { create(:school, name: "Wrong school") }
let(:wrong_academic_year) { create(:academic_year) }
let(:wrong_respondents) do
create(:respondent, school: wrong_school, academic_year: wrong_academic_year, total_students: 40,
total_teachers: 40)
end
let(:student_survey_item) { create(:student_survey_item) }
let(:teacher_survey_item) { create(:teacher_survey_item) }
let(:oldest_student_survey_response) do
create(:survey_item_response, school:, academic_year:, survey_item: student_survey_item)
end
let(:newest_student_survey_response) do
create(:survey_item_response, school:, academic_year:, survey_item: student_survey_item)
end
let(:oldest_teacher_survey_response) do
create(:survey_item_response, school:, academic_year:, survey_item: teacher_survey_item)
end
let(:newest_teacher_survey_response) do
create(:survey_item_response, school:, academic_year:, survey_item: teacher_survey_item)
end
let(:wrong_student_survey_response) do
create(:survey_item_response, school: wrong_school, academic_year: wrong_academic_year,
survey_item: student_survey_item)
end
let(:wrong_teacher_survey_response) do
create(:survey_item_response, school: wrong_school, academic_year: wrong_academic_year,
survey_item: teacher_survey_item)
end
context ".date" do
context "when focus is student" do
before :each do
oldest_student_survey_response
newest_student_survey_response
wrong_student_survey_response
wrong_teacher_survey_response
end
it "ignores all teacher items and only gets the modified date of the last student item" do
rdate = ResponseRatePresenter.new(focus: :student, academic_year:, school:).date
expect(rdate).to eq(newest_student_survey_response.updated_at)
end
end
context "when focus is teacher" do
before :each do
oldest_teacher_survey_response
newest_teacher_survey_response
wrong_student_survey_response
wrong_teacher_survey_response
end
it "ignores all student responses and only gets the modified date of the last teacher item" do
rdate = ResponseRatePresenter.new(focus: :teacher, academic_year:, school:).date
expect(rdate).to eq(newest_teacher_survey_response.updated_at)
end
end
end
context ".percentage" do
before :each do
respondents
wrong_respondents
end
context "when no survey responses are found for a school" do
it "returns a response rate of 0" do
rdate = ResponseRatePresenter.new(focus: :teacher, academic_year:, school:).percentage
expect(rdate).to eq(0)
end
end
context "when there all possible teacher respondents answered questions" do
before :each do
create_list(:survey_item_response, 40, school:, academic_year:,
survey_item: teacher_survey_item)
end
it "returns a response rate of 100" do
rdate = ResponseRatePresenter.new(focus: :teacher, academic_year:, school:).percentage
expect(rdate).to eq(100)
end
end
context "when more teachers responded than staff the school" do
before :each do
create_list(:survey_item_response, 80, school:, academic_year:,
survey_item: teacher_survey_item)
end
it "returns a response rate of 100" do
rdate = ResponseRatePresenter.new(focus: :teacher, academic_year:, school:).percentage
expect(rdate).to eq(100)
end
end
context "when three quarters of the teachers responded to the survey" do
before :each do
create_list(:survey_item_response, 30, school:, academic_year:,
survey_item: teacher_survey_item)
end
it "returns a response rate of 75" do
rdate = ResponseRatePresenter.new(focus: :teacher, academic_year:, school:).percentage
expect(rdate).to eq(75)
end
end
context "when one quarter of the teachers responded to the survey" do
before :each do
create_list(:survey_item_response, 10, school:, academic_year:,
survey_item: teacher_survey_item)
end
it "returns a response rate of 25" do
rdate = ResponseRatePresenter.new(focus: :teacher, academic_year:, school:).percentage
expect(rdate).to eq(25)
end
end
context "When the percentage is not a round number" do
before :each do
create_list(:survey_item_response, 9, school:, academic_year:,
survey_item: teacher_survey_item)
end
it "its rounded to the nearest integer" do
rdate = ResponseRatePresenter.new(focus: :teacher, academic_year:, school:).percentage
expect(rdate).to eq(23)
end
end
context "when there all possible student respondents answered questions" do
before :each do
create_list(:survey_item_response, 40, school:, academic_year:,
survey_item: student_survey_item)
end
it "returns a response rate of 100" do
rdate = ResponseRatePresenter.new(focus: :student, academic_year:, school:).percentage
expect(rdate).to eq(100)
end
end
context "when half of all students responded" do
before :each do
create_list(:survey_item_response, 20, school:, academic_year:,
survey_item: student_survey_item)
end
it "returns a response rate of 50" do
rdate = ResponseRatePresenter.new(focus: :student, academic_year:, school:).percentage
expect(rdate).to eq(50)
end
end
end
end

@ -1,46 +1,46 @@
require 'rails_helper'
require 'fileutils'
require "rails_helper"
require "fileutils"
RSpec.describe Cleaner do
let(:district) { create(:district, name: 'Maynard Public Schools') }
let(:second_district) { create(:district, name: 'District2') }
let(:district) { create(:district, name: "Maynard Public Schools") }
let(:second_district) { create(:district, name: "District2") }
let(:school) { create(:school, dese_id: 1_740_505, district:) }
let(:second_school) { create(:school, dese_id: 1_740_305, district:) }
let(:third_school) { create(:school, dese_id: 222_222, district: second_district) }
let(:academic_year) { create(:academic_year, range: '2022-23') }
let(:academic_year) { create(:academic_year, range: "2022-23") }
let(:respondents) do
create(:respondent, school:, academic_year:, one: 0, nine: 40, ten: 40, eleven: 40, twelve: 40)
create(:respondent, school: second_school, academic_year:, one: 0, four: 40, five: 40, six: 40, seven: 40,
eight: 40)
end
let(:recorded_date) { '2023-04-01' }
let(:recorded_date) { "2023-04-01" }
let(:input_filepath) do
Rails.root.join('spec', 'fixtures', 'raw')
Rails.root.join("spec", "fixtures", "raw")
end
let(:output_filepath) do
Rails.root.join('tmp', 'spec', 'clean')
Rails.root.join("tmp", "spec", "clean")
end
let(:log_filepath) do
Rails.root.join('tmp', 'spec', 'removed')
Rails.root.join("tmp", "spec", "removed")
end
let(:disaggregation_filepath) do
Rails.root.join('spec', 'fixtures', 'disaggregation')
Rails.root.join("spec", "fixtures", "disaggregation")
end
let(:path_to_sample_disaggregation_file) do
File.open(Rails.root.join('spec', 'fixtures', 'disaggregation', 'sample_maynard_disaggregation_data.csv'))
File.open(Rails.root.join("spec", "fixtures", "disaggregation", "sample_maynard_disaggregation_data.csv"))
end
let(:path_to_sample_raw_file) do
File.open(Rails.root.join('spec', 'fixtures', 'raw', 'sample_maynard_raw_student_survey.csv'))
File.open(Rails.root.join("spec", "fixtures", "raw", "sample_maynard_raw_student_survey.csv"))
end
let(:common_headers) do
['Recorded Date', 'DeseID', 'ResponseID']
["Recorded Date", "Dese ID", "ResponseID"]
end
let(:standard_survey_items) do
@ -58,16 +58,16 @@ RSpec.describe Cleaner do
end
let(:short_form_survey_items) do
([create(:survey_item, survey_item_id: 's-phys-q1', on_short_form: true),
create(:survey_item, survey_item_id: 's-phys-q2', on_short_form: true),
create(:survey_item, survey_item_id: 's-phys-q3',
([create(:survey_item, survey_item_id: "s-phys-q1", on_short_form: true),
create(:survey_item, survey_item_id: "s-phys-q2", on_short_form: true),
create(:survey_item, survey_item_id: "s-phys-q3",
on_short_form: true)].map(&:survey_item_id) << common_headers).flatten
end
let(:early_education_survey_items) do
([create(:survey_item, survey_item_id: 's-emsa-es1'),
create(:survey_item, survey_item_id: 's-emsa-es2'),
create(:survey_item, survey_item_id: 's-emsa-es3')].map(&:survey_item_id) << common_headers).flatten
([create(:survey_item, survey_item_id: "s-emsa-es1"),
create(:survey_item, survey_item_id: "s-emsa-es2"),
create(:survey_item, survey_item_id: "s-emsa-es3")].map(&:survey_item_id) << common_headers).flatten
end
let(:teacher_survey_items) do
@ -97,20 +97,20 @@ RSpec.describe Cleaner do
respondents
end
context 'Creating a new Cleaner' do
it 'creates a directory for the clean data' do
context "Creating a new Cleaner" do
it "creates a directory for the clean data" do
Cleaner.new(input_filepath:, output_filepath:, log_filepath:, disaggregation_filepath:).clean
expect(output_filepath).to exist
end
it 'creates a directory for the removed data' do
it "creates a directory for the removed data" do
Cleaner.new(input_filepath:, output_filepath:, log_filepath:, disaggregation_filepath:).clean
expect(log_filepath).to exist
end
end
context '.process_raw_file' do
it 'sorts data into valid and invalid csvs' do
context ".process_raw_file" do
it "sorts data into valid and invalid csvs" do
cleaner = Cleaner.new(input_filepath:, output_filepath:, log_filepath:, disaggregation_filepath:)
processed_data = cleaner.process_raw_file(
file: path_to_sample_raw_file, disaggregation_data: cleaner.disaggregation_data
@ -141,85 +141,85 @@ RSpec.describe Cleaner do
invalid_rows_are_rejected_for_the_correct_reasons(data)
end
it 'adds dissaggregation data to the cleaned file ' do
it "adds dissaggregation data to the cleaned file " do
cleaner = Cleaner.new(input_filepath:, output_filepath:, log_filepath:, disaggregation_filepath:)
processed_data = cleaner.process_raw_file(
file: path_to_sample_raw_file, disaggregation_data: cleaner.disaggregation_data
)
processed_data in [headers, clean_csv, log_csv, data]
expect(clean_csv.second.last).to eq 'Economically Disadvantaged - Y'
expect(clean_csv.second.last).to eq "Economically Disadvantaged - Y"
one_thousand = data.find { |row| row.response_id == '1000' }
expect(one_thousand.income).to eq 'Economically Disadvantaged - Y'
one_thousand = data.find { |row| row.response_id == "1000" }
expect(one_thousand.income).to eq "Economically Disadvantaged - Y"
one_thousand_one = data.find { |row| row.response_id == '1001' }
expect(one_thousand_one.income).to eq 'Economically Disadvantaged - N'
one_thousand_one = data.find { |row| row.response_id == "1001" }
expect(one_thousand_one.income).to eq "Economically Disadvantaged - N"
end
end
context '.filename' do
context 'defines a filename in the format: [district].[early_ed/short_form/standard/teacher].[year as 2022-23]' do
context 'when the file is based on standard survey items' do
it 'adds the survey type as standard to the filename' do
context ".filename" do
context "defines a filename in the format: [district].[early_ed/short_form/standard/teacher].[year as 2022-23]" do
context "when the file is based on standard survey items" do
it "adds the survey type as standard to the filename" do
survey_items = SurveyItem.where(survey_item_id: standard_survey_items)
data = [SurveyItemValues.new(row: { 'Recorded Date' => recorded_date, 'Dese ID' => '1_740_505' }, headers: standard_survey_items, genders: nil, survey_items:,
data = [SurveyItemValues.new(row: { "Recorded Date" => recorded_date, "Dese ID" => "1_740_505" }, headers: standard_survey_items, genders: nil, survey_items:,
schools: School.school_hash)]
filename = Cleaner.new(input_filepath:, output_filepath:, log_filepath:, disaggregation_filepath:).filename(
headers: standard_survey_items, data:
)
expect(filename).to eq 'maynard.standard.2022-23.csv'
expect(filename).to eq "maynard.standard.2022-23.csv"
end
context 'when the file is based on short form survey items' do
it 'adds the survey type as short form to the filename' do
context "when the file is based on short form survey items" do
it "adds the survey type as short form to the filename" do
survey_items = SurveyItem.where(survey_item_id: short_form_survey_items)
data = [SurveyItemValues.new(row: { 'Recorded Date' => recorded_date, 'Dese ID' => '1_740_505' }, headers: short_form_survey_items, genders: nil, survey_items:,
data = [SurveyItemValues.new(row: { "Recorded Date" => recorded_date, "Dese ID" => "1_740_505" }, headers: short_form_survey_items, genders: nil, survey_items:,
schools: School.school_hash)]
filename = Cleaner.new(input_filepath:, output_filepath:, log_filepath:, disaggregation_filepath:).filename(
headers: short_form_survey_items, data:
)
expect(filename).to eq 'maynard.short_form.2022-23.csv'
expect(filename).to eq "maynard.short_form.2022-23.csv"
end
end
context 'when the file is based on early education survey items' do
it 'adds the survey type as early education to the filename' do
context "when the file is based on early education survey items" do
it "adds the survey type as early education to the filename" do
survey_items = SurveyItem.where(survey_item_id: early_education_survey_items)
data = [SurveyItemValues.new(row: { 'Recorded Date' => recorded_date, 'Dese ID' => '1_740_505' }, headers: early_education_survey_items, genders: nil, survey_items:,
data = [SurveyItemValues.new(row: { "Recorded Date" => recorded_date, "Dese ID" => "1_740_505" }, headers: early_education_survey_items, genders: nil, survey_items:,
schools: School.school_hash)]
filename = Cleaner.new(input_filepath:, output_filepath:, log_filepath:, disaggregation_filepath:).filename(
headers: early_education_survey_items, data:
)
expect(filename).to eq 'maynard.early_education.2022-23.csv'
expect(filename).to eq "maynard.early_education.2022-23.csv"
end
end
context 'when the file is based on teacher survey items' do
it 'adds the survey type as teacher to the filename' do
context "when the file is based on teacher survey items" do
it "adds the survey type as teacher to the filename" do
survey_items = SurveyItem.where(survey_item_id: teacher_survey_items)
data = [SurveyItemValues.new(row: { 'Recorded Date' => recorded_date, 'Dese ID' => '1_740_505' }, headers: teacher_survey_items, genders: nil, survey_items:,
data = [SurveyItemValues.new(row: { "Recorded Date" => recorded_date, "Dese ID" => "1_740_505" }, headers: teacher_survey_items, genders: nil, survey_items:,
schools: School.school_hash)]
filename = Cleaner.new(input_filepath:, output_filepath:, log_filepath:, disaggregation_filepath:).filename(
headers: teacher_survey_items, data:
)
expect(filename).to eq 'maynard.teacher.2022-23.csv'
expect(filename).to eq "maynard.teacher.2022-23.csv"
end
end
context 'when there is more than one district' do
it 'adds all districts to the filename' do
context "when there is more than one district" do
it "adds all districts to the filename" do
survey_items = SurveyItem.where(survey_item_id: teacher_survey_items)
data = [SurveyItemValues.new(row: { 'Recorded Date' => recorded_date, 'Dese ID' => '1_740_505' }, headers: teacher_survey_items, genders: nil, survey_items:, schools: School.school_hash),
SurveyItemValues.new(row: { 'Recorded Date' => recorded_date, 'Dese ID' => '222_222' },
data = [SurveyItemValues.new(row: { "Recorded Date" => recorded_date, "Dese ID" => "1_740_505" }, headers: teacher_survey_items, genders: nil, survey_items:, schools: School.school_hash),
SurveyItemValues.new(row: { "Recorded Date" => recorded_date, "Dese ID" => "222_222" },
headers: teacher_survey_items, genders: nil, survey_items:, schools: School.school_hash)]
filename = Cleaner.new(input_filepath:, output_filepath:, log_filepath:, disaggregation_filepath:).filename(
headers: teacher_survey_items, data:
)
expect(filename).to eq 'maynard.district2.teacher.2022-23.csv'
expect(filename).to eq "maynard.district2.teacher.2022-23.csv"
end
end
end
@ -229,90 +229,90 @@ end
def reads_headers_from_raw_csv(processed_data)
processed_data in [headers, clean_csv, log_csv, data]
expect(headers).to eq ['StartDate', 'EndDate', 'Status', 'IPAddress', 'Progress', 'Duration (in seconds)',
'Finished', 'RecordedDate', 'ResponseId', 'District', 'School',
'LASID', 'Gender', 'Race', 'What grade are you in?', 's-emsa-q1', 's-emsa-q2', 's-emsa-q3', 's-tint-q1',
's-tint-q2', 's-tint-q3', 's-tint-q4', 's-tint-q5', 's-acpr-q1', 's-acpr-q2',
's-acpr-q3', 's-acpr-q4', 's-cure-q1', 's-cure-q2', 's-cure-q3', 's-cure-q4', 's-sten-q1', 's-sten-q2',
's-sten-q3', 's-sper-q1', 's-sper-q2', 's-sper-q3', 's-sper-q4', 's-civp-q1', 's-civp-q2', 's-civp-q3',
's-civp-q4', 's-grmi-q1', 's-grmi-q2', 's-grmi-q3', 's-grmi-q4', 's-appa-q1', 's-appa-q2', 's-appa-q3',
's-peff-q1', 's-peff-q2', 's-peff-q3', 's-peff-q4', 's-peff-q5', 's-peff-q6', 's-sbel-q1', 's-sbel-q2',
's-sbel-q3', 's-sbel-q4', 's-sbel-q5', 's-phys-q1', 's-phys-q2', 's-phys-q3', 's-phys-q4', 's-vale-q1',
's-vale-q2', 's-vale-q3', 's-vale-q4', 's-acst-q1', 's-acst-q2', 's-acst-q3', 's-sust-q1', 's-sust-q2',
's-grit-q1', 's-grit-q2', 's-grit-q3', 's-grit-q4', 's-expa-q1', 's-poaf-q1', 's-poaf-q2', 's-poaf-q3',
's-poaf-q4', 's-tint-q1-1', 's-tint-q2-1', 's-tint-q3-1', 's-tint-q4-1', 's-tint-q5-1', 's-acpr-q1-1',
's-acpr-q2-1', 's-acpr-q3-1', 's-acpr-q4-1', 's-peff-q1-1', 's-peff-q2-1', 's-peff-q3-1', 's-peff-q4-1',
's-peff-q5-1', 's-peff-q6-1', 'Raw Income', 'Income']
expect(headers).to eq ["StartDate", "EndDate", "Status", "IPAddress", "Progress", "Duration (in seconds)",
"Finished", "RecordedDate", "ResponseId", "District", "School",
"LASID", "Gender", "Race", "What grade are you in?", "s-emsa-q1", "s-emsa-q2", "s-emsa-q3", "s-tint-q1",
"s-tint-q2", "s-tint-q3", "s-tint-q4", "s-tint-q5", "s-acpr-q1", "s-acpr-q2",
"s-acpr-q3", "s-acpr-q4", "s-cure-q1", "s-cure-q2", "s-cure-q3", "s-cure-q4", "s-sten-q1", "s-sten-q2",
"s-sten-q3", "s-sper-q1", "s-sper-q2", "s-sper-q3", "s-sper-q4", "s-civp-q1", "s-civp-q2", "s-civp-q3",
"s-civp-q4", "s-grmi-q1", "s-grmi-q2", "s-grmi-q3", "s-grmi-q4", "s-appa-q1", "s-appa-q2", "s-appa-q3",
"s-peff-q1", "s-peff-q2", "s-peff-q3", "s-peff-q4", "s-peff-q5", "s-peff-q6", "s-sbel-q1", "s-sbel-q2",
"s-sbel-q3", "s-sbel-q4", "s-sbel-q5", "s-phys-q1", "s-phys-q2", "s-phys-q3", "s-phys-q4", "s-vale-q1",
"s-vale-q2", "s-vale-q3", "s-vale-q4", "s-acst-q1", "s-acst-q2", "s-acst-q3", "s-sust-q1", "s-sust-q2",
"s-grit-q1", "s-grit-q2", "s-grit-q3", "s-grit-q4", "s-expa-q1", "s-poaf-q1", "s-poaf-q2", "s-poaf-q3",
"s-poaf-q4", "s-tint-q1-1", "s-tint-q2-1", "s-tint-q3-1", "s-tint-q4-1", "s-tint-q5-1", "s-acpr-q1-1",
"s-acpr-q2-1", "s-acpr-q3-1", "s-acpr-q4-1", "s-peff-q1-1", "s-peff-q2-1", "s-peff-q3-1", "s-peff-q4-1",
"s-peff-q5-1", "s-peff-q6-1", "Raw Income", "Income"]
end
def invalid_rows_are_rejected_for_the_correct_reasons(data)
one_thousand_two = data.find { |row| row.response_id == '1002' }
one_thousand_two = data.find { |row| row.response_id == "1002" }
expect(one_thousand_two.valid_progress?).to eq false
expect(one_thousand_two.valid_duration?).to eq true
expect(one_thousand_two.valid_grade?).to eq true
expect(one_thousand_two.valid_sd?).to eq true
one_thousand_three = data.find { |row| row.response_id == '1003' }
one_thousand_three = data.find { |row| row.response_id == "1003" }
expect(one_thousand_three.valid_progress?).to eq false
expect(one_thousand_three.valid_duration?).to eq true
expect(one_thousand_three.valid_grade?).to eq true
expect(one_thousand_three.valid_sd?).to eq true
one_thousand_six = data.find { |row| row.response_id == '1006' }
one_thousand_six = data.find { |row| row.response_id == "1006" }
expect(one_thousand_six.valid_progress?).to eq true
expect(one_thousand_six.valid_duration?).to eq false
expect(one_thousand_six.valid_grade?).to eq true
expect(one_thousand_six.valid_sd?).to eq true
one_thousand_seven = data.find { |row| row.response_id == '1007' }
one_thousand_seven = data.find { |row| row.response_id == "1007" }
expect(one_thousand_seven.valid_progress?).to eq true
expect(one_thousand_seven.valid_duration?).to eq false
expect(one_thousand_seven.valid_grade?).to eq true
expect(one_thousand_seven.valid_sd?).to eq true
one_thousand_seven = data.find { |row| row.response_id == '1007' }
one_thousand_seven = data.find { |row| row.response_id == "1007" }
expect(one_thousand_seven.valid_progress?).to eq true
expect(one_thousand_seven.valid_duration?).to eq false
expect(one_thousand_seven.valid_grade?).to eq true
expect(one_thousand_seven.valid_sd?).to eq true
one_thousand_nine = data.find { |row| row.response_id == '1009' }
one_thousand_nine = data.find { |row| row.response_id == "1009" }
expect(one_thousand_nine.valid_progress?).to eq true
expect(one_thousand_nine.valid_duration?).to eq true
expect(one_thousand_nine.valid_grade?).to eq false
expect(one_thousand_nine.valid_sd?).to eq true
one_thousand_ten = data.find { |row| row.response_id == '1010' }
one_thousand_ten = data.find { |row| row.response_id == "1010" }
expect(one_thousand_ten.valid_progress?).to eq true
expect(one_thousand_ten.valid_duration?).to eq true
expect(one_thousand_ten.valid_grade?).to eq false
expect(one_thousand_ten.valid_sd?).to eq true
one_thousand_eleven = data.find { |row| row.response_id == '1011' }
one_thousand_eleven = data.find { |row| row.response_id == "1011" }
expect(one_thousand_eleven.valid_progress?).to eq true
expect(one_thousand_eleven.valid_duration?).to eq true
expect(one_thousand_eleven.valid_grade?).to eq false
expect(one_thousand_eleven.valid_sd?).to eq true
one_thousand_twenty_two = data.find { |row| row.response_id == '1022' }
one_thousand_twenty_two = data.find { |row| row.response_id == "1022" }
expect(one_thousand_twenty_two.valid_progress?).to eq true
expect(one_thousand_twenty_two.valid_duration?).to eq true
expect(one_thousand_twenty_two.valid_grade?).to eq false
expect(one_thousand_twenty_two.valid_sd?).to eq true
one_thousand_twenty_three = data.find { |row| row.response_id == '1023' }
one_thousand_twenty_three = data.find { |row| row.response_id == "1023" }
expect(one_thousand_twenty_three.valid_progress?).to eq true
expect(one_thousand_twenty_three.valid_duration?).to eq true
expect(one_thousand_twenty_three.valid_grade?).to eq false
expect(one_thousand_twenty_three.valid_sd?).to eq true
one_thousand_thirty_three = data.find { |row| row.response_id == '1033' }
one_thousand_thirty_three = data.find { |row| row.response_id == "1033" }
expect(one_thousand_thirty_three.valid_progress?).to eq true
expect(one_thousand_thirty_three.valid_duration?).to eq true
expect(one_thousand_thirty_three.valid_grade?).to eq true
expect(one_thousand_thirty_three.valid_sd?).to eq false
one_thousand_thirty_four = data.find { |row| row.response_id == '1034' }
one_thousand_thirty_four = data.find { |row| row.response_id == "1034" }
expect(one_thousand_thirty_four.valid_progress?).to eq true
expect(one_thousand_thirty_four.valid_duration?).to eq true
expect(one_thousand_thirty_four.valid_grade?).to eq true

@ -1,30 +1,30 @@
require 'rails_helper'
require "rails_helper"
RSpec.describe SurveyItemValues, type: :model do
let(:headers) do
['StartDate', 'EndDate', 'Status', 'IPAddress', 'Progress', 'Duration (in seconds)', 'Finished', 'RecordedDate',
'ResponseId', 'RecipientLastName', 'RecipientFirstName', 'RecipientEmail', 'ExternalReference', 'LocationLatitude', 'LocationLongitude', 'DistributionChannel', 'UserLanguage', 'District', 'School- Lee', 'School- Maynard', 'LASID', 'Grade', 's-emsa-q1', 's-emsa-q2', 's-emsa-q3', 's-tint-q1', 's-tint-q2', 's-tint-q3', 's-tint-q4', 's-tint-q5', 's-acpr-q1', 's-acpr-q2', 's-acpr-q3', 's-acpr-q4', 's-cure-q1', 's-cure-q2', 's-cure-q3', 's-cure-q4', 's-sten-q1', 's-sten-q2', 's-sten-q3', 's-sper-q1', 's-sper-q2', 's-sper-q3', 's-sper-q4', 's-civp-q1', 's-civp-q2', 's-civp-q3', 's-civp-q4', 's-grmi-q1', 's-grmi-q2', 's-grmi-q3', 's-grmi-q4', 's-appa-q1', 's-appa-q2', 's-appa-q3', 's-peff-q1', 's-peff-q2', 's-peff-q3', 's-peff-q4', 's-peff-q5', 's-peff-q6', 's-sbel-q1', 's-sbel-q2', 's-sbel-q3', 's-sbel-q4', 's-sbel-q5', 's-phys-q1', 's-phys-q2', 's-phys-q3', 's-phys-q4', 's-vale-q1', 's-vale-q2', 's-vale-q3', 's-vale-q4', 's-acst-q1', 's-acst-q2', 's-acst-q3', 's-sust-q1', 's-sust-q2', 's-grit-q1', 's-grit-q2', 's-grit-q3', 's-grit-q4', 's-expa-q1', 's-poaf-q1', 's-poaf-q2', 's-poaf-q3', 's-poaf-q4', 's-tint-q1-1', 's-tint-q2-1', 's-tint-q3-1', 's-tint-q4-1', 's-tint-q5-1', 's-acpr-q1-1', 's-acpr-q2-1', 's-acpr-q3-1', 's-acpr-q4-1', 's-peff-q1-1', 's-peff-q2-1', 's-peff-q3-1', 's-peff-q4-1', 's-peff-q5-1', 's-peff-q6-1', 'Gender', 'Race']
["StartDate", "EndDate", "Status", "IPAddress", "Progress", "Duration (in seconds)", "Finished", "RecordedDate",
"ResponseId", "RecipientLastName", "RecipientFirstName", "RecipientEmail", "ExternalReference", "LocationLatitude", "LocationLongitude", "DistributionChannel", "UserLanguage", "District", "School- Lee", "School- Maynard", "LASID", "Grade", "s-emsa-q1", "s-emsa-q2", "s-emsa-q3", "s-tint-q1", "s-tint-q2", "s-tint-q3", "s-tint-q4", "s-tint-q5", "s-acpr-q1", "s-acpr-q2", "s-acpr-q3", "s-acpr-q4", "s-cure-q1", "s-cure-q2", "s-cure-q3", "s-cure-q4", "s-sten-q1", "s-sten-q2", "s-sten-q3", "s-sper-q1", "s-sper-q2", "s-sper-q3", "s-sper-q4", "s-civp-q1", "s-civp-q2", "s-civp-q3", "s-civp-q4", "s-grmi-q1", "s-grmi-q2", "s-grmi-q3", "s-grmi-q4", "s-appa-q1", "s-appa-q2", "s-appa-q3", "s-peff-q1", "s-peff-q2", "s-peff-q3", "s-peff-q4", "s-peff-q5", "s-peff-q6", "s-sbel-q1", "s-sbel-q2", "s-sbel-q3", "s-sbel-q4", "s-sbel-q5", "s-phys-q1", "s-phys-q2", "s-phys-q3", "s-phys-q4", "s-vale-q1", "s-vale-q2", "s-vale-q3", "s-vale-q4", "s-acst-q1", "s-acst-q2", "s-acst-q3", "s-sust-q1", "s-sust-q2", "s-grit-q1", "s-grit-q2", "s-grit-q3", "s-grit-q4", "s-expa-q1", "s-poaf-q1", "s-poaf-q2", "s-poaf-q3", "s-poaf-q4", "s-tint-q1-1", "s-tint-q2-1", "s-tint-q3-1", "s-tint-q4-1", "s-tint-q5-1", "s-acpr-q1-1", "s-acpr-q2-1", "s-acpr-q3-1", "s-acpr-q4-1", "s-peff-q1-1", "s-peff-q2-1", "s-peff-q3-1", "s-peff-q4-1", "s-peff-q5-1", "s-peff-q6-1", "Gender", "Race"]
end
let(:genders) do
create(:gender, qualtrics_code: 1)
Gender.gender_hash
end
let(:survey_items) { [] }
let(:district) { create(:district, name: 'Attleboro') }
let(:district) { create(:district, name: "Attleboro") }
let(:attleboro) do
create(:school, name: 'Attleboro', dese_id: 1234, district:)
create(:school, name: "Attleboro", dese_id: 1234, district:)
end
let(:attleboro_respondents) do
create(:respondent, school: attleboro, academic_year: ay_2022_23, nine: 40, ten: 40, eleven: 40, twelve: 40)
end
let(:schools) { School.school_hash }
let(:recorded_date) { '2023-04-01' }
let(:recorded_date) { "2023-04-01" }
let(:ay_2022_23) do
create(:academic_year, range: '2022-23')
create(:academic_year, range: "2022-23")
end
let(:common_headers) do
['Recorded Date', 'DeseID', 'ResponseID', 'Duration (in seconds)', 'Gender', 'Grade']
["Recorded Date", "DeseID", "ResponseID", "Duration (in seconds)", "Gender", "Grade"]
end
let(:standard_survey_items) do
@ -42,9 +42,9 @@ RSpec.describe SurveyItemValues, type: :model do
end
let(:short_form_survey_items) do
survey_item_ids = [create(:survey_item, survey_item_id: 's-phys-q1', on_short_form: true),
create(:survey_item, survey_item_id: 's-phys-q2', on_short_form: true),
create(:survey_item, survey_item_id: 's-phys-q3',
survey_item_ids = [create(:survey_item, survey_item_id: "s-phys-q1", on_short_form: true),
create(:survey_item, survey_item_id: "s-phys-q2", on_short_form: true),
create(:survey_item, survey_item_id: "s-phys-q3",
on_short_form: true)].map(&:survey_item_id)
survey_item_ids.map do |survey_item_id|
create(:survey_item, survey_item_id:)
@ -53,9 +53,9 @@ RSpec.describe SurveyItemValues, type: :model do
end
let(:early_education_survey_items) do
survey_item_ids = [create(:survey_item, survey_item_id: 's-emsa-es1'),
create(:survey_item, survey_item_id: 's-emsa-es2'),
create(:survey_item, survey_item_id: 's-emsa-es3')].map(&:survey_item_id)
survey_item_ids = [create(:survey_item, survey_item_id: "s-emsa-es1"),
create(:survey_item, survey_item_id: "s-emsa-es2"),
create(:survey_item, survey_item_id: "s-emsa-es3")].map(&:survey_item_id)
survey_item_ids.map do |survey_item_id|
create(:survey_item, survey_item_id:)
end
@ -77,49 +77,50 @@ RSpec.describe SurveyItemValues, type: :model do
(survey_item_ids << common_headers).flatten
end
context '.recorded_date' do
it 'returns the recorded date' do
row = { 'RecordedDate' => '2017-01-01' }
context ".recorded_date" do
it "returns the recorded date" do
row = { "RecordedDate" => "2017-01-01" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.recorded_date).to eq Date.parse('2017-01-01')
expect(values.recorded_date).to eq Date.parse("2017-01-01")
headers = ['Recorded Date']
row = { 'Recorded Date' => '2017-01-02' }
headers = ["Recorded Date"]
row = { "Recorded Date" => "2017-01-02" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.recorded_date).to eq Date.parse('2017-01-02')
expect(values.recorded_date).to eq Date.parse("2017-01-02")
end
end
context '.school' do
it 'returns the school that maps to the dese id provided' do
context ".school" do
it "returns the school that maps to the dese id provided" do
attleboro
row = { 'Dese ID' => '1234' }
headers = ["Dese ID"]
row = { "Dese ID" => "1234" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.school).to eq attleboro
row = { 'DeseID' => '1234' }
row = { "DeseID" => "1234" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.school).to eq attleboro
end
end
context '.grade' do
it 'returns the grade that maps to the grade provided' do
row = { 'Grade' => '1' }
context ".grade" do
it "returns the grade that maps to the grade provided" do
row = { "Grade" => "1" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.grade).to eq 1
end
end
context '.gender' do
it 'returns the grade that maps to the grade provided' do
row = { 'Gender' => '1' }
context ".gender" do
it "returns the grade that maps to the grade provided" do
row = { "Gender" => "1" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:)
expect(values.gender.qualtrics_code).to eq 1
end
end
context '.respondent_type' do
it 'reads header to find the survey type' do
context ".respondent_type" do
it "reads header to find the survey type" do
headers = %w[s-sbel-q5 s-phys-q2 RecordedDate]
values = SurveyItemValues.new(row: {}, headers:, genders:, survey_items:, schools:)
expect(values.respondent_type).to eq :student
@ -130,32 +131,32 @@ RSpec.describe SurveyItemValues, type: :model do
end
end
context '.survey_type' do
context 'when survey type is standard form' do
it 'returns the survey type' do
context ".survey_type" do
context "when survey type is standard form" do
it "returns the survey type" do
headers = standard_survey_items
values = SurveyItemValues.new(row: {}, headers:, genders:, survey_items:, schools:)
expect(values.survey_type).to eq :standard
end
end
context 'when survey type is teacher form' do
it 'returns the survey type' do
context "when survey type is teacher form" do
it "returns the survey type" do
headers = teacher_survey_items
values = SurveyItemValues.new(row: {}, headers:, genders:, survey_items:, schools:)
expect(values.survey_type).to eq :teacher
end
end
context 'when survey type is short form' do
it 'returns the survey type' do
context "when survey type is short form" do
it "returns the survey type" do
headers = short_form_survey_items
values = SurveyItemValues.new(row: {}, headers:, genders:, survey_items:, schools:)
expect(values.survey_type).to eq :short_form
end
end
context 'when survey type is early education' do
it 'returns the survey type' do
context "when survey type is early education" do
it "returns the survey type" do
headers = early_education_survey_items
values = SurveyItemValues.new(row: {}, headers:, genders:, survey_items:, schools:)
expect(values.survey_type).to eq :early_education
@ -163,235 +164,235 @@ RSpec.describe SurveyItemValues, type: :model do
end
end
context '.income' do
context 'when no disaggregation data is provided' do
it 'returns an empty string ' do
context ".income" do
context "when no disaggregation data is provided" do
it "returns an empty string " do
disaggregation_data = {}
values = SurveyItemValues.new(row: {}, headers:, genders:, survey_items:, schools:, disaggregation_data:)
expect(values.income).to eq 'Unknown'
expect(values.income).to eq "Unknown"
end
end
context 'when disaggregation data is provided' do
context "when disaggregation data is provided" do
before :each do
attleboro
ay_2022_23
end
it 'translates Free Lunch to Economically Disadvantaged - Y' do
headers = ['District', 'Academic Year', 'LASID', 'LowIncome']
row = { 'District' => 'Attleboro', 'AcademicYear' => '2022-23', 'LASID' => '1', 'LowIncome' => 'Free Lunch' }
it "translates Free Lunch to Economically Disadvantaged - Y" do
headers = ["District", "Academic Year", "LASID", "LowIncome"]
row = { "District" => "Attleboro", "AcademicYear" => "2022-23", "LASID" => "1", "LowIncome" => "Free Lunch" }
disaggregation_data = { %w[1 Attleboro 2022-23] => DisaggregationRow.new(row:, headers:) }
headers = ['LASID', 'Dese Id', 'RecordedDate']
row = { 'LASID' => '1', 'DESE ID' => '1234', 'RecordedDate' => '2023-1-1' }
headers = ["LASID", "Dese Id", "RecordedDate"]
row = { "LASID" => "1", "DESE ID" => "1234", "RecordedDate" => "2023-1-1" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:,
disaggregation_data:)
expect(values.income).to eq 'Economically Disadvantaged - Y'
expect(values.income).to eq "Economically Disadvantaged - Y"
end
it 'translates Reduced Lunch to Economically Disadvantaged - Y' do
headers = ['District', 'Academic Year', 'LASID', 'LowIncome']
row = { 'District' => 'Attleboro', 'AcademicYear' => '2022-23', 'LASID' => '1', 'LowIncome' => 'Reduced Lunch' }
it "translates Reduced Lunch to Economically Disadvantaged - Y" do
headers = ["District", "Academic Year", "LASID", "LowIncome"]
row = { "District" => "Attleboro", "AcademicYear" => "2022-23", "LASID" => "1", "LowIncome" => "Reduced Lunch" }
disaggregation_data = { %w[1 Attleboro 2022-23] => DisaggregationRow.new(row:, headers:) }
headers = ['LASID', 'Dese Id', 'RecordedDate']
row = { 'LASID' => '1', 'DESE ID' => '1234', 'RecordedDate' => '2023-1-1' }
headers = ["LASID", "Dese Id", "RecordedDate"]
row = { "LASID" => "1", "DESE ID" => "1234", "RecordedDate" => "2023-1-1" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:,
disaggregation_data:)
expect(values.income).to eq 'Economically Disadvantaged - Y'
expect(values.income).to eq "Economically Disadvantaged - Y"
end
it 'translates LowIncome to Economically Disadvantaged - Y' do
headers = ['District', 'Academic Year', 'LASID', 'LowIncome']
row = { 'District' => 'Attleboro', 'AcademicYear' => '2022-23', 'LASID' => '1', 'LowIncome' => 'LowIncome' }
it "translates LowIncome to Economically Disadvantaged - Y" do
headers = ["District", "Academic Year", "LASID", "LowIncome"]
row = { "District" => "Attleboro", "AcademicYear" => "2022-23", "LASID" => "1", "LowIncome" => "LowIncome" }
disaggregation_data = { %w[1 Attleboro 2022-23] => DisaggregationRow.new(row:, headers:) }
headers = ['LASID', 'Dese Id', 'RecordedDate']
row = { 'LASID' => '1', 'DESE ID' => '1234', 'RecordedDate' => '2023-1-1' }
headers = ["LASID", "Dese Id", "RecordedDate"]
row = { "LASID" => "1", "DESE ID" => "1234", "RecordedDate" => "2023-1-1" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:,
disaggregation_data:)
expect(values.income).to eq 'Economically Disadvantaged - Y'
expect(values.income).to eq "Economically Disadvantaged - Y"
end
it 'translates Not Eligible to Economically Disadvantaged - N' do
headers = ['District', 'Academic Year', 'LASID', 'LowIncome']
row = { 'District' => 'Attleboro', 'AcademicYear' => '2022-23', 'LASID' => '1', 'LowIncome' => 'Not Eligible' }
it "translates Not Eligible to Economically Disadvantaged - N" do
headers = ["District", "Academic Year", "LASID", "LowIncome"]
row = { "District" => "Attleboro", "AcademicYear" => "2022-23", "LASID" => "1", "LowIncome" => "Not Eligible" }
disaggregation_data = { %w[1 Attleboro 2022-23] => DisaggregationRow.new(row:, headers:) }
headers = ['LASID', 'Dese Id', 'RecordedDate']
row = { 'LASID' => '1', 'DESE ID' => '1234', 'RecordedDate' => '2023-1-1' }
headers = ["LASID", "Dese Id", "RecordedDate"]
row = { "LASID" => "1", "DESE ID" => "1234", "RecordedDate" => "2023-1-1" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:,
disaggregation_data:)
expect(values.income).to eq 'Economically Disadvantaged - N'
expect(values.income).to eq "Economically Disadvantaged - N"
end
it 'translates blanks to Unknown' do
headers = ['District', 'Academic Year', 'LASID', 'LowIncome']
row = { 'District' => 'Attleboro', 'AcademicYear' => '2022-23', 'LASID' => '1', 'LowIncome' => '' }
it "translates blanks to Unknown" do
headers = ["District", "Academic Year", "LASID", "LowIncome"]
row = { "District" => "Attleboro", "AcademicYear" => "2022-23", "LASID" => "1", "LowIncome" => "" }
disaggregation_data = { %w[1 Attleboro 2022-23] => DisaggregationRow.new(row:, headers:) }
headers = ['LASID', 'Dese Id', 'RecordedDate']
row = { 'LASID' => '1', 'DESE ID' => '1234', 'RecordedDate' => '2023-1-1' }
headers = ["LASID", "Dese Id", "RecordedDate"]
row = { "LASID" => "1", "DESE ID" => "1234", "RecordedDate" => "2023-1-1" }
values = SurveyItemValues.new(row:, headers:, genders:, survey_items:, schools:,
disaggregation_data:)
expect(values.income).to eq 'Unknown'
expect(values.income).to eq "Unknown"
end
end
end
context '.valid_duration' do
context 'when duration is valid' do
it 'returns true' do
context ".valid_duration" do
context "when duration is valid" do
it "returns true" do
headers = standard_survey_items
values = SurveyItemValues.new(row: { 'Duration (in seconds)' => '240', 'Gender' => 'Male' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Duration (in seconds)" => "240", "Gender" => "Male" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_duration?).to eq true
headers = teacher_survey_items
values = SurveyItemValues.new(row: { 'Duration (in seconds)' => '300' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Duration (in seconds)" => "300" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_duration?).to eq true
headers = short_form_survey_items
values = SurveyItemValues.new(row: { 'Duration (in seconds)' => '100' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Duration (in seconds)" => "100" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_duration?).to eq true
# When duration is blank or N/A or NA, we don't have enough information to kick out the row as invalid so we keep it in
headers = short_form_survey_items
values = SurveyItemValues.new(row: { 'Duration (in seconds)' => '' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Duration (in seconds)" => "" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_duration?).to eq true
headers = short_form_survey_items
values = SurveyItemValues.new(row: { 'Duration (in seconds)' => 'N/A' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Duration (in seconds)" => "N/A" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_duration?).to eq true
headers = short_form_survey_items
values = SurveyItemValues.new(row: { 'Duration (in seconds)' => 'NA' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Duration (in seconds)" => "NA" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_duration?).to eq true
end
end
context 'when duration is invalid' do
it 'returns false' do
context "when duration is invalid" do
it "returns false" do
headers = standard_survey_items
values = SurveyItemValues.new(row: { 'Duration (in seconds)' => '239' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Duration (in seconds)" => "239" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_duration?).to eq false
headers = teacher_survey_items
values = SurveyItemValues.new(row: { 'Duration (in seconds)' => '299' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Duration (in seconds)" => "299" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_duration?).to eq false
headers = short_form_survey_items
values = SurveyItemValues.new(row: { 'Duration (in seconds)' => '99' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Duration (in seconds)" => "99" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_duration?).to eq false
end
end
end
context '.valid_progress' do
context 'when progress is valid' do
it 'returns true' do
context ".valid_progress" do
context "when progress is valid" do
it "returns true" do
headers = %w[s-sbel-q5 s-phys-q2 RecordedDate]
values = SurveyItemValues.new(row: { 'Progress' => '25' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Progress" => "25" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_progress?).to eq true
# When progress is blank or N/A or NA, we don't have enough information to kick out the row as invalid so we keep it in
headers = %w[s-sbel-q5 s-phys-q2 RecordedDate]
values = SurveyItemValues.new(row: { 'Progress' => '' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Progress" => "" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_progress?).to eq true
headers = %w[s-sbel-q5 s-phys-q2 RecordedDate]
values = SurveyItemValues.new(row: { 'Progress' => 'N/A' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Progress" => "N/A" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_progress?).to eq true
headers = %w[s-sbel-q5 s-phys-q2 RecordedDate]
values = SurveyItemValues.new(row: { 'Progress' => 'NA' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Progress" => "NA" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_progress?).to eq true
end
end
context 'when progress is invalid' do
it 'returns false' do
context "when progress is invalid" do
it "returns false" do
headers = %w[s-sbel-q5 s-phys-q2 RecordedDate]
values = SurveyItemValues.new(row: { 'Progress' => '24' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "Progress" => "24" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_progress?).to eq false
end
end
end
context '.valid_grade?' do
context 'when grade is valid' do
context ".valid_grade?" do
context "when grade is valid" do
before :each do
attleboro
attleboro_respondents
end
it 'returns true for students' do
it "returns true for students" do
headers = %w[s-sbel-q5 s-phys-q2 grade RecordedDate]
values = SurveyItemValues.new(row: { 'grade' => '9', 'RecordedDate' => recorded_date, 'Dese ID' => '1234' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "grade" => "9", "RecordedDate" => recorded_date, "Dese ID" => "1234" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_grade?).to eq true
end
it 'returns true for teachers' do
it "returns true for teachers" do
headers = %w[t-sbel-q5 t-phys-q2 grade RecordedDate]
values = SurveyItemValues.new(row: { 'RecordedDate' => recorded_date, 'Dese ID' => '1234' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "Dese ID" => "1234" }, headers:, genders:, survey_items:,
schools:)
expect(values.valid_grade?).to eq true
end
end
context 'when grade is invalid' do
context "when grade is invalid" do
before :each do
attleboro
attleboro_respondents
end
it 'returns false' do
it "returns false" do
headers = %w[s-sbel-q5 s-phys-q2 grade RecordedDate]
values = SurveyItemValues.new(row: { 'grade' => '2', 'RecordedDate' => recorded_date, 'Dese ID' => '1234' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "grade" => "2", "RecordedDate" => recorded_date, "Dese ID" => "1234" }, headers:, genders:, survey_items:,
schools: School.school_hash)
expect(values.valid_grade?).to eq false
end
end
end
context '.valid_sd?' do
context 'when the standard deviation is valid' do
it 'returns true for student questions' do
context ".valid_sd?" do
context "when the standard deviation is valid" do
it "returns true for student questions" do
headers = %w[s-sbel-q5 s-phys-q1 s-phys-q2 RecordedDate]
values = SurveyItemValues.new(row: { 'RecordedDate' => recorded_date, 'Dese ID' => '1234', 's-sbel-q5' => '1', 's-phys-q1' => '', 's-phys-q2' => '5' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "Dese ID" => "1234", "s-sbel-q5" => "1", "s-phys-q1" => "", "s-phys-q2" => "5" }, headers:, genders:, survey_items:,
schools: School.school_hash)
expect(values.valid_sd?).to eq true
end
it 'returns true for teacher questions' do
it "returns true for teacher questions" do
headers = %w[t-sbel-q5 t-phys-q2]
values = SurveyItemValues.new(row: { 'RecordedDate' => recorded_date, 'Dese ID' => '1234', 't-sbel-q5' => '1', 't-phys-q2' => '5' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "Dese ID" => "1234", "t-sbel-q5" => "1", "t-phys-q2" => "5" }, headers:, genders:, survey_items:,
schools: School.school_hash)
expect(values.valid_sd?).to eq true
end
end
context 'when the standard deviation is invalid' do
it 'returns false for student questions' do
context "when the standard deviation is invalid" do
it "returns false for student questions" do
headers = %w[s-sbel-q5 s-phys-q1 s-phys-q2 RecordedDate]
values = SurveyItemValues.new(row: { 'RecordedDate' => recorded_date, 'Dese ID' => '1234', 's-sbel-q5' => '1', 's-phys-q2' => '1' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "Dese ID" => "1234", "s-sbel-q5" => "1", "s-phys-q2" => "1" }, headers:, genders:, survey_items:,
schools: School.school_hash)
expect(values.valid_sd?).to eq false
end
it 'returns false for teacher questions' do
it "returns false for teacher questions" do
headers = %w[t-sbel-q5 t-phys-q1 t-phys-q2 RecordedDate]
values = SurveyItemValues.new(row: { 'RecordedDate' => recorded_date, 'Dese ID' => '1234', 't-sbel-q5' => '1', 't-phys-q2' => '1' }, headers:, genders:, survey_items:,
values = SurveyItemValues.new(row: { "RecordedDate" => recorded_date, "Dese ID" => "1234", "t-sbel-q5" => "1", "t-phys-q2" => "1" }, headers:, genders:, survey_items:,
schools: School.school_hash)
expect(values.valid_sd?).to eq false
end

@ -1,59 +1,59 @@
require 'rails_helper'
require "rails_helper"
describe SurveyResponsesDataLoader do
let(:path_to_teacher_responses) { Rails.root.join('spec', 'fixtures', 'test_2020-21_teacher_survey_responses.csv') }
let(:path_to_student_responses) { Rails.root.join('spec', 'fixtures', 'test_2020-21_student_survey_responses.csv') }
let(:path_to_teacher_responses) { Rails.root.join("spec", "fixtures", "test_2020-21_teacher_survey_responses.csv") }
let(:path_to_student_responses) { Rails.root.join("spec", "fixtures", "test_2020-21_student_survey_responses.csv") }
let(:path_to_butler_student_responses) do
Rails.root.join('spec', 'fixtures', 'test_2022-23_butler_student_survey_responses.csv')
Rails.root.join("spec", "fixtures", "test_2022-23_butler_student_survey_responses.csv")
end
let(:ay_2020_21) { create(:academic_year, range: '2020-21') }
let(:ay_2022_23) { create(:academic_year, range: '2022-23') }
let(:ay_2020_21) { create(:academic_year, range: "2020-21") }
let(:ay_2022_23) { create(:academic_year, range: "2022-23") }
let(:school) { create(:school, name: 'Lee Elementary School', slug: 'lee-elementary-school', dese_id: 1_500_025) }
let(:lowell) { create(:district, name: 'Lowell', slug: 'lowell') }
let(:school) { create(:school, name: "Lee Elementary School", slug: "lee-elementary-school", dese_id: 1_500_025) }
let(:lowell) { create(:district, name: "Lowell", slug: "lowell") }
let(:second_school) do
create(:school, name: 'Lee Middle High School', slug: 'lee-middle-high-school', dese_id: 1_500_505,
create(:school, name: "Lee Middle High School", slug: "lee-middle-high-school", dese_id: 1_500_505,
district: lowell)
end
let(:butler_school) do
create(:school, name: 'Butler Elementary School', slug: 'butler-elementary-school', dese_id: 1_600_310,
create(:school, name: "Butler Elementary School", slug: "butler-elementary-school", dese_id: 1_600_310,
district: lowell)
end
let(:t_pcom_q3) { create(:survey_item, survey_item_id: 't-pcom-q3') }
let(:t_pcom_q2) { create(:survey_item, survey_item_id: 't-pcom-q2') }
let(:t_coll_q1) { create(:survey_item, survey_item_id: 't-coll-q1') }
let(:t_coll_q2) { create(:survey_item, survey_item_id: 't-coll-q2') }
let(:t_coll_q3) { create(:survey_item, survey_item_id: 't-coll-q3') }
let(:t_sach_q1) { create(:survey_item, survey_item_id: 't-sach-q1') }
let(:t_sach_q2) { create(:survey_item, survey_item_id: 't-sach-q2') }
let(:t_sach_q3) { create(:survey_item, survey_item_id: 't-sach-q3') }
let(:s_phys_q1) { create(:survey_item, survey_item_id: 's-phys-q1') }
let(:s_phys_q2) { create(:survey_item, survey_item_id: 's-phys-q2') }
let(:s_phys_q3) { create(:survey_item, survey_item_id: 's-phys-q3') }
let(:s_phys_q4) { create(:survey_item, survey_item_id: 's-phys-q4') }
let(:s_vale_q1) { create(:survey_item, survey_item_id: 's-phys-q1') }
let(:s_vale_q2) { create(:survey_item, survey_item_id: 's-phys-q2') }
let(:s_vale_q3) { create(:survey_item, survey_item_id: 's-phys-q3') }
let(:s_vale_q4) { create(:survey_item, survey_item_id: 's-phys-q4') }
let(:s_acst_q1) { create(:survey_item, survey_item_id: 's-acst-q1') }
let(:s_acst_q2) { create(:survey_item, survey_item_id: 's-acst-q2') }
let(:s_acst_q3) { create(:survey_item, survey_item_id: 's-acst-q3') }
let(:s_acst_q4) { create(:survey_item, survey_item_id: 's-acst-q4') }
let(:s_emsa_q1) { create(:survey_item, survey_item_id: 's-emsa-q1') }
let(:s_emsa_q2) { create(:survey_item, survey_item_id: 's-emsa-q2') }
let(:s_emsa_q3) { create(:survey_item, survey_item_id: 's-emsa-q3') }
let(:t_pcom_q3) { create(:survey_item, survey_item_id: "t-pcom-q3") }
let(:t_pcom_q2) { create(:survey_item, survey_item_id: "t-pcom-q2") }
let(:t_coll_q1) { create(:survey_item, survey_item_id: "t-coll-q1") }
let(:t_coll_q2) { create(:survey_item, survey_item_id: "t-coll-q2") }
let(:t_coll_q3) { create(:survey_item, survey_item_id: "t-coll-q3") }
let(:t_sach_q1) { create(:survey_item, survey_item_id: "t-sach-q1") }
let(:t_sach_q2) { create(:survey_item, survey_item_id: "t-sach-q2") }
let(:t_sach_q3) { create(:survey_item, survey_item_id: "t-sach-q3") }
let(:s_phys_q1) { create(:survey_item, survey_item_id: "s-phys-q1") }
let(:s_phys_q2) { create(:survey_item, survey_item_id: "s-phys-q2") }
let(:s_phys_q3) { create(:survey_item, survey_item_id: "s-phys-q3") }
let(:s_phys_q4) { create(:survey_item, survey_item_id: "s-phys-q4") }
let(:s_vale_q1) { create(:survey_item, survey_item_id: "s-phys-q1") }
let(:s_vale_q2) { create(:survey_item, survey_item_id: "s-phys-q2") }
let(:s_vale_q3) { create(:survey_item, survey_item_id: "s-phys-q3") }
let(:s_vale_q4) { create(:survey_item, survey_item_id: "s-phys-q4") }
let(:s_acst_q1) { create(:survey_item, survey_item_id: "s-acst-q1") }
let(:s_acst_q2) { create(:survey_item, survey_item_id: "s-acst-q2") }
let(:s_acst_q3) { create(:survey_item, survey_item_id: "s-acst-q3") }
let(:s_acst_q4) { create(:survey_item, survey_item_id: "s-acst-q4") }
let(:s_emsa_q1) { create(:survey_item, survey_item_id: "s-emsa-q1") }
let(:s_emsa_q2) { create(:survey_item, survey_item_id: "s-emsa-q2") }
let(:s_emsa_q3) { create(:survey_item, survey_item_id: "s-emsa-q3") }
let(:female) { create(:gender, qualtrics_code: 1) }
let(:male) { create(:gender, qualtrics_code: 2) }
let(:another_gender) { create(:gender, qualtrics_code: 3) }
let(:non_binary) { create(:gender, qualtrics_code: 4) }
let(:unknown_gender) { create(:gender, qualtrics_code: 99) }
let(:low_income) { create(:income, designation: 'Economically Disadvantaged Y') }
let(:high_income) { create(:income, designation: 'Economically Disadvantaged N') }
let(:unknown_income) { create(:income, designation: 'Unknown') }
let(:low_income) { create(:income, designation: "Economically Disadvantaged Y") }
let(:high_income) { create(:income, designation: "Economically Disadvantaged N") }
let(:unknown_income) { create(:income, designation: "Unknown") }
let(:setup) do
ay_2020_21
@ -98,12 +98,12 @@ describe SurveyResponsesDataLoader do
setup
end
describe 'loading teacher survey responses' do
describe "loading teacher survey responses" do
before do
SurveyResponsesDataLoader.load_data filepath: path_to_teacher_responses
end
it 'ensures teacher responses load correctly' do
it "ensures teacher responses load correctly" do
assigns_academic_year_to_survey_item_responses
assigns_school_to_the_survey_item_responses
assigns_recorded_date_to_teacher_responses
@ -114,12 +114,12 @@ describe SurveyResponsesDataLoader do
end
end
describe 'student survey responses' do
describe "student survey responses" do
before do
SurveyResponsesDataLoader.load_data filepath: path_to_student_responses
end
it 'ensures student responses load correctly' do
it "ensures student responses load correctly" do
assigns_academic_year_to_student_survey_item_responses
assigns_school_to_student_survey_item_responses
assigns_recorded_date_to_student_responses
@ -132,82 +132,82 @@ describe SurveyResponsesDataLoader do
is_idempotent_for_students
end
context 'when updating student survey responses from another csv file' do
context "when updating student survey responses from another csv file" do
before :each do
SurveyResponsesDataLoader.load_data filepath: Rails.root.join('spec', 'fixtures',
'secondary_test_2020-21_student_survey_responses.csv')
SurveyResponsesDataLoader.load_data filepath: Rails.root.join("spec", "fixtures",
"secondary_test_2020-21_student_survey_responses.csv")
end
it 'updates the likert score to the score on the new csv file' do
s_emsa_q1 = SurveyItem.find_by_survey_item_id 's-emsa-q1'
expect(SurveyItemResponse.where(response_id: 'student_survey_response_3',
it "updates the likert score to the score on the new csv file" do
s_emsa_q1 = SurveyItem.find_by_survey_item_id "s-emsa-q1"
expect(SurveyItemResponse.where(response_id: "student_survey_response_3",
survey_item: s_emsa_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_4',
expect(SurveyItemResponse.where(response_id: "student_survey_response_4",
survey_item: s_emsa_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_5',
expect(SurveyItemResponse.where(response_id: "student_survey_response_5",
survey_item: s_emsa_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_5',
expect(SurveyItemResponse.where(response_id: "student_survey_response_5",
survey_item: s_acst_q3).first.likert_score).to eq 4
end
end
end
# figure out why this is failing
describe 'when using Lowell rules to skip rows in the csv file' do
describe "when using Lowell rules to skip rows in the csv file" do
before :each do
SurveyResponsesDataLoader.load_data filepath: path_to_student_responses,
rules: [Rule::SkipNonLowellSchools]
end
it 'rejects any non-lowell school' do
expect(SurveyItemResponse.where(response_id: 'student_survey_response_1').count).to eq 0
it "rejects any non-lowell school" do
expect(SurveyItemResponse.where(response_id: "student_survey_response_1").count).to eq 0
expect(SurveyItemResponse.count).to eq 69
end
it 'loads the correct number of responses for lowell schools' do
expect(SurveyItemResponse.where(response_id: 'student_survey_response_2').count).to eq 0
expect(SurveyItemResponse.where(response_id: 'student_survey_response_3').count).to eq 12
expect(SurveyItemResponse.where(response_id: 'student_survey_response_4').count).to eq 15
expect(SurveyItemResponse.where(response_id: 'student_survey_response_5').count).to eq 14
it "loads the correct number of responses for lowell schools" do
expect(SurveyItemResponse.where(response_id: "student_survey_response_2").count).to eq 0
expect(SurveyItemResponse.where(response_id: "student_survey_response_3").count).to eq 12
expect(SurveyItemResponse.where(response_id: "student_survey_response_4").count).to eq 15
expect(SurveyItemResponse.where(response_id: "student_survey_response_5").count).to eq 14
end
context 'when loading 22-23 butler survey responses' do
context "when loading 22-23 butler survey responses" do
before :each do
SurveyResponsesDataLoader.load_data filepath: path_to_butler_student_responses,
rules: [Rule::SkipNonLowellSchools]
end
it 'loads all the responses for Butler' do
it "loads all the responses for Butler" do
expect(SurveyItemResponse.where(school: butler_school).count).to eq 56
end
it 'blank entries for grade get loaded as nils, not zero values' do
expect(SurveyItemResponse.where(response_id: 'butler_student_survey_response_1').first.grade).to eq 7
expect(SurveyItemResponse.where(response_id: 'butler_student_survey_response_2').first.grade).to eq 7
expect(SurveyItemResponse.where(response_id: 'butler_student_survey_response_3').first.grade).to eq 7
expect(SurveyItemResponse.where(response_id: 'butler_student_survey_response_4').first.grade).to eq 5
expect(SurveyItemResponse.where(response_id: 'butler_student_survey_response_5').first.grade).to eq 7
expect(SurveyItemResponse.where(response_id: 'butler_student_survey_response_6').first.grade).to eq 6
expect(SurveyItemResponse.where(response_id: 'butler_student_survey_response_7').first.grade).to eq nil
expect(SurveyItemResponse.where(response_id: 'butler_student_survey_response_8').first.grade).to eq 0
it "blank entries for grade get loaded as nils, not zero values" do
expect(SurveyItemResponse.where(response_id: "butler_student_survey_response_1").first.grade).to eq 7
expect(SurveyItemResponse.where(response_id: "butler_student_survey_response_2").first.grade).to eq 7
expect(SurveyItemResponse.where(response_id: "butler_student_survey_response_3").first.grade).to eq 7
expect(SurveyItemResponse.where(response_id: "butler_student_survey_response_4").first.grade).to eq 5
expect(SurveyItemResponse.where(response_id: "butler_student_survey_response_5").first.grade).to eq 7
expect(SurveyItemResponse.where(response_id: "butler_student_survey_response_6").first.grade).to eq 6
expect(SurveyItemResponse.where(response_id: "butler_student_survey_response_7").first.grade).to eq nil
expect(SurveyItemResponse.where(response_id: "butler_student_survey_response_8").first.grade).to eq 0
end
end
end
end
def assigns_academic_year_to_survey_item_responses
expect(SurveyItemResponse.find_by_response_id('teacher_survey_response_1').academic_year).to eq ay_2020_21
expect(SurveyItemResponse.find_by_response_id("teacher_survey_response_1").academic_year).to eq ay_2020_21
end
def assigns_school_to_the_survey_item_responses
expect(SurveyItemResponse.find_by_response_id('teacher_survey_response_1').school).to eq school
expect(SurveyItemResponse.find_by_response_id("teacher_survey_response_1").school).to eq school
end
def loads_survey_item_responses_for_a_given_survey_response
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_1').count).to eq 5
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_2').count).to eq 0
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_3').count).to eq 8
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_4').count).to eq 8
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_5').count).to eq 8
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_1").count).to eq 5
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_2").count).to eq 0
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_3").count).to eq 8
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_4").count).to eq 8
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_5").count).to eq 8
end
def loads_all_survey_item_responses_for_a_given_survey_item
@ -216,20 +216,20 @@ def loads_all_survey_item_responses_for_a_given_survey_item
end
def captures_likert_scores_for_survey_item_responses
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_1').where(survey_item: t_pcom_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_1').where(survey_item: t_pcom_q3).first.likert_score).to eq 3
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_1").where(survey_item: t_pcom_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_1").where(survey_item: t_pcom_q3).first.likert_score).to eq 3
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_2').where(survey_item: t_pcom_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_2').where(survey_item: t_pcom_q3)).to be_empty
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_2").where(survey_item: t_pcom_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_2").where(survey_item: t_pcom_q3)).to be_empty
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_3').where(survey_item: t_pcom_q2).first.likert_score).to eq 5
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_3').where(survey_item: t_pcom_q3).first.likert_score).to eq 5
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_3").where(survey_item: t_pcom_q2).first.likert_score).to eq 5
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_3").where(survey_item: t_pcom_q3).first.likert_score).to eq 5
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_4').where(survey_item: t_pcom_q2).first.likert_score).to eq 4
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_4').where(survey_item: t_pcom_q3).first.likert_score).to eq 4
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_4").where(survey_item: t_pcom_q2).first.likert_score).to eq 4
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_4").where(survey_item: t_pcom_q3).first.likert_score).to eq 4
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_5').where(survey_item: t_pcom_q2).first.likert_score).to eq 2
expect(SurveyItemResponse.where(response_id: 'teacher_survey_response_5').where(survey_item: t_pcom_q3).first.likert_score).to eq 4
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_5").where(survey_item: t_pcom_q2).first.likert_score).to eq 2
expect(SurveyItemResponse.where(response_id: "teacher_survey_response_5").where(survey_item: t_pcom_q3).first.likert_score).to eq 4
end
def is_idempotent
@ -241,19 +241,19 @@ def is_idempotent
end
def assigns_academic_year_to_student_survey_item_responses
expect(SurveyItemResponse.find_by_response_id('student_survey_response_3').academic_year).to eq ay_2020_21
expect(SurveyItemResponse.find_by_response_id("student_survey_response_3").academic_year).to eq ay_2020_21
end
def assigns_school_to_student_survey_item_responses
expect(SurveyItemResponse.find_by_response_id('student_survey_response_3').school).to eq second_school
expect(SurveyItemResponse.find_by_response_id("student_survey_response_3").school).to eq second_school
end
def loads_student_survey_item_response_values
expect(SurveyItemResponse.where(response_id: 'student_survey_response_1').count).to eq 3
expect(SurveyItemResponse.where(response_id: 'student_survey_response_2').count).to eq 0
expect(SurveyItemResponse.where(response_id: 'student_survey_response_3').count).to eq 12
expect(SurveyItemResponse.where(response_id: 'student_survey_response_4').count).to eq 15
expect(SurveyItemResponse.where(response_id: 'student_survey_response_5').count).to eq 14
expect(SurveyItemResponse.where(response_id: "student_survey_response_1").count).to eq 3
expect(SurveyItemResponse.where(response_id: "student_survey_response_2").count).to eq 0
expect(SurveyItemResponse.where(response_id: "student_survey_response_3").count).to eq 12
expect(SurveyItemResponse.where(response_id: "student_survey_response_4").count).to eq 15
expect(SurveyItemResponse.where(response_id: "student_survey_response_5").count).to eq 14
end
def student_survey_item_response_count_matches_expected
@ -262,20 +262,20 @@ def student_survey_item_response_count_matches_expected
end
def captures_likert_scores_for_student_survey_item_responses
expect(SurveyItemResponse.where(response_id: 'student_survey_response_1').where(survey_item: s_phys_q1).first.likert_score).to eq 3
expect(SurveyItemResponse.where(response_id: 'student_survey_response_1').where(survey_item: s_phys_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: "student_survey_response_1").where(survey_item: s_phys_q1).first.likert_score).to eq 3
expect(SurveyItemResponse.where(response_id: "student_survey_response_1").where(survey_item: s_phys_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: 'student_survey_response_2').where(survey_item: s_phys_q1)).to be_empty
expect(SurveyItemResponse.where(response_id: 'student_survey_response_2').where(survey_item: s_phys_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: "student_survey_response_2").where(survey_item: s_phys_q1)).to be_empty
expect(SurveyItemResponse.where(response_id: "student_survey_response_2").where(survey_item: s_phys_q2)).to be_empty
expect(SurveyItemResponse.where(response_id: 'student_survey_response_3').where(survey_item: s_phys_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_3').where(survey_item: s_phys_q2).first.likert_score).to eq 3
expect(SurveyItemResponse.where(response_id: "student_survey_response_3").where(survey_item: s_phys_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: "student_survey_response_3").where(survey_item: s_phys_q2).first.likert_score).to eq 3
expect(SurveyItemResponse.where(response_id: 'student_survey_response_4').where(survey_item: s_phys_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_4').where(survey_item: s_phys_q2).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: "student_survey_response_4").where(survey_item: s_phys_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: "student_survey_response_4").where(survey_item: s_phys_q2).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_5').where(survey_item: s_phys_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: 'student_survey_response_5').where(survey_item: s_phys_q2).first.likert_score).to eq 2
expect(SurveyItemResponse.where(response_id: "student_survey_response_5").where(survey_item: s_phys_q1).first.likert_score).to eq 1
expect(SurveyItemResponse.where(response_id: "student_survey_response_5").where(survey_item: s_phys_q2).first.likert_score).to eq 2
end
def is_idempotent_for_students
@ -287,12 +287,12 @@ def is_idempotent_for_students
end
def assigns_grade_level_to_responses
results = { 'student_survey_response_1' => 11,
'student_survey_response_3' => 8,
'student_survey_response_4' => 8,
'student_survey_response_5' => 7,
'student_survey_response_6' => 3,
'student_survey_response_7' => 4 }
results = { "student_survey_response_1" => 11,
"student_survey_response_3" => 8,
"student_survey_response_4" => 8,
"student_survey_response_5" => 7,
"student_survey_response_6" => 3,
"student_survey_response_7" => 4 }
results.each do |key, value|
expect(SurveyItemResponse.where(response_id: key).all? do |response|
response.grade == value
@ -301,12 +301,12 @@ def assigns_grade_level_to_responses
end
def assigns_gender_to_responses
results = { 'student_survey_response_1' => female,
'student_survey_response_3' => male,
'student_survey_response_4' => non_binary,
'student_survey_response_5' => non_binary,
'student_survey_response_6' => unknown_gender,
'student_survey_response_7' => unknown_gender }
results = { "student_survey_response_1" => female,
"student_survey_response_3" => male,
"student_survey_response_4" => non_binary,
"student_survey_response_5" => non_binary,
"student_survey_response_6" => unknown_gender,
"student_survey_response_7" => unknown_gender }
results.each do |key, value|
expect(SurveyItemResponse.where(response_id: key).first.gender).to eq value
@ -314,34 +314,34 @@ def assigns_gender_to_responses
end
def assigns_recorded_date_to_student_responses
results = { 'student_survey_response_1' => '2020-09-30T18:48:50',
'student_survey_response_3' => '2021-03-31T09:59:02',
'student_survey_response_4' => '2021-03-31T10:00:17',
'student_survey_response_5' => '2021-03-31T10:01:36',
'student_survey_response_6' => '2021-03-31T10:01:37',
'student_survey_response_7' => '2021-03-31T10:01:38' }
results = { "student_survey_response_1" => "2020-09-30T18:48:50",
"student_survey_response_3" => "2021-03-31T09:59:02",
"student_survey_response_4" => "2021-03-31T10:00:17",
"student_survey_response_5" => "2021-03-31T10:01:36",
"student_survey_response_6" => "2021-03-31T10:01:37",
"student_survey_response_7" => "2021-03-31T10:01:38" }
results.each do |key, value|
expect(SurveyItemResponse.find_by_response_id(key).recorded_date).to eq Date.parse(value)
end
end
def assigns_recorded_date_to_teacher_responses
results = { 'teacher_survey_response_1' => '2020-10-16 11:09:03',
'teacher_survey_response_3' => '2020-12-06 8:36:52',
'teacher_survey_response_4' => '2020-12-06 8:51:25',
'teacher_survey_response_5' => '2020-12-06 8:55:58' }
results = { "teacher_survey_response_1" => "2020-10-16 11:09:03",
"teacher_survey_response_3" => "2020-12-06 8:36:52",
"teacher_survey_response_4" => "2020-12-06 8:51:25",
"teacher_survey_response_5" => "2020-12-06 8:55:58" }
results.each do |key, value|
expect(SurveyItemResponse.find_by_response_id(key).recorded_date).to eq Date.parse(value)
end
end
def assigns_income_to_responses
results = { 'student_survey_response_1' => low_income,
'student_survey_response_3' => low_income,
'student_survey_response_4' => unknown_income,
'student_survey_response_5' => low_income,
'student_survey_response_6' => high_income,
'student_survey_response_7' => low_income }
results = { "student_survey_response_1" => low_income,
"student_survey_response_3" => low_income,
"student_survey_response_4" => unknown_income,
"student_survey_response_5" => low_income,
"student_survey_response_6" => high_income,
"student_survey_response_7" => low_income }
results.each do |key, value|
expect(SurveyItemResponse.where(response_id: key).first.income).to eq value

@ -1,12 +1,37 @@
# <<<<<<< HEAD
# # require "rails_helper"
# # include AnalyzeHelper
# # describe "District Admin", js: true do
# # let(:district) { District.find_by_slug "lee-public-schools" }
# # let(:different_district) { District.find_by_slug "maynard-public-schools" }
# # let(:school) { School.find_by_slug "lee-elementary-school" }
# # let(:school_in_same_district) { School.find_by_slug "lee-middle-high-school" }
# # let(:first_school_in_wareham) { School.find_by_slug "fowler-school" }
# # let(:category) { Category.find_by_name("Teachers & Leadership") }
# # let(:different_category) { Category.find_by_name("School Culture") }
# # let(:subcategory) { Subcategory.find_by_name("Teachers & The Teaching Environment") }
# # let(:different_subcategory) { Subcategory.find_by_name("Relationships") }
# # let(:measures_for_subcategory) { Measure.where(subcategory:) }
# # let(:scales_for_subcategory) { Scale.where(measure: measures_for_subcategory) }
# # let(:survey_items_for_subcategory) { SurveyItem.where(scale: scales_for_subcategory) }
# # let(:measure_1A_i) { Measure.find_by_measure_id("1A-i") }
# # let(:measure_2A_i) { Measure.find_by_measure_id("2A-i") }
# # let(:measure_2A_ii) { Measure.find_by_measure_id("2A-ii") }
# # let(:measure_4C_i) { Measure.find_by_measure_id("4C-i") }
# # let(:measure_with_no_survey_responses) { Measure.find_by_measure_id("3A-i") }
# =======
# require "rails_helper"
# include AnalyzeHelper
# describe "District Admin", js: true do
# let(:district) { District.find_by_slug "lee-public-schools" }
# let(:different_district) { District.find_by_slug "maynard-public-schools" }
# let(:school) { School.find_by_slug "lee-elementary-school" }
# let(:school_in_same_district) { School.find_by_slug "lee-middle-high-school" }
# let(:first_school_in_wareham) { School.find_by_slug "fowler-school" }
# let(:district) { District.find_by_slug "winchester" }
# let(:different_district) { District.find_by_slug "wareham" }
# let(:school) { School.find_by_slug "winchester-high-school" }
# let(:school_in_same_district) { School.find_by_slug "muraco-elementary-school" }
# let(:first_school_in_wareham) { School.find_by_slug "john-william-decas-elementary-school" }
# let(:category) { Category.find_by_name("Teachers & Leadership") }
# let(:different_category) { Category.find_by_name("School Culture") }
@ -21,12 +46,27 @@
# let(:measure_2A_ii) { Measure.find_by_measure_id("2A-ii") }
# let(:measure_4C_i) { Measure.find_by_measure_id("4C-i") }
# let(:measure_with_no_survey_responses) { Measure.find_by_measure_id("3A-i") }
# let(:survey_items_for_measure_1A_i) { measure_1A_i.survey_items }
# let(:survey_items_for_measure_2A_i) { measure_2A_i.survey_items }
# let(:survey_items_for_measure_2A_ii) { measure_2A_ii.survey_items }
# let(:survey_items_for_measure_4C_i) { measure_4C_i.survey_items }
# >>>>>>> a71ebbc (Add Overall Response Rate)
# # let(:survey_items_for_measure_1A_i) { measure_1A_i.survey_items }
# # let(:survey_items_for_measure_2A_i) { measure_2A_i.survey_items }
# # let(:survey_items_for_measure_2A_ii) { measure_2A_ii.survey_items }
# # let(:survey_items_for_measure_4C_i) { measure_4C_i.survey_items }
# <<<<<<< HEAD
# # let(:ay_2021_22) { AcademicYear.find_by_range "2021-22" }
# # let(:ay_2019_20) { AcademicYear.find_by_range "2019-20" }
# # let(:response_rates) do
# # [ay_2021_22, ay_2019_20].each do |academic_year|
# # [school, school_in_same_district, first_school_in_wareham].each do |school|
# # [subcategory, different_subcategory].each do |subcategory|
# # ResponseRate.create!(subcategory:, school:, academic_year:, student_response_rate: 100, teacher_response_rate: 100,
# # meets_student_threshold: true, meets_teacher_threshold: true)
# # end
# # end
# # end
# # end
# =======
# let(:ay_2021_22) { AcademicYear.find_by_range "2021-22" }
# let(:ay_2019_20) { AcademicYear.find_by_range "2019-20" }
# let(:response_rates) do
@ -34,83 +74,140 @@
# [school, school_in_same_district, first_school_in_wareham].each do |school|
# [subcategory, different_subcategory].each do |subcategory|
# ResponseRate.create!(subcategory:, school:, academic_year:, student_response_rate: 100, teacher_response_rate: 100,
# meets_student_threshold: true, meets_teacher_threshold: true)
# meets_student_threshold: true, meets_teacher_threshold: true)
# end
# end
# end
# end
# let(:username) { district.short_name }
# let(:password) { "#{district.short_name}!" }
# let(:respondents) do
# respondent = Respondent.find_or_initialize_by(school:, academic_year: ay_2021_22)
# respondent.total_students = 8
# respondent.total_teachers = 8
# respondent.one = 20
# respondent.save
# respondent = Respondent.find_or_initialize_by(school:, academic_year: ay_2019_20)
# respondent.total_students = 8
# respondent.total_teachers = 8
# respondent.one = 20
# respondent.save
# end
# before :each do
# Rails.application.load_seed
# respondents
# response_rates
# survey_item_responses = []
# >>>>>>> a71ebbc (Add Overall Response Rate)
# # let(:username) { district.short_name }
# # let(:password) { "#{district.short_name}!" }
# # let(:respondents) do
# # respondent = Respondent.find_or_initialize_by(school:, academic_year: ay_2021_22)
# # respondent.total_students = 8
# # respondent.total_teachers = 8
# # respondent.one = 20
# # respondent.save
# # respondent = Respondent.find_or_initialize_by(school:, academic_year: ay_2019_20)
# # respondent.total_students = 8
# # respondent.total_teachers = 8
# # respondent.one = 20
# # respondent.save
# # end
# # before :each do
# # Rails.application.load_seed
# <<<<<<< HEAD
# # respondents
# # response_rates
# # survey_item_responses = []
# # survey_items_for_measure_1A_i.each do |survey_item|
# # SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD.times do
# # survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2021_22,
# # school:, survey_item:, likert_score: 4)
# # end
# # end
# # survey_items_for_measure_2A_i.each do |survey_item|
# # SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD.times do
# # survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2021_22,
# # school:, survey_item:, likert_score: 5, grade: 1)
# # end
# # end
# # survey_items_for_measure_2A_ii.each do |survey_item|
# # SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD.times do
# # survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2021_22,
# # school:, survey_item:, likert_score: 5, grade: 1)
# # end
# # end
# # survey_items_for_measure_4C_i.each do |survey_item|
# # SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD.times do
# # survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2021_22,
# # school:, survey_item:, likert_score: 1, grade: 1)
# # end
# # end
# =======
# survey_items_for_measure_1A_i.each do |survey_item|
# SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD.times do
# survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2021_22,
# school:, survey_item:, likert_score: 4)
# school:, survey_item:, likert_score: 4)
# end
# end
# survey_items_for_measure_2A_i.each do |survey_item|
# SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD.times do
# survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2021_22,
# school:, survey_item:, likert_score: 5, grade: 1)
# school:, survey_item:, likert_score: 5, grade: 1)
# end
# end
# survey_items_for_measure_2A_ii.each do |survey_item|
# SurveyItemResponse::STUDENT_RESPONSE_THRESHOLD.times do
# survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2021_22,
# school:, survey_item:, likert_score: 5, grade: 1)
# school:, survey_item:, likert_score: 5, grade: 1)
# end
# end
# survey_items_for_measure_4C_i.each do |survey_item|
# SurveyItemResponse::TEACHER_RESPONSE_THRESHOLD.times do
# survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2021_22,
# school:, survey_item:, likert_score: 1, grade: 1)
# school:, survey_item:, likert_score: 1, grade: 1)
# end
# end
# survey_items_for_subcategory.each do |survey_item|
# 2.times do
# survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2021_22,
# school:, survey_item:, likert_score: 4, grade: 1)
# school:, survey_item:, likert_score: 4, grade: 1)
# end
# end
# SurveyItemResponse.import survey_item_responses
# end
# >>>>>>> a71ebbc (Add Overall Response Rate)
# # survey_items_for_subcategory.each do |survey_item|
# # 2.times do
# # survey_item_responses << SurveyItemResponse.new(response_id: rand.to_s, academic_year: ay_2021_22,
# # school:, survey_item:, likert_score: 4, grade: 1)
# # end
# # end
# # SurveyItemResponse.import survey_item_responses
# # end
# <<<<<<< HEAD
# # it "navigates through the site" do
# # page.driver.basic_authorize(username, password)
# # visit "/welcome"
# # expect(page).to have_text("Teachers & Leadership")
# # go_to_school_overview_from_welcome_page(district, school)
# =======
# it "navigates through the site" do
# page.driver.basic_authorize(username, password)
# # page.driver.basic_authorize(username, password)
# visit "/welcome"
# expect(page).to have_text("Teachers & Leadership")
# go_to_school_overview_from_welcome_page(district, school)
# >>>>>>> a71ebbc (Add Overall Response Rate)
# district_admin_sees_overview_content
# # district_admin_sees_overview_content
# <<<<<<< HEAD
# # click_on "Teachers & Leadership"
# # district_admin_sees_browse_content
# # click_on "Overview"
# # district_admin_sees_overview_content
# # click_on "Analyze"
# # district_admin_sees_analyze_content
# =======
# click_on "Teachers & Leadership"
# district_admin_sees_browse_content
@ -119,46 +216,101 @@
# click_on "Analyze"
# district_admin_sees_analyze_content
# >>>>>>> a71ebbc (Add Overall Response Rate)
# # go_to_different_category(different_category)
# # district_admin_sees_category_change
# go_to_different_category(different_category)
# district_admin_sees_category_change
# # go_to_different_subcategory(different_subcategory)
# # district_admin_sees_subcategory_change
# go_to_different_subcategory(different_subcategory)
# district_admin_sees_subcategory_change
# <<<<<<< HEAD
# # click_on "Browse"
# # district_admin_sees_browse_content
# # click_on "School Culture"
# # expect(page).to have_text("Measures the degree to which the school environment is safe, caring, and academically-oriented. It considers factors like bullying, student-teacher relationships, and student valuing of learning.")
# =======
# click_on "Browse"
# district_admin_sees_browse_content
# click_on "School Culture"
# expect(page).to have_text("Measures the degree to which the school environment is safe, caring, and academically-oriented. It considers factors like bullying, student-teacher relationships, and student valuing of learning.")
# >>>>>>> a71ebbc (Add Overall Response Rate)
# go_to_different_school_in_same_district(school_in_same_district)
# district_admin_sees_schools_change
# # go_to_different_school_in_same_district(school_in_same_district)
# # district_admin_sees_schools_change
# go_to_different_district(different_district)
# district_admin_sees_district_change
# # go_to_different_district(different_district)
# # district_admin_sees_district_change
# go_to_different_year(ay_2019_20)
# district_admin_sees_year_change
# end
# end
# # go_to_different_year(ay_2019_20)
# # district_admin_sees_year_change
# # end
# # end
# private
# # private
# <<<<<<< HEAD
# # def district_admin_sees_professional_qualifications
# # expect(page).to have_text("Professional Qualifications")
# # expect(page).to have_css("[data-for-measure-id='1A-i']")
# =======
# def district_admin_sees_professional_qualifications
# expect(page).to have_text("Professional Qualifications")
# expect(page).to have_css("[data-for-measure-id='1A-i']")
# >>>>>>> a71ebbc (Add Overall Response Rate)
# # TODO: cutpoints in source of truth have changed so the cutpoints have moved and '2.99%' is no longer a valid value for this cutpoint.
# # expect(page).to have_css("[data-for-measure-id='1A-i'][width='2.99%'][x='60%']")
# end
# # # TODO: cutpoints in source of truth have changed so the cutpoints have moved and '2.99%' is no longer a valid value for this cutpoint.
# # # expect(page).to have_css("[data-for-measure-id='1A-i'][width='2.99%'][x='60%']")
# # end
# <<<<<<< HEAD
# # def district_admin_sees_student_physical_safety
# # expect(page).to have_text("Student Physical Safety")
# =======
# def district_admin_sees_student_physical_safety
# expect(page).to have_text("Student Physical Safety")
# expect(page).to have_css("[data-for-measure-id='2A-i'][width='40.0%'][x='60%']")
# end
# >>>>>>> a71ebbc (Add Overall Response Rate)
# # expect(page).to have_css("[data-for-measure-id='2A-i'][width='40.0%'][x='60%']")
# # end
# <<<<<<< HEAD
# # def district_admin_sees_problem_solving_emphasis
# # expect(page).to have_text("Problem Solving")
# # expect(page).to have_css("[data-for-measure-id='4C-i'][width='60.0%'][x='0.0%']")
# # end
# # def go_to_school_overview_from_welcome_page(district, school)
# # expect(page).to have_select("district", selected: "Select a District")
# # select district.name, from: "district-dropdown"
# # expect(page).to have_select("school", selected: "Select a School")
# # select school.name, from: "school-dropdown"
# # expect(page).to have_select("school", selected: "Lee Elementary School")
# # expect(page).to have_xpath("//a[@class='mx-4 btn btn-secondary'][.='Go' and not(@disabled='disabled')]")
# # click_on "Go"
# # end
# # def go_to_different_school_in_same_district(school)
# # select school.name, from: "select-school"
# # end
# # def go_to_different_district(district)
# # page.driver.basic_authorize(different_district.short_name, "#{different_district.short_name}!")
# # select district.name, from: "select-district"
# # end
# # def go_to_different_year(year)
# # select year.formatted_range, from: "select-academic-year"
# # end
# # def district_admin_sees_schools_change
# # expected_path = "/districts/#{school_in_same_district.district.slug}/schools/#{school_in_same_district.slug}/browse/teachers-and-leadership?year=#{ay_2021_22.range}"
# # expect(page).to have_current_path(expected_path)
# # end
# =======
# def district_admin_sees_problem_solving_emphasis
# expect(page).to have_text("Problem Solving")
# expect(page).to have_css("[data-for-measure-id='4C-i'][width='60.0%'][x='0.0%']")
@ -169,9 +321,8 @@
# select district.name, from: "district-dropdown"
# expect(page).to have_select("school", selected: "Select a School")
# select school.name, from: "school-dropdown"
# expect(page).to have_select("school", selected: "Lee Elementary School")
# expect(page).to have_select("school", selected: "Winchester High School")
# expect(page).to have_xpath("//a[@class='mx-4 btn btn-secondary'][.='Go' and not(@disabled='disabled')]")
# click_on "Go"
# end
@ -180,7 +331,6 @@
# end
# def go_to_different_district(district)
# page.driver.basic_authorize(different_district.short_name, "#{different_district.short_name}!")
# select district.name, from: "select-district"
# end
@ -188,31 +338,67 @@
# select year.formatted_range, from: "select-academic-year"
# end
# def district_admin_sees_schools_change
# expected_path = "/districts/#{school_in_same_district.district.slug}/schools/#{school_in_same_district.slug}/browse/teachers-and-leadership?year=#{ay_2021_22.range}"
# expect(page).to have_current_path(expected_path)
# end
# def district_admin_sees_district_change
# expected_path = "/districts/#{different_district.slug}/schools/#{different_district.schools.alphabetic.first.slug}/browse/teachers-and-leadership?year=#{ay_2021_22.range}"
# expect(page).to have_current_path(expected_path)
# def got_to_analyze_page
# end
# def district_admin_sees_year_change
# expected_path = "/districts/#{different_district.slug}/schools/#{different_district.schools.alphabetic.first.slug}/browse/teachers-and-leadership?year=2019-20"
# expect(page).to have_current_path(expected_path)
# end
# >>>>>>> a71ebbc (Add Overall Response Rate)
# # def district_admin_sees_district_change
# # expected_path = "/districts/#{different_district.slug}/schools/#{different_district.schools.alphabetic.first.slug}/browse/teachers-and-leadership?year=#{ay_2021_22.range}"
# # expect(page).to have_current_path(expected_path)
# # end
# # def district_admin_sees_year_change
# # expected_path = "/districts/#{different_district.slug}/schools/#{different_district.schools.alphabetic.first.slug}/browse/teachers-and-leadership?year=2019-20"
# # expect(page).to have_current_path(expected_path)
# # end
# # def district_admin_sees_overview_content
# # expect(page).to have_select("academic-year", selected: "2021 2022")
# # expect(page).to have_select("district", selected: "Lee Public Schools")
# # expect(page).to have_select("school", selected: "Lee Elementary School")
# # expect(page).to have_text(school.name)
# <<<<<<< HEAD
# # district_admin_sees_professional_qualifications
# # district_admin_sees_student_physical_safety
# # district_admin_sees_problem_solving_emphasis
# =======
# def district_admin_sees_overview_content
# expect(page).to have_select("academic-year", selected: "2021 2022")
# expect(page).to have_select("district", selected: "Lee Public Schools")
# expect(page).to have_select("school", selected: "Lee Elementary School")
# expect(page).to have_select("district", selected: "Winchester")
# expect(page).to have_select("school", selected: "Winchester High School")
# expect(page).to have_text(school.name)
# >>>>>>> a71ebbc (Add Overall Response Rate)
# # page.assert_selector(".measure-row-bar", count: 6)
# # end
# <<<<<<< HEAD
# # def district_admin_sees_browse_content
# # expect(page).to have_text("Teachers & Leadership")
# # expect(page).to have_text("Approval")
# # end
# # def district_admin_sees_analyze_content
# # expect(page).to have_text("1:Teachers & Leadership > 1A:Teachers & The Teaching Environment")
# # end
# # def go_to_different_category(category)
# # select category.name, from: "select-category"
# # end
# # def district_admin_sees_category_change
# # expect(page).to have_text "2A:Safety"
# # end
# district_admin_sees_professional_qualifications
# district_admin_sees_student_physical_safety
# district_admin_sees_problem_solving_emphasis
# # def go_to_different_subcategory(subcategory)
# # select subcategory.name, from: "select-subcategory"
# # end
# # def district_admin_sees_subcategory_change
# # expect(page).to have_text("Relationships")
# # end
# =======
# page.assert_selector(".measure-row-bar", count: 6)
# end
@ -240,3 +426,4 @@
# def district_admin_sees_subcategory_change
# expect(page).to have_text("Relationships")
# end
# >>>>>>> a71ebbc (Add Overall Response Rate)

@ -1,42 +1,42 @@
require 'rails_helper'
require "rails_helper"
include VarianceHelper
describe 'overview/index' do
describe "overview/index" do
subject { Nokogiri::HTML(rendered) }
let(:support_for_teaching) do
measure = create(:measure, name: 'Support For Teaching Development & Growth', measure_id: '1')
measure = create(:measure, name: "Support For Teaching Development & Growth", measure_id: "1")
scale = create(:scale, measure:)
create(:student_survey_item,
scale:,
watch_low_benchmark: 1.5,
growth_low_benchmark: 2.5,
approval_low_benchmark: 3.5,
ideal_low_benchmark: 4.5)
scale:,
watch_low_benchmark: 1.5,
growth_low_benchmark: 2.5,
approval_low_benchmark: 3.5,
ideal_low_benchmark: 4.5)
measure
end
let(:effective_leadership) do
measure = create(:measure, name: 'Effective Leadership', measure_id: '2')
measure = create(:measure, name: "Effective Leadership", measure_id: "2")
scale = create(:scale, measure:)
create(:teacher_survey_item,
scale:,
watch_low_benchmark: 1.5,
growth_low_benchmark: 2.5,
approval_low_benchmark: 3.5,
ideal_low_benchmark: 4.5)
scale:,
watch_low_benchmark: 1.5,
growth_low_benchmark: 2.5,
approval_low_benchmark: 3.5,
ideal_low_benchmark: 4.5)
measure
end
let(:professional_qualifications) do
measure = create(:measure, name: 'Professional Qualifications', measure_id: '3')
measure = create(:measure, name: "Professional Qualifications", measure_id: "3")
scale = create(:scale, measure:)
create(:admin_data_item,
scale:,
watch_low_benchmark: 1.5,
growth_low_benchmark: 2.5,
approval_low_benchmark: 3.5,
ideal_low_benchmark: 4.5)
scale:,
watch_low_benchmark: 1.5,
growth_low_benchmark: 2.5,
approval_low_benchmark: 3.5,
ideal_low_benchmark: 4.5)
measure
end
@ -47,14 +47,19 @@ describe 'overview/index' do
assign :academic_years, [@academic_year]
@district = create(:district)
@school = create(:school)
@student_response_rate_presenter = ResponseRatePresenter.new(focus: :student, school: @school,
academic_year: @academic_year)
@teacher_response_rate_presenter = ResponseRatePresenter.new(focus: :teacher, school: @school,
academic_year: @academic_year)
Respondent.create!(school: @school, academic_year: @academic_year, total_students: 40, total_teachers: 40)
ResponseRate.create!(subcategory: Subcategory.first, school: @school, academic_year: @academic_year,
student_response_rate: 100, teacher_response_rate: 100, meets_student_threshold: true, meets_teacher_threshold: true)
student_response_rate: 100, teacher_response_rate: 100, meets_student_threshold: true, meets_teacher_threshold: true)
render
end
context 'when some presenters have a nil score' do
context "when some presenters have a nil score" do
let(:variance_chart_row_presenters) do
[
VarianceChartRowPresenter.new(measure: support_for_teaching, score: Score.new),
@ -63,49 +68,49 @@ describe 'overview/index' do
]
end
it 'displays a note detailing which measures have insufficient responses for the given school & academic year' do
it "displays a note detailing which measures have insufficient responses for the given school & academic year" do
expect(rendered).to match %r{Note: The following measures are not displayed due to limited availability of school admin data and/or low survey response rates: Support For Teaching Development &amp; Growth; Professional Qualifications.}
end
it 'displays a variance row and label only those presenters for which the score is not nil' do
displayed_variance_rows = subject.css('[data-for-measure-id]')
it "displays a variance row and label only those presenters for which the score is not nil" do
displayed_variance_rows = subject.css("[data-for-measure-id]")
expect(displayed_variance_rows.count).to eq 1
expect(displayed_variance_rows.first.attribute('data-for-measure-id').value).to eq '2'
expect(displayed_variance_rows.first.attribute("data-for-measure-id").value).to eq "2"
displayed_variance_labels = subject.css('[data-variance-row-label]')
displayed_variance_labels = subject.css("[data-variance-row-label]")
expect(displayed_variance_labels.count).to eq 1
expect(displayed_variance_labels.first.inner_text).to include 'Effective Leadership'
expect(displayed_variance_labels.first.inner_text).to include "Effective Leadership"
end
end
context 'when all the presenters have a non-nil score' do
context "when all the presenters have a non-nil score" do
let(:variance_chart_row_presenters) do
measure = create(:measure, name: 'Display Me', measure_id: 'display-me')
measure = create(:measure, name: "Display Me", measure_id: "display-me")
scale = create(:scale, measure:)
create(:student_survey_item,
scale:,
watch_low_benchmark: 1.5,
growth_low_benchmark: 2.5,
approval_low_benchmark: 3.5,
ideal_low_benchmark: 4.5)
scale:,
watch_low_benchmark: 1.5,
growth_low_benchmark: 2.5,
approval_low_benchmark: 3.5,
ideal_low_benchmark: 4.5)
[
VarianceChartRowPresenter.new(measure:,
score: Score.new(average: rand))
score: Score.new(average: rand))
]
end
it 'does not display a note detailing which measures have insufficient responses for the given school & academic year' do
it "does not display a note detailing which measures have insufficient responses for the given school & academic year" do
expect(rendered).not_to match %r{Note: The following measures are not displayed due to limited availability of school admin data and/or low survey response rates}
end
it 'displays a variance row for each presenter' do
displayed_variance_rows = subject.css('[data-for-measure-id]')
it "displays a variance row for each presenter" do
displayed_variance_rows = subject.css("[data-for-measure-id]")
expect(displayed_variance_rows.count).to eq 1
expect(displayed_variance_rows.first.attribute('data-for-measure-id').value).to eq 'display-me'
expect(displayed_variance_rows.first.attribute("data-for-measure-id").value).to eq "display-me"
displayed_variance_labels = subject.css('[data-variance-row-label]')
displayed_variance_labels = subject.css("[data-variance-row-label]")
expect(displayed_variance_labels.count).to eq 1
expect(displayed_variance_labels.first.inner_text).to include 'Display Me'
expect(displayed_variance_labels.first.inner_text).to include "Display Me"
end
end
end

Loading…
Cancel
Save