From 26f739090b2066c0a26dc6d998e3975f9b252d46 Mon Sep 17 00:00:00 2001 From: rebuilt Date: Tue, 2 Aug 2022 21:28:25 -0700 Subject: [PATCH] add race columns to graph --- app/models/analyze/graph/students_by_group.rb | 15 ++++---- .../analyze/graph/column/american_indian.rb | 37 +++++++++++++++++++ app/presenters/analyze/graph/column/asian.rb | 34 +++++++++++++++++ app/presenters/analyze/graph/column/black.rb | 34 +++++++++++++++++ .../column/grouped_bar_column_presenter.rb | 1 + .../analyze/graph/column/hispanic.rb | 34 +++++++++++++++++ .../analyze/graph/column/middle_eastern.rb | 34 +++++++++++++++++ .../analyze/graph/column/race_score.rb | 17 +++++++++ .../analyze/graph/column/unknown.rb | 34 +++++++++++++++++ app/presenters/analyze/graph/column/white.rb | 34 +++++++++++++++++ app/services/student_loader.rb | 2 + app/views/analyze/_data_filters.html.erb | 1 + app/views/analyze/index.html.erb | 1 + spec/views/analyze/index.html.erb_spec.rb | 1 + 14 files changed, 271 insertions(+), 8 deletions(-) create mode 100644 app/presenters/analyze/graph/column/american_indian.rb create mode 100644 app/presenters/analyze/graph/column/asian.rb create mode 100644 app/presenters/analyze/graph/column/black.rb create mode 100644 app/presenters/analyze/graph/column/hispanic.rb create mode 100644 app/presenters/analyze/graph/column/middle_eastern.rb create mode 100644 app/presenters/analyze/graph/column/race_score.rb create mode 100644 app/presenters/analyze/graph/column/unknown.rb create mode 100644 app/presenters/analyze/graph/column/white.rb diff --git a/app/models/analyze/graph/students_by_group.rb b/app/models/analyze/graph/students_by_group.rb index ff420652..20e6e4ed 100644 --- a/app/models/analyze/graph/students_by_group.rb +++ b/app/models/analyze/graph/students_by_group.rb @@ -10,14 +10,13 @@ module Analyze end def columns - [Analyze::Graph::Column::Student, - Analyze::Graph::Column::Student, - Analyze::Graph::Column::Student, - Analyze::Graph::Column::Student, - Analyze::Graph::Column::Student, - Analyze::Graph::Column::Student, - Analyze::Graph::Column::Student, - Analyze::Graph::Column::Student, + [Analyze::Graph::Column::AmericanIndian, + Analyze::Graph::Column::Asian, + Analyze::Graph::Column::Black, + Analyze::Graph::Column::Hispanic, + Analyze::Graph::Column::MiddleEastern, + Analyze::Graph::Column::Unknown, + Analyze::Graph::Column::White, Analyze::Graph::Column::Student] end end diff --git a/app/presenters/analyze/graph/column/american_indian.rb b/app/presenters/analyze/graph/column/american_indian.rb new file mode 100644 index 00000000..5e695d37 --- /dev/null +++ b/app/presenters/analyze/graph/column/american_indian.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Analyze + module Graph + module Column + class AmericanIndian < GroupedBarColumnPresenter + include Analyze::Graph::Column::RaceScore + def label + # TODO: offset labels so they don't overlap + 'American Indian or Alaskan Native' + end + + def basis + 'student' + end + + def show_irrelevancy_message? + !measure.includes_student_survey_items? + end + + def show_insufficient_data_message? + # TODO: implement this logic. Resize messages so they are bound to their column + false + end + + def score(year_index) + # TODO: make sure the score calculation bubble up instead of just average + race_score(measure:, school:, academic_year: academic_years[year_index], race:) + end + + def race + Race.find_by_qualtrics_code 1 + end + end + end + end +end diff --git a/app/presenters/analyze/graph/column/asian.rb b/app/presenters/analyze/graph/column/asian.rb new file mode 100644 index 00000000..830647fa --- /dev/null +++ b/app/presenters/analyze/graph/column/asian.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Analyze + module Graph + module Column + class Asian < GroupedBarColumnPresenter + include Analyze::Graph::Column::RaceScore + def label + 'Asian or Pacific Islander' + end + + def basis + 'student' + end + + def show_irrelevancy_message? + !measure.includes_student_survey_items? + end + + def show_insufficient_data_message? + false + end + + def score(year_index) + race_score(measure:, school:, academic_year: academic_years[year_index], race:) + end + + def race + Race.find_by_qualtrics_code 2 + end + end + end + end +end diff --git a/app/presenters/analyze/graph/column/black.rb b/app/presenters/analyze/graph/column/black.rb new file mode 100644 index 00000000..8946c7a5 --- /dev/null +++ b/app/presenters/analyze/graph/column/black.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Analyze + module Graph + module Column + class Black < GroupedBarColumnPresenter + include Analyze::Graph::Column::RaceScore + def label + 'Black or African American' + end + + def basis + 'student' + end + + def show_irrelevancy_message? + !measure.includes_student_survey_items? + end + + def show_insufficient_data_message? + false + end + + def score(year_index) + race_score(measure:, school:, academic_year: academic_years[year_index], race:) + end + + def race + Race.find_by_qualtrics_code 3 + end + end + end + end +end diff --git a/app/presenters/analyze/graph/column/grouped_bar_column_presenter.rb b/app/presenters/analyze/graph/column/grouped_bar_column_presenter.rb index 19a50bb1..3369e495 100644 --- a/app/presenters/analyze/graph/column/grouped_bar_column_presenter.rb +++ b/app/presenters/analyze/graph/column/grouped_bar_column_presenter.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# TODO: resize bars so they never extend beyond the bounds of the column module Analyze module Graph module Column diff --git a/app/presenters/analyze/graph/column/hispanic.rb b/app/presenters/analyze/graph/column/hispanic.rb new file mode 100644 index 00000000..e6c76459 --- /dev/null +++ b/app/presenters/analyze/graph/column/hispanic.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Analyze + module Graph + module Column + class Hispanic < GroupedBarColumnPresenter + include Analyze::Graph::Column::RaceScore + def label + 'Hispanic or Latinx' + end + + def basis + 'student' + end + + def show_irrelevancy_message? + !measure.includes_student_survey_items? + end + + def show_insufficient_data_message? + false + end + + def score(year_index) + race_score(measure:, school:, academic_year: academic_years[year_index], race:) + end + + def race + Race.find_by_qualtrics_code 4 + end + end + end + end +end diff --git a/app/presenters/analyze/graph/column/middle_eastern.rb b/app/presenters/analyze/graph/column/middle_eastern.rb new file mode 100644 index 00000000..8cc3c924 --- /dev/null +++ b/app/presenters/analyze/graph/column/middle_eastern.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Analyze + module Graph + module Column + class MiddleEastern < GroupedBarColumnPresenter + include Analyze::Graph::Column::RaceScore + def label + 'Middle Eastern' + end + + def basis + 'student' + end + + def show_irrelevancy_message? + !measure.includes_student_survey_items? + end + + def show_insufficient_data_message? + false + end + + def score(year_index) + race_score(measure:, school:, academic_year: academic_years[year_index], race:) + end + + def race + Race.find_by_qualtrics_code 8 + end + end + end + end +end diff --git a/app/presenters/analyze/graph/column/race_score.rb b/app/presenters/analyze/graph/column/race_score.rb new file mode 100644 index 00000000..33ceb0da --- /dev/null +++ b/app/presenters/analyze/graph/column/race_score.rb @@ -0,0 +1,17 @@ +module Analyze + module Graph + module Column + module RaceScore + def race_score(measure:, school:, academic_year:, race:) + survey_items = measure.student_survey_items + average = SurveyItemResponse.where(school:, + academic_year:, + survey_item: survey_items, + student: StudentRace.where(race:)) + .average(:likert_score) + Score.new(average, true, true, true) + end + end + end + end +end diff --git a/app/presenters/analyze/graph/column/unknown.rb b/app/presenters/analyze/graph/column/unknown.rb new file mode 100644 index 00000000..48339fbd --- /dev/null +++ b/app/presenters/analyze/graph/column/unknown.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Analyze + module Graph + module Column + class Unknown < GroupedBarColumnPresenter + include Analyze::Graph::Column::RaceScore + def label + 'Unknown' + end + + def basis + 'student' + end + + def show_irrelevancy_message? + !measure.includes_student_survey_items? + end + + def show_insufficient_data_message? + false + end + + def score(year_index) + race_score(measure:, school:, academic_year: academic_years[year_index], race:) + end + + def race + Race.find_by_qualtrics_code 99 + end + end + end + end +end diff --git a/app/presenters/analyze/graph/column/white.rb b/app/presenters/analyze/graph/column/white.rb new file mode 100644 index 00000000..b3dbdf24 --- /dev/null +++ b/app/presenters/analyze/graph/column/white.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Analyze + module Graph + module Column + class White < GroupedBarColumnPresenter + include Analyze::Graph::Column::RaceScore + def label + 'White or Caucasian' + end + + def basis + 'student' + end + + def show_irrelevancy_message? + !measure.includes_student_survey_items? + end + + def show_insufficient_data_message? + false + end + + def score(year_index) + race_score(measure:, school:, academic_year: academic_years[year_index], race:) + end + + def race + Race.find_by_qualtrics_code 5 + end + end + end + end +end diff --git a/app/services/student_loader.rb b/app/services/student_loader.rb index 52af3e80..3a0dc481 100644 --- a/app/services/student_loader.rb +++ b/app/services/student_loader.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true # SurveyItemResponse.where(student: StudentRace.where(race: Race.find_by_qualtrics_code(8)).limit(10).map(&:student)).count + +# TODO figure out why earlier years don't have races attached require 'csv' class StudentLoader diff --git a/app/views/analyze/_data_filters.html.erb b/app/views/analyze/_data_filters.html.erb index ee510db6..76e35e29 100644 --- a/app/views/analyze/_data_filters.html.erb +++ b/app/views/analyze/_data_filters.html.erb @@ -1,3 +1,4 @@ +<%# TODO Hook up the buttons so that only the selected races are shown for each column %>

Data Filters

<% @graphs.each do |graph| %> diff --git a/app/views/analyze/index.html.erb b/app/views/analyze/index.html.erb index 41f776d8..6d3d1c66 100644 --- a/app/views/analyze/index.html.erb +++ b/app/views/analyze/index.html.erb @@ -17,6 +17,7 @@ <%= render partial: "data_filters", locals: {district: @district, school: @school, academic_year: @academic_year, category: @category, subcategory: @subcategory} %>
+ <%# TODO : make sure the caching rules work with the new graphs %> <% cache [@subcategory, @school, @selected_academic_years, @response_rate_timestamp] do %>
<% @measures.each do |measure| %> diff --git a/spec/views/analyze/index.html.erb_spec.rb b/spec/views/analyze/index.html.erb_spec.rb index de115d91..d08c85f3 100644 --- a/spec/views/analyze/index.html.erb_spec.rb +++ b/spec/views/analyze/index.html.erb_spec.rb @@ -1,3 +1,4 @@ +# TODO: fix failing tests require 'rails_helper' include AnalyzeHelper