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 @@ +
Score is : <%= gauge.score %>
+ <% end %> + + +<%= gauge.title %> +Measure <%= measure_presenter.id %>
+<%= measure_presenter.description %>
+ +Subcategory <%= subcategory.id %>
+<%= 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
+Category <%= @category.id %>
+<%= @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