checkbox change. Draw bar graphs for each academic year selected. Center bar graphs in their column. Color the columns to match the sample colors on the checkboxes. Add scores on beta to top of graph. Automatically display the most recent year of data for the district. Modify logic for the insufficient data message or the 'measure not based on student/teacher surveys' message so it only shows if there are no bars with data to display.pull/1/head
parent
30c97f4428
commit
50256cacce
@ -0,0 +1,2 @@
|
||||
module ColorHelper
|
||||
end
|
||||
@ -0,0 +1,63 @@
|
||||
class AnalyzeBarPresenter
|
||||
include AnalyzeHelper
|
||||
attr_reader :score, :x_position, :academic_year, :measure_id, :measure, :color
|
||||
|
||||
def initialize(measure:, academic_year:, score:, x_position:, color:)
|
||||
@score = score
|
||||
@x_position = x_position
|
||||
@academic_year = academic_year
|
||||
@measure = measure
|
||||
@measure_id = measure.measure_id
|
||||
@color = color
|
||||
end
|
||||
|
||||
def y_offset
|
||||
case zone.type
|
||||
when :ideal, :approval
|
||||
(analyze_zone_height * 2) - bar_height_percentage
|
||||
else
|
||||
(analyze_zone_height * 2)
|
||||
end
|
||||
end
|
||||
|
||||
def bar_color
|
||||
"fill-#{zone.type}"
|
||||
end
|
||||
|
||||
def bar_height_percentage
|
||||
case zone.type
|
||||
when :ideal
|
||||
(percentage * zone_height_percentage + zone_height_percentage) * 100
|
||||
when :approval
|
||||
(percentage * zone_height_percentage) * 100
|
||||
when :growth
|
||||
((1 - percentage) * zone_height_percentage) * 100
|
||||
when :watch
|
||||
((1 - percentage) * zone_height_percentage + zone_height_percentage) * 100
|
||||
when :warning
|
||||
((1 - percentage) * zone_height_percentage + zone_height_percentage + zone_height_percentage) * 100
|
||||
else
|
||||
0.0
|
||||
end
|
||||
end
|
||||
|
||||
def percentage
|
||||
(score.average - 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.average)
|
||||
end
|
||||
|
||||
def average
|
||||
return 0 if score.average.nil?
|
||||
|
||||
score.average.round(2)
|
||||
end
|
||||
end
|
||||
@ -1,78 +1,102 @@
|
||||
class GroupedBarColumnPresenter
|
||||
include AnalyzeHelper
|
||||
attr_reader :score, :measure_name, :measure_id, :category, :position, :measure, :school, :academic_year
|
||||
include ColorHelper
|
||||
|
||||
def initialize(measure:, school:, academic_year:, position:)
|
||||
attr_reader :measure_name, :measure_id, :category, :position, :measure, :school, :academic_years
|
||||
|
||||
def initialize(measure:, school:, academic_years:, position:)
|
||||
@measure = measure
|
||||
@measure_name = @measure.name
|
||||
@measure_id = @measure.measure_id
|
||||
@category = @measure.subcategory.category
|
||||
@school = school
|
||||
@academic_year = academic_year
|
||||
@academic_years = academic_years
|
||||
@position = position
|
||||
end
|
||||
|
||||
def score
|
||||
measure.score(school:, academic_year:)
|
||||
def score(year_index)
|
||||
measure.score(school:, academic_year: academic_years[year_index])
|
||||
end
|
||||
|
||||
def y_offset
|
||||
case zone.type
|
||||
when :ideal, :approval
|
||||
(analyze_zone_height * 2) - bar_height_percentage
|
||||
else
|
||||
(analyze_zone_height * 2)
|
||||
def bars
|
||||
@bars ||= yearly_scores.map.each_with_index do |item, index|
|
||||
year = item[0]
|
||||
score = item[1]
|
||||
AnalyzeBarPresenter.new(measure:, academic_year: year, score:, x_position: bar_x(index),
|
||||
color: bar_color(year))
|
||||
end
|
||||
end
|
||||
|
||||
def bar_color
|
||||
"fill-#{zone.type}"
|
||||
end
|
||||
|
||||
def bar_height_percentage
|
||||
case zone.type
|
||||
when :ideal
|
||||
(percentage * zone_height_percentage + zone_height_percentage) * 100
|
||||
when :approval
|
||||
(percentage * zone_height_percentage) * 100
|
||||
when :growth
|
||||
((1 - percentage) * zone_height_percentage) * 100
|
||||
when :watch
|
||||
((1 - percentage) * zone_height_percentage + zone_height_percentage) * 100
|
||||
when :warning
|
||||
((1 - percentage) * zone_height_percentage + zone_height_percentage + zone_height_percentage) * 100
|
||||
else
|
||||
0.0
|
||||
def label
|
||||
'All Survey Data'
|
||||
end
|
||||
|
||||
def basis
|
||||
''
|
||||
end
|
||||
|
||||
def show_irrelevancy_message?
|
||||
!measure.includes_teacher_survey_items? && !measure.includes_student_survey_items?
|
||||
end
|
||||
|
||||
def show_insufficient_data_message?
|
||||
scores = academic_years.map do |year|
|
||||
measure.score(school:, academic_year: year)
|
||||
end
|
||||
|
||||
scores.all? { |score| !score.meets_teacher_threshold? && !score.meets_student_threshold? }
|
||||
end
|
||||
|
||||
def percentage
|
||||
(score.average - zone.low_benchmark) / (zone.high_benchmark - zone.low_benchmark)
|
||||
def column_midpoint
|
||||
zone_label_width + (grouped_chart_column_width * (position + 1)) - (grouped_chart_column_width / 2)
|
||||
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.average)
|
||||
def bar_width
|
||||
3.5
|
||||
end
|
||||
|
||||
def label
|
||||
'All Survey Data'
|
||||
def message_x
|
||||
column_midpoint - message_width / 2
|
||||
end
|
||||
|
||||
def basis
|
||||
''
|
||||
def message_y
|
||||
17
|
||||
end
|
||||
|
||||
def show_irrelevancy_message?
|
||||
!@measure.includes_teacher_survey_items? && !@measure.includes_student_survey_items?
|
||||
def message_width
|
||||
20
|
||||
end
|
||||
|
||||
def show_insufficient_data_message?
|
||||
!score.meets_teacher_threshold? && !score.meets_student_threshold?
|
||||
def message_height
|
||||
34
|
||||
end
|
||||
|
||||
def column_end_x
|
||||
zone_label_width + (grouped_chart_column_width * (position + 1))
|
||||
end
|
||||
|
||||
def column_start_x
|
||||
zone_label_width + (grouped_chart_column_width * position)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def yearly_scores
|
||||
yearly_scores = academic_years.each_with_index.map do |year, index|
|
||||
[year, score(index)]
|
||||
end
|
||||
yearly_scores.reject do |yearly_score|
|
||||
score = yearly_score[1]
|
||||
score.average.nil? || score.average.zero? || score.average.nan?
|
||||
end
|
||||
end
|
||||
|
||||
def bar_color(year)
|
||||
@available_academic_years ||= AcademicYear.order(:range).all
|
||||
colors[@available_academic_years.find_index(year)]
|
||||
end
|
||||
|
||||
def bar_x(index)
|
||||
column_start_x + (index * bar_width * 1.2) + ((column_end_x - column_start_x) - (yearly_scores.size * bar_width * 1.2)) / 2
|
||||
end
|
||||
end
|
||||
|
||||
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.2 KiB |
@ -1,30 +1,33 @@
|
||||
<g id="grouped-bar-column">
|
||||
<rect x="<%= bar_label_x(presenter.position) - 2.5 %>%" y="<%= presenter.y_offset %>%" width="5%" height="<%= presenter.bar_height_percentage %>%" fill="#3E3A38" data-for-measure-id="<%= presenter.measure_id %>"/>
|
||||
<g class="grouped-bar-column" data-for-measure-id="<%= presenter.measure.measure_id %>">
|
||||
<% presenter.bars.each_with_index do |bar, index| %>
|
||||
<rect data-for-academic-year="<%= bar.academic_year.range %>" x="<%= bar.x_position %>%" y="<%= bar.y_offset %>%" width="<%= presenter.bar_width %>%" height="<%= bar.bar_height_percentage %>%" fill="<%= bar.color %>" />
|
||||
|
||||
<% if ENV["SCORES"].present? && ENV["SCORES"].upcase == "SHOW" %>
|
||||
<text x="<%= bar_label_x(presenter.position) %>%" y="<%= 5 %>%" text-anchor="middle" dominant-baseline="middle" >
|
||||
<%= presenter.score.average %>
|
||||
</text>
|
||||
<% if ENV["SCORES"].present? && ENV["SCORES"].upcase == "SHOW" %>
|
||||
<text x="<%= bar.x_position + 1 %>%" y="5%" text-anchor="middle" dominant-baseline="middle" >
|
||||
<%= bar.average %>
|
||||
</text>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<text class="graph-footer" x="<%= bar_label_x(presenter.position) %>%" y="<%= bar_label_height %>%" text-anchor="middle" dominant-baseline="middle" data-grouped-bar-label="<%= presenter.label %>">
|
||||
|
||||
<text class="graph-footer" x="<%= presenter.column_midpoint %>%" y="<%= bar_label_height %>%" text-anchor="middle" dominant-baseline="middle" data-grouped-bar-label="<%= presenter.label %>">
|
||||
<%= presenter.label %>
|
||||
</text>
|
||||
|
||||
<% if presenter.show_irrelevancy_message? %>
|
||||
<rect x="<%= bar_label_x(presenter.position) - 10 %>%" y="<%= 17 %>%" rx="15" ry="15" width="20%" height="<%= 34 %>%" fill="white" stroke="gray"/>
|
||||
<rect x="<%= presenter.message_x %>%" y="<%= presenter.message_y %>%" rx="15" ry="15" width="<%= presenter.message_width %>%" height="<%= presenter.message_height %>%" fill="white" stroke="gray"/>
|
||||
|
||||
<text x="<%= bar_label_x(presenter.position) %>%" y="<%= 20 %>%" text-anchor="middle">
|
||||
<tspan x="<%= bar_label_x(presenter.position) %>%" y="29%">measure not</tspan>
|
||||
<tspan x="<%= bar_label_x(presenter.position) %>%" y="34%">based on</tspan>
|
||||
<tspan x="<%= bar_label_x(presenter.position) %>%" y="39%"><%= presenter.basis %> surveys </tspan>
|
||||
<text x="<%= presenter.column_midpoint %>%" y="<%= 20 %>%" text-anchor="middle">
|
||||
<tspan x="<%= presenter.column_midpoint %>%" y="29%">measure not</tspan>
|
||||
<tspan x="<%= presenter.column_midpoint %>%" y="34%">based on</tspan>
|
||||
<tspan x="<%= presenter.column_midpoint %>%" y="39%"><%= presenter.basis %> surveys </tspan>
|
||||
</text>
|
||||
<% elsif presenter.show_insufficient_data_message? %>
|
||||
<rect x="<%= bar_label_x(presenter.position) - 10 %>%" y="<%= 17 %>%" rx="15" ry="15" width="20%" height="<%= 34 %>%" fill="white" stroke="gray" />
|
||||
<rect x="<%= presenter.message_x %>%" y="<%= presenter.message_y %>%" rx="15" ry="15" width="<%= presenter.message_width %>%" height="<%= presenter.message_height %>%" fill="white" stroke="gray" />
|
||||
|
||||
<text x="<%= bar_label_x(presenter.position) %>%" y="<%= 20 %>%" text-anchor="middle" >
|
||||
<tspan x="<%= bar_label_x(presenter.position) %>%" y="29%">survey response</tspan>
|
||||
<tspan x="<%= bar_label_x(presenter.position) %>%" y="34%">rate below 25%</tspan>
|
||||
<text x="<%= presenter.column_midpoint %>%" y="<%= 20 %>%" text-anchor="middle" >
|
||||
<tspan x="<%= presenter.column_midpoint %>%" y="29%">survey response</tspan>
|
||||
<tspan x="<%= presenter.column_midpoint %>%" y="34%">rate below 25%</tspan>
|
||||
</text>
|
||||
<% end %>
|
||||
</g>
|
||||
|
||||
Loading…
Reference in new issue