diff --git a/Gemfile b/Gemfile index 1b0231c1..42c98fa6 100644 --- a/Gemfile +++ b/Gemfile @@ -6,72 +6,33 @@ git_source(:github) do |repo_name| "https://github.com/#{repo_name}.git" end -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem "rails", "~> 7.1.3" -gem "sprockets-rails" - -gem "pg" - -# Use Puma as the app server -gem "puma", ">= 6.4.0" -# Use Uglifier as compressor for JavaScript assets -# gem "uglifier", ">= 1.3.0" -# See https://github.com/rails/execjs#readme for more supported runtimes -# Use jquery as the JavaScript library -# gem "jquery-rails" -# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -# gem "jbuilder", "~> 2.5" -# Use Redis adapter to run Action Cable in production -# gem "redis", "~> 3.0" -# Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' - -gem "nokogiri" - -gem "bootsnap", require: false - -# gem "haml" - -gem "friendly_id", "~> 5.1.0" - -gem "newrelic_rpm" - -gem "devise", git: "https://github.com/heartcombo/devise" - -# gem "omniauth" - gem "activerecord-import" - -gem "jsbundling-rails" - -gem "cssbundling-rails" - -gem "turbo-rails" - -gem "stimulus-rails" - -gem "watir" - gem "bcrypt_pbkdf" +gem "bootsnap", require: false +gem "cssbundling-rails" +gem "csv", "~> 3.3" +gem "devise", git: "https://github.com/heartcombo/devise" gem "ed25519" +gem "friendly_id", "~> 5.1.0" +gem "jsbundling-rails" gem "net-sftp" - +gem "newrelic_rpm" +gem "nokogiri" +gem "observer", "~> 0.1.2" +gem "pg" +gem "puma", ">= 6.4.0" +gem "rails", "~> 7.1.3" +gem "sprockets-rails" gem "standard_deviation" - -group :development, :test do - # Call 'byebug' anywhere in the code to stop execution and get a debugger console - gem "byebug", platform: :mri - gem "dotenv-rails" - gem "factory_bot_rails" - gem "parallel_tests" - gem "rack-mini-profiler" - gem "rspec-rails", "~> 6.0.3" -end +gem "stimulus-rails" +gem "turbo-rails" +gem "watir" group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem "brakeman" gem "bullet" + gem "dexter" gem "erb_lint", require: false gem "erblint-github" gem "guard" @@ -79,32 +40,38 @@ group :development do gem "guard-rspec", require: false gem "listen", "~> 3.8.0" gem "nested_scaffold" - gem "rack-livereload" - # gem 'reek', require: false - gem "dexter" gem "pghero" gem "pg_query", ">= 2" + gem "rack-livereload" gem "rubocop", require: false gem "seed_dump" gem "solargraph-reek" gem "spring" + # gem "web-console" + # gem 'reek', require: false end -group "test" do +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem "byebug", platform: :mri + gem "dotenv-rails" + gem "factory_bot_rails" + gem "parallel_tests" + gem "rack-mini-profiler" + gem "rspec-rails", "~> 6.0.3" +end + +group :test do gem "capybara" gem "cuprite" gem "database_cleaner" gem "launchy" gem "rails-controller-testing" gem "simplecov", require: false - gem "timecop" + # gem "timecop" end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby] # gem "reline", "~> 0.3.2" - -gem "csv", "~> 3.3" - -gem "observer", "~> 0.1.2" diff --git a/Gemfile.lock b/Gemfile.lock index 052b45e1..5529c009 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -465,7 +465,6 @@ GEM strscan (3.1.0) thor (1.3.1) tilt (2.3.0) - timecop (0.9.8) timeout (0.4.1) trollop (2.9.10) turbo-rails (1.5.0) @@ -545,7 +544,6 @@ DEPENDENCIES sprockets-rails standard_deviation stimulus-rails - timecop turbo-rails tzinfo-data watir diff --git a/app/controllers/analyze_controller.rb b/app/controllers/analyze_controller.rb index f46fa907..d50837ea 100644 --- a/app/controllers/analyze_controller.rb +++ b/app/controllers/analyze_controller.rb @@ -4,5 +4,6 @@ class AnalyzeController < SqmApplicationController def index @presenter = Analyze::Presenter.new(params:, school: @school, academic_year: @academic_year) @background ||= BackgroundPresenter.new(num_of_columns: @presenter.graph.columns.count) + @academic_year = @presenter.selected_academic_years&.first || AcademicYear.last end end diff --git a/app/controllers/sqm_application_controller.rb b/app/controllers/sqm_application_controller.rb index 160756cd..38933500 100644 --- a/app/controllers/sqm_application_controller.rb +++ b/app/controllers/sqm_application_controller.rb @@ -12,8 +12,8 @@ class SqmApplicationController < ApplicationController @districts = District.all.order(:name) @school = School.find_by_slug(school_slug) @schools = School.includes([:district]).where(district: @district).order(:name) - @academic_year = AcademicYear.find_by_range params[:year] - @academic_years = AcademicYear.all.order(range: :desc) + @academic_year = AcademicYear.find_by_range params[:year] || AcademicYear.last + @academic_years = AcademicYear.all.order(range: :desc) || [AcademicYear.last] end def district_slug diff --git a/app/helpers/header_helper.rb b/app/helpers/header_helper.rb index e9e5bef5..95e35340 100644 --- a/app/helpers/header_helper.rb +++ b/app/helpers/header_helper.rb @@ -11,7 +11,7 @@ module HeaderHelper def link_to_analyze(district:, school:, academic_year:) year = academic_year.range - "/districts/#{district.slug}/schools/#{school.slug}/analyze?year=#{year}&category=1&academic_years=#{year}" + "/districts/#{district.slug}/schools/#{school.slug}/analyze?category=1&academic_year-1=#{year}" end def district_url_for(district:, academic_year:) @@ -35,7 +35,7 @@ module HeaderHelper end def link_weight(path:) - active?(path:) ? 'weight-700' : 'weight-400' + active?(path:) ? "weight-700" : "weight-400" end private diff --git a/app/javascript/controllers/analyze_controller.js b/app/javascript/controllers/analyze_controller.js index e839be5f..45ea0905 100644 --- a/app/javascript/controllers/analyze_controller.js +++ b/app/javascript/controllers/analyze_controller.js @@ -1,152 +1,25 @@ import { Controller } from "@hotwired/stimulus"; +import debounce from "debounce"; // Connects to data-controller="analyze" export default class extends Controller { - connect() { } - refresh(event) { - let base_url = event.target.value; - let target = event.target; - console.log(this.selected_slice(target)) - console.log(target.name) + static targets = ["category", "subcategory"] - let url = - base_url + - "&academic_years=" + - this.selected_years().join(",") + - "&source=" + - this.selected_source(target) + - "&slice=" + - this.selected_slice(target) + - "&group=" + - this.selected_group() + - "&graph=" + - this.selected_graph(target) + - "&races=" + - this.selected_items("race").join(",") + - "&genders=" + - this.selected_items("gender").join(",") + - "&incomes=" + - this.selected_items("income").join(",") + - "&grades=" + - this.selected_items("grade").join(",") + - "&ells=" + - this.selected_items("ell").join(",") + - "&speds=" + - this.selected_items("sped").join(","); - - this.go_to(url); - } - - go_to(location) { - window.location = location; - } - - selected_years() { - let year_checkboxes = [...document.getElementsByName("year-checkbox")]; - let years = year_checkboxes - .filter((item) => { - return item.checked; - }) - .map((item) => { - return item.id; - }); - - return years; + initialize() { + this.submit = debounce(this.submit.bind(this), 300) } - selected_group() { - let groups = [...document.getElementsByName("group-option")]; - let selected_group = groups - .filter((item) => { - return item.selected; - }) - .map((item) => { - return item.id; - }); - - return selected_group[0]; - } + connect() { + const collection = document.getElementsByClassName("popover"); - selected_source(target) { - if (target.name === 'source') { - return target.id; + for (let i = 0; i < collection.length; i++) { + collection[i].parentNode.removeChild(collection[i]); } - if (target.name === 'slice' || target.name === 'group') { - return 'survey-data-only'; - } - - return window.source; - } - - selected_slice(target) { - if (target.name === 'source' && target.id === 'all-data') { - return 'all-data'; - } - if (target.name === 'source' && target.id === 'survey-data-only') { - return 'students-and-teachers'; - } - - if (target.name === 'group') { - return 'students-by-group'; - } - - if (target.name === 'source' || target.name === 'slice') { - let slices = [...document.getElementsByName("slice")]; - let selected_slice = slices - .filter((item) => { - return item.id != "all-data"; - }) - .filter((item) => { - return item.checked; - }) - .map((item) => { - return item.id; - }); - - return selected_slice[0]; - } - - return window.slice; - } - - selected_graph(target) { - if (target.name === 'source' && target.id === 'all-data') { - return 'all-data' - } - if (target.name === 'source' && target.id === 'survey-data-only') { - return 'students-and-teachers' - } - - let graphs = [...document.getElementsByName("slice")]; - let selected_slice = graphs - .filter((item) => { - return item.checked; - }) - .map((item) => { - return item.id; - })[0]; - - if (target.name === 'slice' || target.name === 'group') { - if (selected_slice === 'students-and-teachers') { - return 'students-and-teachers'; - } - return `students-by-${this.selected_group()}`; - } - - return window.graph; - } - selected_items(type) { - let checkboxes = [...document.getElementsByName(`${type}-checkbox`)] - let items = checkboxes - .filter((item) => { - return item.checked; - }) - .map((item) => { - return item.id.replace(`${type}-`, ''); - }); + submit() { + console.log("Submitting form"); - return items; + this.element.requestSubmit(); } } diff --git a/app/models/academic_year.rb b/app/models/academic_year.rb index 8e7d1f24..bc21609b 100644 --- a/app/models/academic_year.rb +++ b/app/models/academic_year.rb @@ -3,6 +3,9 @@ require "date" class AcademicYear < ActiveRecord::Base + include FriendlyId + friendly_id :range, use: [:slugged] + scope :by_range, -> { all.map { |academic_year| [academic_year.range, academic_year] }.to_h } scope :of_year, ->(range) { all.select { |ay| ay.range.start_with?(range) } } diff --git a/app/models/gender.rb b/app/models/gender.rb index a8b7f40d..8b95985b 100644 --- a/app/models/gender.rb +++ b/app/models/gender.rb @@ -1,4 +1,7 @@ class Gender < ApplicationRecord + include FriendlyId + friendly_id :designation, use: [:slugged] + scope :by_qualtrics_code, lambda { all.map { |gender| [gender.qualtrics_code, gender] }.to_h } diff --git a/app/presenters/analyze/graph/all_data.rb b/app/presenters/analyze/graph/all_data.rb index 7bd83ef2..93a9bd50 100644 --- a/app/presenters/analyze/graph/all_data.rb +++ b/app/presenters/analyze/graph/all_data.rb @@ -4,6 +4,7 @@ module Analyze module Graph class AllData include Analyze::Graph::Column + def to_s %w[All Data] end @@ -15,6 +16,14 @@ module Analyze def columns [AllStudent, AllTeacher, AllAdmin, GroupedBarColumnPresenter] end + + def source + Analyze::Source::AllData.new(slices: [slice]) + end + + def slice + Analyze::Slice::AllData.new + end end end end diff --git a/app/presenters/analyze/graph/column/all_teacher.rb b/app/presenters/analyze/graph/column/all_teacher.rb index d4bbdf7b..15f665f3 100644 --- a/app/presenters/analyze/graph/column/all_teacher.rb +++ b/app/presenters/analyze/graph/column/all_teacher.rb @@ -32,9 +32,9 @@ module Analyze :teacher end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(survey_item: measure.teacher_survey_items, school:, - academic_year: academic_years[year_index]).count + academic_year:).pluck(:response_id).uniq.count end end end diff --git a/app/presenters/analyze/graph/column/ell_column/ell_count.rb b/app/presenters/analyze/graph/column/ell_column/ell_count.rb index 66c0ca79..582d7221 100644 --- a/app/presenters/analyze/graph/column/ell_column/ell_count.rb +++ b/app/presenters/analyze/graph/column/ell_column/ell_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(ell:, survey_item: measure.student_survey_items, school:, grade: grades, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count end end end diff --git a/app/presenters/analyze/graph/column/gender_column/gender_count.rb b/app/presenters/analyze/graph/column/gender_column/gender_count.rb index 874c7cde..ad0c4e72 100644 --- a/app/presenters/analyze/graph/column/gender_column/gender_count.rb +++ b/app/presenters/analyze/graph/column/gender_column/gender_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(gender:, survey_item: measure.student_survey_items, school:, grade: grades, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count end end end diff --git a/app/presenters/analyze/graph/column/grade/grade_count.rb b/app/presenters/analyze/graph/column/grade/grade_count.rb index 42ed3a23..a12aeba7 100644 --- a/app/presenters/analyze/graph/column/grade/grade_count.rb +++ b/app/presenters/analyze/graph/column/grade/grade_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(grade:, survey_item: measure.student_survey_items, school:, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count 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 8277f38d..450ad4b9 100644 --- a/app/presenters/analyze/graph/column/grouped_bar_column_presenter.rb +++ b/app/presenters/analyze/graph/column/grouped_bar_column_presenter.rb @@ -113,13 +113,13 @@ module Analyze %i[student teacher].include? type end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(survey_item: measure.student_survey_items, school:, grade: grades, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count end - def popover_content(year_index) - "#{n_size(year_index)} #{type.to_s.capitalize}s" + def popover_content(academic_year) + "#{n_size(academic_year)} #{type.to_s.capitalize}s" end def insufficiency_message diff --git a/app/presenters/analyze/graph/column/income_column/income_count.rb b/app/presenters/analyze/graph/column/income_column/income_count.rb index a61bdc61..886459d1 100644 --- a/app/presenters/analyze/graph/column/income_column/income_count.rb +++ b/app/presenters/analyze/graph/column/income_column/income_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(income:, survey_item: measure.student_survey_items, school:, grade: grades, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count end end end diff --git a/app/presenters/analyze/graph/column/race_column/race_count.rb b/app/presenters/analyze/graph/column/race_column/race_count.rb index b46d3de1..17a59f55 100644 --- a/app/presenters/analyze/graph/column/race_column/race_count.rb +++ b/app/presenters/analyze/graph/column/race_column/race_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.joins("JOIN student_races on survey_item_responses.student_id = student_races.student_id JOIN students on students.id = student_races.student_id").where( - school:, academic_year: academic_years[year_index], + school:, academic_year:, survey_item: measure.student_survey_items ).where("student_races.race_id": race.id).select(:response_id).distinct.count end diff --git a/app/presenters/analyze/graph/column/sped_column/sped_count.rb b/app/presenters/analyze/graph/column/sped_column/sped_count.rb index 61975708..eb88311a 100644 --- a/app/presenters/analyze/graph/column/sped_column/sped_count.rb +++ b/app/presenters/analyze/graph/column/sped_column/sped_count.rb @@ -7,9 +7,9 @@ module Analyze :student end - def n_size(year_index) + def n_size(academic_year) SurveyItemResponse.where(sped:, survey_item: measure.student_survey_items, school:, grade: grades, - academic_year: academic_years[year_index]).select(:response_id).distinct.count + academic_year:).select(:response_id).distinct.count end end end diff --git a/app/presenters/analyze/graph/students_and_teachers.rb b/app/presenters/analyze/graph/students_and_teachers.rb index 482f817e..8d29538b 100644 --- a/app/presenters/analyze/graph/students_and_teachers.rb +++ b/app/presenters/analyze/graph/students_and_teachers.rb @@ -5,16 +5,24 @@ module Analyze class StudentsAndTeachers include Analyze::Graph::Column def to_s - 'Students & Teachers' + "Students & Teachers" end def slug - 'students-and-teachers' + "students-and-teachers" end def columns [AllStudent, AllTeacher, AllSurveyData] end + + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsAndTeachers.new + end end end end diff --git a/app/presenters/analyze/graph/students_by_ell.rb b/app/presenters/analyze/graph/students_by_ell.rb index 7431faad..1188d405 100644 --- a/app/presenters/analyze/graph/students_by_ell.rb +++ b/app/presenters/analyze/graph/students_by_ell.rb @@ -28,6 +28,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_ell_code(code:) diff --git a/app/presenters/analyze/graph/students_by_gender.rb b/app/presenters/analyze/graph/students_by_gender.rb index 97d33634..ccd1d2a5 100644 --- a/app/presenters/analyze/graph/students_by_gender.rb +++ b/app/presenters/analyze/graph/students_by_gender.rb @@ -28,6 +28,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_gender_code(code:) diff --git a/app/presenters/analyze/graph/students_by_grade.rb b/app/presenters/analyze/graph/students_by_grade.rb index a59e71b6..1723e240 100644 --- a/app/presenters/analyze/graph/students_by_grade.rb +++ b/app/presenters/analyze/graph/students_by_grade.rb @@ -27,6 +27,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_grade_code(code:) diff --git a/app/presenters/analyze/graph/students_by_income.rb b/app/presenters/analyze/graph/students_by_income.rb index e72b6efb..d28be884 100644 --- a/app/presenters/analyze/graph/students_by_income.rb +++ b/app/presenters/analyze/graph/students_by_income.rb @@ -26,6 +26,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_income_code(code:) diff --git a/app/presenters/analyze/graph/students_by_race.rb b/app/presenters/analyze/graph/students_by_race.rb index 74a7cb8f..d3e3507c 100644 --- a/app/presenters/analyze/graph/students_by_race.rb +++ b/app/presenters/analyze/graph/students_by_race.rb @@ -26,6 +26,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_race_code(code:) diff --git a/app/presenters/analyze/graph/students_by_sped.rb b/app/presenters/analyze/graph/students_by_sped.rb index 6129d62c..bc5c4289 100644 --- a/app/presenters/analyze/graph/students_by_sped.rb +++ b/app/presenters/analyze/graph/students_by_sped.rb @@ -27,6 +27,14 @@ module Analyze end end + def source + Analyze::Source::SurveyData.new(slices: nil) + end + + def slice + Analyze::Slice::StudentsByGroup.new + end + private def column_for_sped_code(code:) diff --git a/app/presenters/analyze/group/ell.rb b/app/presenters/analyze/group/ell.rb index 512b3d5b..628ef0ca 100644 --- a/app/presenters/analyze/group/ell.rb +++ b/app/presenters/analyze/group/ell.rb @@ -8,6 +8,10 @@ module Analyze def slug "ell" end + + def graph + Analyze::Graph::StudentsByEll.new(ells: nil) + end end end end diff --git a/app/presenters/analyze/group/gender.rb b/app/presenters/analyze/group/gender.rb index 901d24d8..9810d893 100644 --- a/app/presenters/analyze/group/gender.rb +++ b/app/presenters/analyze/group/gender.rb @@ -2,11 +2,15 @@ module Analyze module Group class Gender def name - 'Gender' + "Gender" end def slug - 'gender' + "gender" + end + + def graph + Analyze::Graph::StudentsByGender.new(genders: nil) end end end diff --git a/app/presenters/analyze/group/grade.rb b/app/presenters/analyze/group/grade.rb index 9504469c..67149012 100644 --- a/app/presenters/analyze/group/grade.rb +++ b/app/presenters/analyze/group/grade.rb @@ -2,11 +2,15 @@ module Analyze module Group class Grade def name - 'Grade' + "Grade" end def slug - 'grade' + "grade" + end + + def graph + Analyze::Graph::StudentsByGrade.new(grades: nil) end end end diff --git a/app/presenters/analyze/group/income.rb b/app/presenters/analyze/group/income.rb index 21e364b4..74ba80c0 100644 --- a/app/presenters/analyze/group/income.rb +++ b/app/presenters/analyze/group/income.rb @@ -2,11 +2,15 @@ module Analyze module Group class Income def name - 'Income' + "Income" end def slug - 'income' + "income" + end + + def graph + Analyze::Graph::StudentsByIncome.new(incomes: nil) end end end diff --git a/app/presenters/analyze/group/race.rb b/app/presenters/analyze/group/race.rb index 1155d1c4..fec01545 100644 --- a/app/presenters/analyze/group/race.rb +++ b/app/presenters/analyze/group/race.rb @@ -2,11 +2,15 @@ module Analyze module Group class Race def name - 'Race' + "Race" end def slug - 'race' + "race" + end + + def graph + Analyze::Graph::StudentsByRace.new(races: nil) end end end diff --git a/app/presenters/analyze/group/sped.rb b/app/presenters/analyze/group/sped.rb index a4ac896b..7de07d53 100644 --- a/app/presenters/analyze/group/sped.rb +++ b/app/presenters/analyze/group/sped.rb @@ -8,6 +8,10 @@ module Analyze def slug "sped" end + + def graph + Analyze::Graph::StudentsBySped.new(speds: nil) + end end end end diff --git a/app/presenters/analyze/presenter.rb b/app/presenters/analyze/presenter.rb index 9f0593b7..d67d51c1 100644 --- a/app/presenters/analyze/presenter.rb +++ b/app/presenters/analyze/presenter.rb @@ -5,7 +5,6 @@ module Analyze def initialize(params:, school:, academic_year:) @params = params @school = school - @academic_year = academic_year end def category @@ -34,10 +33,16 @@ module Analyze def selected_academic_years @selected_academic_years ||= begin - year_params = params[:academic_years] - return [] unless year_params + array = [] - year_params.split(",").map { |year| AcademicYear.find_by_range(year) }.compact + keys = params.keys.select { |key| key.start_with? "academic_year" } + keys.each do |key| + year_params = params[key]&.chomp + next if year_params.nil? + + array << AcademicYear.find_by_range(year_params) + end + array end end @@ -46,12 +51,7 @@ module Analyze end def selected_races - @selected_races ||= begin - race_params = params[:races] - return races unless race_params - - race_params.split(",").map { |race| Race.find_by_slug race }.compact - end + @selected_races ||= selected_items(name: "race", list: races) end def ells @@ -59,12 +59,15 @@ module Analyze end def selected_ells - @selected_ells ||= begin - ell_params = params[:ells] - return ells unless ell_params + @selected_ells ||= selected_items(name: "ell", list: ells) + end - ell_params.split(",").map { |ell| Ell.find_by_slug ell }.compact - end + def selected_items(name:, list:) + selected_params = params.select { |key, _| key.start_with?(name) && key.end_with?("checkbox") } + return list unless selected_params.keys.length.positive? + + selected_params.values + .map { |slug| list.find { |item| item.slug == slug } } end def speds @@ -72,47 +75,20 @@ module Analyze end def selected_speds - @selected_speds ||= begin - sped_params = params[:speds] - return speds unless sped_params - - sped_params.split(",").map { |sped| Sped.find_by_slug sped }.compact - end - end - - def graphs - @graphs ||= [Analyze::Graph::AllData.new, - Analyze::Graph::StudentsAndTeachers.new, - Analyze::Graph::StudentsByRace.new(races: selected_races), - Analyze::Graph::StudentsByGrade.new(grades:), - Analyze::Graph::StudentsByGender.new(genders: selected_genders), - Analyze::Graph::StudentsByIncome.new(incomes: selected_incomes), - Analyze::Graph::StudentsByEll.new(ells: selected_ells), - Analyze::Graph::StudentsBySped.new(speds: selected_speds)] - end - - def graph - @graph ||= graphs.reduce(graphs.first) do |acc, graph| - graph.slug == params[:graph] ? graph : acc - end + @selected_speds ||= selected_items(name: "sped", list: speds) end def selected_grades @selected_grades ||= begin - grade_params = params[:grades] - return grades unless grade_params + selected_params = params.select { |key, _| key.start_with?("grade") && key.end_with?("checkbox") } + return grades unless selected_params.keys.length.positive? - grade_params.split(",").map(&:to_i) + selected_params.values.map(&:to_i) end end def selected_genders - @selected_genders ||= begin - gender_params = params[:genders] - return genders unless gender_params - - gender_params.split(",").sort.map { |gender| Gender.find_by_designation(gender) }.compact - end + @selected_genders ||= selected_items(name: "gender", list: genders) end def genders @@ -131,33 +107,53 @@ module Analyze end def slice - @slice ||= slices.reduce(slices.first) do |acc, slice| - slice.slug == params[:slice] ? slice : acc - end + @slice ||= graph.slice || slices.first end def slices - source.slices + graphs.map { |graph| graph.slice }.uniq end def source - @source ||= sources.reduce(sources.first) do |acc, source| - source.slug == params[:source] ? source : acc - end + @source ||= graph&.source || sources.first end def sources - all_data_slices = [Analyze::Slice::AllData.new] + all_data_slice = Analyze::Slice::AllData.new + all_data_slice.graph = Analyze::Graph::AllData.new + all_data_slices = [all_data_slice] + all_data_source = Analyze::Source::AllData.new(slices: all_data_slices) + all_data_source.graph = Analyze::Graph::AllData.new students_and_teachers = Analyze::Slice::StudentsAndTeachers.new - students_by_group = Analyze::Slice::StudentsByGroup.new(races:, grades:) + students_by_group = Analyze::Slice::StudentsByGroup.new + students_by_group.graph = Analyze::Graph::StudentsByEll.new(ells: selected_ells) + survey_data_slices = [students_and_teachers, students_by_group] survey_data_source = Analyze::Source::SurveyData.new(slices: survey_data_slices) + survey_data_source.graph = Analyze::Graph::StudentsAndTeachers.new @sources = [all_data_source, survey_data_source] end + def graphs + @graphs ||= [Analyze::Graph::AllData.new, + Analyze::Graph::StudentsAndTeachers.new, + Analyze::Graph::StudentsByRace.new(races: selected_races), + Analyze::Graph::StudentsByGrade.new(grades: selected_grades), + Analyze::Graph::StudentsByGender.new(genders: selected_genders), + Analyze::Graph::StudentsByIncome.new(incomes: selected_incomes), + Analyze::Graph::StudentsByEll.new(ells: selected_ells), + Analyze::Graph::StudentsBySped.new(speds: selected_speds)] + end + + def graph + @graph ||= graphs.find do |graph| + graph.slug == params[:graph] + end || graphs.first + end + def grades @grades ||= SurveyItemResponse.where(school:, academic_year: academic_years) .where.not(grade: nil) @@ -180,16 +176,12 @@ module Analyze end def selected_incomes - @selected_incomes ||= begin - income_params = params[:incomes] - return incomes unless income_params - - income_params.split(",").map { |income| Income.find_by_slug(income) }.compact - end + @selected_incomes ||= selected_items(name: "income", list: incomes) end def cache_objects - [subcategory, + [category, + subcategory, selected_academic_years, graph, selected_races, diff --git a/app/presenters/analyze/slice/all_data.rb b/app/presenters/analyze/slice/all_data.rb index 10137a78..326af4b2 100644 --- a/app/presenters/analyze/slice/all_data.rb +++ b/app/presenters/analyze/slice/all_data.rb @@ -1,16 +1,14 @@ module Analyze module Slice class AllData + attr_accessor :graph + def to_s - 'All Data' + "All Data" end def slug - 'all-data' - end - - def graphs - [Analyze::Graph::AllData.new] + "all-data" end end end diff --git a/app/presenters/analyze/slice/students_and_teachers.rb b/app/presenters/analyze/slice/students_and_teachers.rb index 75eb921b..e14ef29e 100644 --- a/app/presenters/analyze/slice/students_and_teachers.rb +++ b/app/presenters/analyze/slice/students_and_teachers.rb @@ -2,15 +2,15 @@ module Analyze module Slice class StudentsAndTeachers def to_s - 'Students & Teachers' + "Students & Teachers" end def slug - 'students-and-teachers' + "students-and-teachers" end - def graphs - [Analyze::Graph::StudentsAndTeachers.new] + def graph + Analyze::Graph::StudentsAndTeachers.new end end end diff --git a/app/presenters/analyze/slice/students_by_group.rb b/app/presenters/analyze/slice/students_by_group.rb index af62be61..ae91d060 100644 --- a/app/presenters/analyze/slice/students_by_group.rb +++ b/app/presenters/analyze/slice/students_by_group.rb @@ -1,23 +1,14 @@ module Analyze module Slice class StudentsByGroup - attr_reader :races, :grades - - def initialize(races:, grades:) - @races = races - @grades = grades - end + attr_accessor :graph def to_s - 'Students by Group' + "Students by Group" end def slug - 'students-by-group' - end - - def graphs - [Analyze::Graph::StudentsByRace.new(races:), Analyze::Graph::StudentsByGrade.new(grades:)] + "students-by-group" end end end diff --git a/app/presenters/analyze/source/all_data.rb b/app/presenters/analyze/source/all_data.rb index 72889904..181a8947 100644 --- a/app/presenters/analyze/source/all_data.rb +++ b/app/presenters/analyze/source/all_data.rb @@ -2,6 +2,7 @@ module Analyze module Source class AllData attr_reader :slices + attr_accessor :graph include Analyze::Slice @@ -10,11 +11,11 @@ module Analyze end def to_s - 'All Data' + "All Data" end def slug - 'all-data' + "all-data" end end end diff --git a/app/presenters/analyze/source/survey_data.rb b/app/presenters/analyze/source/survey_data.rb index 654020b6..8510999f 100644 --- a/app/presenters/analyze/source/survey_data.rb +++ b/app/presenters/analyze/source/survey_data.rb @@ -2,6 +2,7 @@ module Analyze module Source class SurveyData attr_reader :slices + attr_accessor :graph include Analyze::Slice @@ -10,11 +11,11 @@ module Analyze end def to_s - 'Survey Data Only' + "Survey Data Only" end def slug - 'survey-data-only' + "survey-data-only" end end end diff --git a/app/views/analyze/_checkboxes.html.erb b/app/views/analyze/_checkboxes.html.erb index d64d7e6b..eba16e09 100644 --- a/app/views/analyze/_checkboxes.html.erb +++ b/app/views/analyze/_checkboxes.html.erb @@ -1,17 +1,13 @@
Select a category & subcategory to analyze measure-level results
- - + +Select a group
+Select a group
+ +<% if @presenter.graph.slug == 'students-by-race' %> + <% @presenter.races.each_with_index do |race, index| %> + <%= render(partial: "checkboxes", locals: {id: "race-#{}#{race.slug}", item: race.slug, selected_items: @presenter.selected_races.map(&:slug), name: "race", label_text: race.designation, index: index })%> + <% end %> +<% end %> -<% @presenter.races.each do |race| %> - <%= render(partial: "checkboxes", locals: {id: "race-#{race.slug}", item: race, selected_items: @presenter.selected_races, name: "race", label_text: race.designation}) %> +<% if @presenter.graph.slug == 'students-by-grade' %> + <% @presenter.grades.each_with_index do |grade, index| %> + <%= render(partial: "checkboxes", locals: {id: "grade-#{grade}", item: grade, selected_items: @presenter.selected_grades, name: "grade", label_text: grade, index: index }) %> + <% end %> <% end %> -<% @presenter.grades.each do |grade| %> - <%= render(partial: "checkboxes", locals: {id: "grade-#{grade}", item: grade, selected_items: @presenter.selected_grades, name: "grade", label_text: grade}) %> +<% if @presenter.graph.slug == 'students-by-gender' %> + <% @presenter.genders.each_with_index do |gender, index| %> + <%= render(partial: "checkboxes", locals: {id: "gender-#{gender.designation}", item: gender.slug, selected_items: @presenter.selected_genders.map(&:slug), name: "gender", label_text: gender.designation, index: index }) %> + <% end %> <% end %> -<% @presenter.genders.each do |gender| %> - <%= render(partial: "checkboxes", locals: {id: "gender-#{gender.designation}", item: gender, selected_items: @presenter.selected_genders, name: "gender", label_text: gender.designation}) %> +<% if @presenter.graph.slug == 'students-by-income' %> + <% @presenter.incomes.each_with_index do |income, index| %> + <%= render(partial: "checkboxes", locals: {id: "income-#{income.slug}", item: income.slug, selected_items: @presenter.selected_incomes.map(&:slug), name: "income", label_text: income.label, index: index })%> + <% end %> <% end %> -<% @presenter.incomes.each do |income| %> - <%= render(partial: "checkboxes", locals: {id: "income-#{income.slug}", item: income, selected_items: @presenter.selected_incomes, name: "income", label_text: income.label}) %> +<% if @presenter.graph.slug == 'students-by-ell' %> + <% @presenter.ells.each_with_index do |ell, index| %> + <%= render(partial: "checkboxes", locals: {id: "ell-#{ell.slug}", item: ell.slug, selected_items: @presenter.selected_ells.map(&:slug), name: "ell", label_text: ell.designation, index: index}) %> + <% end %> <% end %> -<% @presenter.ells.each do |ell| %> - <%= render(partial: "checkboxes", locals: {id: "ell-#{ell.slug}", item: ell, selected_items: @presenter.selected_ells, name: "ell", label_text: ell.designation}) %> +<% if @presenter.graph.slug == 'students-by-sped' %> + <% @presenter.speds.each_with_index do |sped, index| %> + <%= render(partial: "checkboxes", locals: {id: "sped-#{sped.slug}", item: sped.slug, selected_items: @presenter.selected_speds.map(&:slug), name: "sped", label_text: sped.designation, index: index}) %> + <% end %> <% end %> -<% @presenter.speds.each do |sped| %> - <%= render(partial: "checkboxes", locals: {id: "sped-#{sped.slug}", item: sped, selected_items: @presenter.selected_speds, name: "sped", label_text: sped.designation}) %> <% end %> diff --git a/app/views/analyze/_grouped_bar_chart.html.erb b/app/views/analyze/_grouped_bar_chart.html.erb index 47feb8eb..944cde5a 100644 --- a/app/views/analyze/_grouped_bar_chart.html.erb +++ b/app/views/analyze/_grouped_bar_chart.html.erb @@ -6,5 +6,4 @@ <% p = column.new(measure: measure, school: @school, academic_years: @presenter.selected_academic_years, position: index , number_of_columns:) %> <%= render partial: "grouped_bar_column", locals: {column: p} %> <% end %> - diff --git a/app/views/analyze/_grouped_bar_column.html.erb b/app/views/analyze/_grouped_bar_column.html.erb index 17bce6f4..2970e436 100644 --- a/app/views/analyze/_grouped_bar_column.html.erb +++ b/app/views/analyze/_grouped_bar_column.html.erb @@ -5,7 +5,7 @@ <% if column.show_popover? %> data-bs-toggle="popover" data-bs-placement="right" - data-bs-content="<%= column.popover_content(index) %>" + data-bs-content="<%= column.popover_content(bar.academic_year) %>" <% end %> data-for-academic-year="<%= bar.academic_year.range %>" diff --git a/app/views/analyze/_school_years.html.erb b/app/views/analyze/_school_years.html.erb index 968000ce..3b7b432a 100644 --- a/app/views/analyze/_school_years.html.erb +++ b/app/views/analyze/_school_years.html.erb @@ -1,13 +1,24 @@ +<%= form_with(url: district_school_analyze_index_path, + method: :get, + data: { + turbo_frame: "results", + turbo_action: "advance", + controller: "form", + action: "input->form#submit" + }) do |f| %> + <% params.reject{|key,_| key.start_with?("academic_year")}.each do |key, value| %> + +<% end %> +Measure <%= measure.measure_id %>
-Measure <%= measure.measure_id %>
+