From f71f88a4acf845a4fac1018d80ab155080830554 Mon Sep 17 00:00:00 2001 From: Nelson Jovel Date: Fri, 26 Jan 2024 07:43:52 -0800 Subject: [PATCH] chore: start adding browse view --- .../dashboard/analyze_controller.rb | 10 +- .../dashboard/categories_controller.rb | 12 +- app/helpers/dashboard/gauge_helper.rb | 187 +++++++++--------- app/models/dashboard/race.rb | 4 +- app/models/dashboard/student.rb | 4 +- app/models/dashboard/survey_item_response.rb | 2 +- .../categories/_data_item_section.html.erb | 42 ++++ .../categories/_gauge_graph.html.erb | 59 ++++++ .../categories/_measures_section.html.erb | 12 ++ .../categories/_subcategory_section.html.erb | 59 ++++++ app/views/dashboard/categories/show.html.erb | 25 +++ .../dashboard/string_monkey_patches.rb | 7 + 12 files changed, 316 insertions(+), 107 deletions(-) create mode 100644 app/views/dashboard/categories/_data_item_section.html.erb create mode 100644 app/views/dashboard/categories/_gauge_graph.html.erb create mode 100644 app/views/dashboard/categories/_measures_section.html.erb create mode 100644 app/views/dashboard/categories/_subcategory_section.html.erb create mode 100644 app/views/dashboard/categories/show.html.erb create mode 100644 config/initializers/dashboard/string_monkey_patches.rb diff --git a/app/controllers/dashboard/analyze_controller.rb b/app/controllers/dashboard/analyze_controller.rb index f46fa90..ef02adf 100644 --- a/app/controllers/dashboard/analyze_controller.rb +++ b/app/controllers/dashboard/analyze_controller.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true -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) +module Dashboard + 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) + end end end diff --git a/app/controllers/dashboard/categories_controller.rb b/app/controllers/dashboard/categories_controller.rb index e44a57b..a87e8cd 100644 --- a/app/controllers/dashboard/categories_controller.rb +++ b/app/controllers/dashboard/categories_controller.rb @@ -1,11 +1,13 @@ # frozen_string_literal: true -class CategoriesController < SqmApplicationController - helper GaugeHelper +module Dashboard + class CategoriesController < SqmApplicationController + helper GaugeHelper - def show - @categories = Category.sorted.map { |category| CategoryPresenter.new(category:) } + def show + @categories = Category.sorted.map { |category| CategoryPresenter.new(category:) } - @category = CategoryPresenter.new(category: Category.find_by_slug(params[:id])) + @category = CategoryPresenter.new(category: Category.find_by_slug(params[:id])) + end end end diff --git a/app/helpers/dashboard/gauge_helper.rb b/app/helpers/dashboard/gauge_helper.rb index b596885..997decf 100644 --- a/app/helpers/dashboard/gauge_helper.rb +++ b/app/helpers/dashboard/gauge_helper.rb @@ -2,98 +2,99 @@ Point = Struct.new(:x, :y) Rect = Struct.new(:x, :y, :width, :height) - -module GaugeHelper - def outer_radius - 100 - end - - def inner_radius - 50 - end - - def stroke_width - 1 - end - - def effective_radius - outer_radius + stroke_width - end - - def diameter - 2 * effective_radius - end - - def width - diameter - end - - def height - outer_radius + 2 * stroke_width + key_benchmark_indicator_gutter - end - - def key_benchmark_indicator_gutter - 10 - end - - def viewbox - x = arc_center.x - effective_radius - y = arc_center.y - effective_radius - key_benchmark_indicator_gutter - Rect.new(x, y, width, height) - end - - def arc_center - Point.new(0, 0) - end - - def arc_radius(radius) - "#{radius} #{radius}" - end - - def angle_for(percentage:) - -Math::PI * (1 - percentage) - end - - def arc_end_point_for(radius:, percentage:) - angle = angle_for(percentage:) - - x = arc_center.x + radius * Math.cos(angle) - y = arc_center.y + radius * Math.sin(angle) - Point.new(x, y) - end - - def arc_end_line_destination(radius:, percentage:) - angle = angle_for(percentage:) - x = arc_center.x + radius * Math.cos(angle) - y = arc_center.y + radius * Math.sin(angle) - Point.new(x, y) - end - - def arc_start_point - Point.new(arc_center.x - outer_radius, arc_center.y) - end - - def move_to(point:) - "M #{coordinates_for(point)}" - end - - def draw_arc(radius:, percentage:, clockwise:) - sweep_flag = clockwise ? 1 : 0 - "A #{arc_radius(radius)} 0 0 #{sweep_flag} #{coordinates_for(arc_end_point_for(radius:, - percentage:))}" - end - - def draw_line_to(point:) - "L #{coordinates_for(point)}" - end - - def benchmark_line_point(radius, angle) - x = (radius * Math.cos(angle)).to_s - y = (radius * Math.sin(angle) + arc_center.y).to_s - Point.new(x, y) - end - - def coordinates_for(point) - "#{point.x} #{point.y}" +module Dashboard + module GaugeHelper + def outer_radius + 100 + end + + def inner_radius + 50 + end + + def stroke_width + 1 + end + + def effective_radius + outer_radius + stroke_width + end + + def diameter + 2 * effective_radius + end + + def width + diameter + end + + def height + outer_radius + 2 * stroke_width + key_benchmark_indicator_gutter + end + + def key_benchmark_indicator_gutter + 10 + end + + def viewbox + x = arc_center.x - effective_radius + y = arc_center.y - effective_radius - key_benchmark_indicator_gutter + Rect.new(x, y, width, height) + end + + def arc_center + Point.new(0, 0) + end + + def arc_radius(radius) + "#{radius} #{radius}" + end + + def angle_for(percentage:) + -Math::PI * (1 - percentage) + end + + def arc_end_point_for(radius:, percentage:) + angle = angle_for(percentage:) + + x = arc_center.x + radius * Math.cos(angle) + y = arc_center.y + radius * Math.sin(angle) + Point.new(x, y) + end + + def arc_end_line_destination(radius:, percentage:) + angle = angle_for(percentage:) + x = arc_center.x + radius * Math.cos(angle) + y = arc_center.y + radius * Math.sin(angle) + Point.new(x, y) + end + + def arc_start_point + Point.new(arc_center.x - outer_radius, arc_center.y) + end + + def move_to(point:) + "M #{coordinates_for(point)}" + end + + def draw_arc(radius:, percentage:, clockwise:) + sweep_flag = clockwise ? 1 : 0 + "A #{arc_radius(radius)} 0 0 #{sweep_flag} #{coordinates_for(arc_end_point_for(radius:, + percentage:))}" + end + + def draw_line_to(point:) + "L #{coordinates_for(point)}" + end + + def benchmark_line_point(radius, angle) + x = (radius * Math.cos(angle)).to_s + y = (radius * Math.sin(angle) + arc_center.y).to_s + Point.new(x, y) + end + + def coordinates_for(point) + "#{point.x} #{point.y}" + end end end diff --git a/app/models/dashboard/race.rb b/app/models/dashboard/race.rb index f7e2fb9..3f78ff4 100644 --- a/app/models/dashboard/race.rb +++ b/app/models/dashboard/race.rb @@ -1,8 +1,8 @@ module Dashboard class Race < ApplicationRecord include FriendlyId - has_many :dashboard_student_races - has_many :dashboard_students, through: :student_races + has_and_belongs_to_many :students, join_table: :dashboard_student_races, class_name: "Student", + foreign_key: :dashboard_student_id, association_foreign_key: :dashboard_student_id friendly_id :designation, use: [:slugged] diff --git a/app/models/dashboard/student.rb b/app/models/dashboard/student.rb index 8f769ab..44102f3 100644 --- a/app/models/dashboard/student.rb +++ b/app/models/dashboard/student.rb @@ -1,8 +1,8 @@ module Dashboard class Student < ApplicationRecord # has_many :dashboard_survey_item_responses - has_many :dashboard_student_races - has_and_belongs_to_many :races, join_table: :student_races + has_and_belongs_to_many :races, join_table: :dashboard_student_races, class_name: "Race", + foreign_key: :dashboard_race_id, association_foreign_key: :dashboard_race_id encrypts :lasid, deterministic: true end diff --git a/app/models/dashboard/survey_item_response.rb b/app/models/dashboard/survey_item_response.rb index 0dabec6..1c20f8a 100644 --- a/app/models/dashboard/survey_item_response.rb +++ b/app/models/dashboard/survey_item_response.rb @@ -54,7 +54,7 @@ module Dashboard def self.grouped_responses(school:, academic_year:) @grouped_responses ||= Hash.new do |memo, (school, academic_year)| memo[[school, academic_year]] = - SurveyItemResponse.where(school:, academic_year:).group(:survey_item_id).average(:likert_score) + SurveyItemResponse.where(school:, academic_year:).group(:dashboard_survey_item_id).average(:likert_score) end @grouped_responses[[school, academic_year]] end diff --git a/app/views/dashboard/categories/_data_item_section.html.erb b/app/views/dashboard/categories/_data_item_section.html.erb new file mode 100644 index 0000000..41fb700 --- /dev/null +++ b/app/views/dashboard/categories/_data_item_section.html.erb @@ -0,0 +1,42 @@ +
+

+ +

+ +
+
+ <% unless data_item_section.sufficient_data? %> + + <% end %> +
    + <% data_item_section.descriptions_and_availability.each do |data| %> +
  • <%= data.description %> + <% unless data.available? %> +   + <% end %> +
  • + <% end %> +
+
+
+
diff --git a/app/views/dashboard/categories/_gauge_graph.html.erb b/app/views/dashboard/categories/_gauge_graph.html.erb new file mode 100644 index 0000000..fec3775 --- /dev/null +++ b/app/views/dashboard/categories/_gauge_graph.html.erb @@ -0,0 +1,59 @@ +
+ <% if ENV["SCORES"].present? && ENV["SCORES"].upcase == "SHOW" %> +

Score is : <%= gauge.score %>

+ <% end %> + + + <% if gauge.score_percentage.present? %> + + <% end %> + + + + + <% benchmark_boundaries = [:watch_low, :growth_low, :ideal_low]%> + <% benchmark_boundaries.each do |zone| %> + + <% end %> + + <% if gauge.key_benchmark_percentage.present? %> + + <% end %> + +<%= gauge.title %> +
diff --git a/app/views/dashboard/categories/_measures_section.html.erb b/app/views/dashboard/categories/_measures_section.html.erb new file mode 100644 index 0000000..562b4a8 --- /dev/null +++ b/app/views/dashboard/categories/_measures_section.html.erb @@ -0,0 +1,12 @@ +
+

Measure <%= measure_presenter.id %>

+

<%= measure_presenter.name %>

+
+ <%= render partial: "gauge_graph", locals: { gauge: measure_presenter.gauge_presenter, gauge_class: 'gauge-graph-sm', font_class: 'weight-700' } %> +
+

<%= measure_presenter.description %>

+ +
+ <%= render partial: "data_item_section", collection: measure_presenter.data_item_presenters %> +
+
diff --git a/app/views/dashboard/categories/_subcategory_section.html.erb b/app/views/dashboard/categories/_subcategory_section.html.erb new file mode 100644 index 0000000..6746538 --- /dev/null +++ b/app/views/dashboard/categories/_subcategory_section.html.erb @@ -0,0 +1,59 @@ +
+
+

Subcategory <%= subcategory.id %>

+

<%= subcategory.name %>

+ +
+
+ <%= render partial: "gauge_graph", locals: { gauge: subcategory.gauge_presenter, gauge_class: 'gauge-graph-lg', font_class: 'sub-header-3' } %> +
+
+

<%= subcategory.description %>

+ +
+
+

<%= subcategory.admin_collection_rate.first %> / <%= subcategory.admin_collection_rate.last %>

+

school admin data sources

+
+
+

<%= subcategory.student_response_rate %>

+

of students responded

+
+
+

<%= subcategory.teacher_response_rate %>

+

of teachers responded

+
+
+
+
+
+ +
+
+
+
+ +
+ <% subcategory.measure_presenters.each do |measure_presenter| %> + <%= render partial: "measures_section", locals: { measure_presenter: measure_presenter } %> + <% end %> +
+
diff --git a/app/views/dashboard/categories/show.html.erb b/app/views/dashboard/categories/show.html.erb new file mode 100644 index 0000000..ba9a841 --- /dev/null +++ b/app/views/dashboard/categories/show.html.erb @@ -0,0 +1,25 @@ +<% content_for :navigation do %> + + + <% end %> + <% cache [@category, @school, @academic_year] do %> +

Category <%= @category.id %>

+

<%= @category.name %>

+

<%= @category.description %>

+ <% @category.subcategories(academic_year: @academic_year, school: @school).each do |subcategory| %> + <%= render partial: "subcategory_section", locals: {subcategory: subcategory} %> + <% end %> + <% end %> diff --git a/config/initializers/dashboard/string_monkey_patches.rb b/config/initializers/dashboard/string_monkey_patches.rb new file mode 100644 index 0000000..65ab487 --- /dev/null +++ b/config/initializers/dashboard/string_monkey_patches.rb @@ -0,0 +1,7 @@ +module StringMonkeyPatches + def valid_likert_score? + to_i.between? 1, 5 + end +end + +String.include StringMonkeyPatches