Round all averages to two decimal places

rpp-main
rebuilt 3 years ago
parent 9f21a76ba4
commit 1a27b980d0

@ -25,13 +25,13 @@ class Measure < ActiveRecord::Base
end end
def student_survey_items_with_sufficient_responses(school:, academic_year:) def student_survey_items_with_sufficient_responses(school:, academic_year:)
SurveyItem.where(id: SurveyItem.joins('inner join survey_item_responses on survey_item_responses.survey_item_id = survey_items.id') SurveyItem.where(id: SurveyItem.joins("inner join survey_item_responses on survey_item_responses.survey_item_id = survey_items.id")
.student_survey_items .student_survey_items
.where("survey_item_responses.school": school, .where("survey_item_responses.school": school,
"survey_item_responses.academic_year": academic_year, "survey_item_responses.academic_year": academic_year,
"survey_item_responses.survey_item_id": survey_items.student_survey_items) "survey_item_responses.survey_item_id": survey_items.student_survey_items)
.group('survey_items.id') .group("survey_items.id")
.having('count(*) >= 10') .having("count(*) >= 10")
.count.keys) .count.keys)
end end
@ -60,7 +60,7 @@ class Measure < ActiveRecord::Base
next Score::NIL_SCORE if incalculable_score(school:, academic_year:) next Score::NIL_SCORE if incalculable_score(school:, academic_year:)
scores = collect_averages_for_teacher_student_and_admin_data(school:, academic_year:) scores = collect_averages_for_teacher_student_and_admin_data(school:, academic_year:)
average = scores.flatten.compact.remove_blanks.average average = scores.flatten.compact.remove_blanks.average.round(2)
next Score::NIL_SCORE if average.nan? next Score::NIL_SCORE if average.nan?
@ -72,7 +72,7 @@ class Measure < ActiveRecord::Base
def student_score(school:, academic_year:) def student_score(school:, academic_year:)
@student_score ||= Hash.new do |memo, (school, academic_year)| @student_score ||= Hash.new do |memo, (school, academic_year)|
meets_student_threshold = sufficient_student_data?(school:, academic_year:) meets_student_threshold = sufficient_student_data?(school:, academic_year:)
average = student_average(school:, academic_year:) if meets_student_threshold average = student_average(school:, academic_year:).round(2) if meets_student_threshold
memo[[school, academic_year]] = scorify(average:, school:, academic_year:) memo[[school, academic_year]] = scorify(average:, school:, academic_year:)
end end
@ -82,7 +82,7 @@ class Measure < ActiveRecord::Base
def teacher_score(school:, academic_year:) def teacher_score(school:, academic_year:)
@teacher_score ||= Hash.new do |memo, (school, academic_year)| @teacher_score ||= Hash.new do |memo, (school, academic_year)|
meets_teacher_threshold = sufficient_teacher_data?(school:, academic_year:) meets_teacher_threshold = sufficient_teacher_data?(school:, academic_year:)
average = teacher_average(school:, academic_year:) if meets_teacher_threshold average = teacher_average(school:, academic_year:).round(2) if meets_teacher_threshold
memo[[school, academic_year]] = scorify(average:, school:, academic_year:) memo[[school, academic_year]] = scorify(average:, school:, academic_year:)
end end
@ -92,7 +92,7 @@ class Measure < ActiveRecord::Base
def admin_score(school:, academic_year:) def admin_score(school:, academic_year:)
@admin_score ||= Hash.new do |memo, (school, academic_year)| @admin_score ||= Hash.new do |memo, (school, academic_year)|
meets_admin_threshold = sufficient_admin_data?(school:, academic_year:) meets_admin_threshold = sufficient_admin_data?(school:, academic_year:)
average = admin_data_averages(school:, academic_year:).average if meets_admin_threshold average = admin_data_averages(school:, academic_year:).average.round(2) if meets_admin_threshold
memo[[school, academic_year]] = scorify(average:, school:, academic_year:) memo[[school, academic_year]] = scorify(average:, school:, academic_year:)
end end

@ -7,7 +7,7 @@ module Analyze
academic_year = academic_years[year_index] academic_year = academic_years[year_index]
averages = SurveyItemResponse.averages_for_gender(measure.student_survey_items, school, academic_year, averages = SurveyItemResponse.averages_for_gender(measure.student_survey_items, school, academic_year,
gender) gender)
average = bubble_up_averages(averages:) average = bubble_up_averages(averages:).round(2)
scorify(average:, meets_student_threshold: sufficient_student_responses?(academic_year:)) scorify(average:, meets_student_threshold: sufficient_student_responses?(academic_year:))
end end

@ -4,8 +4,9 @@ module Analyze
module Grade module Grade
module ScoreForGrade module ScoreForGrade
def score(year_index) def score(year_index)
averages = SurveyItemResponse.averages_for_grade(measure.student_survey_items, school, academic_years[year_index], grade) averages = SurveyItemResponse.averages_for_grade(measure.student_survey_items, school,
average = bubble_up_averages(averages:) academic_years[year_index], grade)
average = bubble_up_averages(averages:).round(2)
Score.new(average:, Score.new(average:,
meets_teacher_threshold: false, meets_teacher_threshold: false,

@ -4,7 +4,7 @@ module Analyze
module ScoreForRace module ScoreForRace
def score(year_index) def score(year_index)
s = ::RaceScore.find_by(measure:, school:, academic_year: academic_years[year_index], race:) s = ::RaceScore.find_by(measure:, school:, academic_year: academic_years[year_index], race:)
average = s.average unless s.nil? average = s.average.round(2) unless s.nil?
average ||= 0 average ||= 0
meets_student_threshold = s.meets_student_threshold? unless s.nil? meets_student_threshold = s.meets_student_threshold? unless s.nil?
meets_student_threshold ||= false meets_student_threshold ||= false

@ -3,7 +3,7 @@
class GaugePresenter class GaugePresenter
def initialize(zones:, score:) def initialize(zones:, score:)
@zones = zones @zones = zones
@score = score @score = score&.round(2)
end end
def title def title

@ -4,7 +4,7 @@
<rect data-for-academic-year="<%= bar.academic_year.range %>" x="<%= bar.x_position %>%" y="<%= bar.y_offset %>%" width="<%= column.bar_width %>%" height="<%= bar.bar_height_percentage %>%" fill="<%= bar.color %>" /> <rect data-for-academic-year="<%= bar.academic_year.range %>" x="<%= bar.x_position %>%" y="<%= bar.y_offset %>%" width="<%= column.bar_width %>%" height="<%= bar.bar_height_percentage %>%" fill="<%= bar.color %>" />
<% if ENV["SCORES"].present? && ENV["SCORES"].upcase == "SHOW" %> <% if ENV["SCORES"].present? && ENV["SCORES"].upcase == "SHOW" %>
<text x="<%= bar.x_position + 3 %>%" y="<%= score_label_y[index] %>%" text-anchor="middle" dominant-baseline="middle"> <text x="<%= bar.x_position + (column.bar_width * 0.5) %>%" y="<%= score_label_y[index] %>%" text-anchor="middle" dominant-baseline="middle">
<%= bar.average %> <%= bar.average %>
</text> </text>
<% end %> <% end %>

@ -1,6 +1,6 @@
<div class="d-flex flex-column align-items-center position-relative"> <div class="d-flex flex-column align-items-center position-relative">
<% if ENV["SCORES"].present? && ENV["SCORES"].upcase == "SHOW" %> <% if ENV["SCORES"].present? && ENV["SCORES"].upcase == "SHOW" %>
<p>Score is : <%=gauge.score %> </p> <p>Score is : <%= gauge.score %> </p>
<% end %> <% end %>
<svg <svg

Loading…
Cancel
Save