diff --git a/app/controllers/analyze_controller.rb b/app/controllers/analyze_controller.rb index 49292472..3fd5b5be 100644 --- a/app/controllers/analyze_controller.rb +++ b/app/controllers/analyze_controller.rb @@ -5,5 +5,8 @@ class AnalyzeController < SqmApplicationController @subcategory ||= Subcategory.find_by_subcategory_id(params[:subcategory_id]) @subcategory ||= Subcategory.find_by_subcategory_id('1A') + + @measure = @subcategory.measures.first + @academic_year ||= AcademicYear.order('range DESC').first end end diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 8ba4ebd3..ad84a669 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,4 +1,5 @@ class CategoriesController < SqmApplicationController + helper GaugeHelper def show @categories = Category.sorted.map { |category| CategoryPresenter.new(category:) } diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 744ec810..4e02ecb6 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,4 +1,5 @@ class HomeController < ApplicationController + helper HeaderHelper def index @districts = District.all.order(:name) @schools = School.all.includes([:district]).order(:name) diff --git a/app/controllers/overview_controller.rb b/app/controllers/overview_controller.rb index 346fefbe..b05c6413 100644 --- a/app/controllers/overview_controller.rb +++ b/app/controllers/overview_controller.rb @@ -1,5 +1,6 @@ class OverviewController < SqmApplicationController before_action :check_empty_dataset, only: [:index] + helper VarianceHelper def index @variance_chart_row_presenters = Measure.all.map(&method(:presenter_for_measure)) diff --git a/app/controllers/sqm_application_controller.rb b/app/controllers/sqm_application_controller.rb index 3422e325..c0061866 100644 --- a/app/controllers/sqm_application_controller.rb +++ b/app/controllers/sqm_application_controller.rb @@ -1,6 +1,7 @@ class SqmApplicationController < ApplicationController protect_from_forgery with: :exception, prepend: true before_action :set_schools_and_districts + helper HeaderHelper private diff --git a/app/helpers/analyze_helper.rb b/app/helpers/analyze_helper.rb new file mode 100644 index 00000000..25b5cfd7 --- /dev/null +++ b/app/helpers/analyze_helper.rb @@ -0,0 +1,57 @@ +module AnalyzeHelper + def zone_label_width + 15 + end + + def zone_label_x + 2 + end + + def graph_height + 85 + end + + def svg_height + 400 + end + + def graph_width + 85 + end + + def benchmark_y + (zone_height * 2) - (benchmark_height / 2.0) + end + + def benchmark_height + 1 + end + + def grouped_chart_width + graph_width / data_sources + end + + def grouped_chart_divider_x(position) + zone_label_width + (grouped_chart_width * position) + end + + def bar_label_height + (100 - ((100 - graph_height) / 2)) + end + + def bar_label_x(position) + zone_label_width + (grouped_chart_width * position) - (grouped_chart_width / 2) + end + + def zone_height + graph_height / 5 + end + + def zone_label_y(position) + 8.5 * (position + position - 1) + end + + def data_sources + 3 + end +end diff --git a/app/models/measure.rb b/app/models/measure.rb index f50df8d2..5cd0b3e0 100644 --- a/app/models/measure.rb +++ b/app/models/measure.rb @@ -135,7 +135,6 @@ class Measure < ActiveRecord::Base averages << student_survey_items.first.send(name) if includes_student_survey_items? averages << teacher_survey_items.first.send(name) if includes_teacher_survey_items? (averages << admin_data_items.map(&name)).flatten! if includes_admin_data_items? - averages.average end end diff --git a/app/models/survey_item_response.rb b/app/models/survey_item_response.rb index 966a5aaa..13e685dc 100644 --- a/app/models/survey_item_response.rb +++ b/app/models/survey_item_response.rb @@ -7,7 +7,7 @@ class SurveyItemResponse < ActiveRecord::Base belongs_to :survey_item scope :exclude_boston, lambda { - boston = District.where(name: 'Boston').first + boston = District.find_by_name('Boston') where.not(school: boston.schools) if boston.present? } end diff --git a/app/presenters/grouped_bar_chart_presenter.rb b/app/presenters/grouped_bar_chart_presenter.rb new file mode 100644 index 00000000..2a7fcb4d --- /dev/null +++ b/app/presenters/grouped_bar_chart_presenter.rb @@ -0,0 +1,59 @@ +class GroupedBarChartPresenter + attr_reader :score + + def initialize(measure:, score:) + @measure = measure + @score = score.average + @meets_teacher_threshold = score.meets_teacher_threshold? + @meets_student_threshold = score.meets_student_threshold? + @measure_name = @measure.name + @measure_id = @measure.measure_id + @category = @measure.subcategory.category + end + + IDEAL_ZONE_WIDTH_PERCENTAGE = 0.17 + APPROVAL_ZONE_WIDTH_PERCENTAGE = 0.17 + GROWTH_ZONE_WIDTH_PERCENTAGE = 0.17 + WATCH_ZONE_WIDTH_PERCENTAGE = 0.17 + WARNING_ZONE_WIDTH_PERCENTAGE = 0.17 + + def y_offset + case zone.type + when :ideal, :approval + 34 - bar_height_percentage * 100 + else + 34 + end + end + + def bar_height_percentage + case zone.type + when :ideal + percentage * IDEAL_ZONE_WIDTH_PERCENTAGE + APPROVAL_ZONE_WIDTH_PERCENTAGE + when :approval + percentage * APPROVAL_ZONE_WIDTH_PERCENTAGE + when :growth + (1 - percentage) * GROWTH_ZONE_WIDTH_PERCENTAGE + when :watch + (1 - percentage) * WATCH_ZONE_WIDTH_PERCENTAGE + GROWTH_ZONE_WIDTH_PERCENTAGE + when :warning + (1 - percentage) * WARNING_ZONE_WIDTH_PERCENTAGE + WATCH_ZONE_WIDTH_PERCENTAGE + GROWTH_ZONE_WIDTH_PERCENTAGE + else + 0.0 + end + end + + def percentage + (@score - zone.low_benchmark) / (zone.high_benchmark - zone.low_benchmark) + end + + def zone + zones = Zones.new( + watch_low_benchmark: @measure.watch_low_benchmark, + growth_low_benchmark: @measure.growth_low_benchmark, + approval_low_benchmark: @measure.approval_low_benchmark, + ideal_low_benchmark: @measure.ideal_low_benchmark + ) + zones.zone_for_score(@score) + end +end diff --git a/app/views/analyze/index.html.erb b/app/views/analyze/index.html.erb index c80be234..a4c5073b 100644 --- a/app/views/analyze/index.html.erb +++ b/app/views/analyze/index.html.erb @@ -1,9 +1,74 @@ <% content_for :title do %>