chore: start adding overview page

This commit is contained in:
Nelson Jovel 2024-01-17 12:49:23 -08:00
parent 1b0af124f7
commit 64b4d599c7
33 changed files with 783 additions and 199 deletions

View file

@ -0,0 +1,70 @@
# frozen_string_literal: true
module Dashboard
module AnalyzeHelper
def svg_height
400
end
def zone_label_width
15
end
def graph_width
85
end
def analyze_graph_height
85
end
def analyze_zone_height
analyze_graph_height / 5
end
def zone_height_percentage
analyze_zone_height / 100.0
end
def analyze_category_link(district:, school:, academic_year:, category:)
year = academic_year.range
"/districts/#{district.slug}/schools/#{school.slug}/analyze?year=#{year}&academic_years=#{year}&category=#{category.category_id}"
end
def analyze_subcategory_link(district:, school:, academic_year:, category:, subcategory:)
"/districts/#{district.slug}/schools/#{school.slug}/analyze?year=#{academic_year.range}&category=#{category.category_id}&subcategory=#{subcategory.subcategory_id}"
end
def colors
@colors ||= ["#49416D", "#FFC857", "#920020", "#00B0B3", "#B2D236", "#004D61", "#FFB3CC", "#FF3D00", "#212121", "#9E9D24",
"#689F38", "#388E3C", "#00897B", "#00796B", "#00695C", "#004D40", "#1B5E20", "#FF6F00", "#33691E", "#D50000",
"#827717", "#F57F17", "#FF6F00", "#E65100", "#BF360C", "#3E2723", "#263238", "#37474F", "#455A64"]
end
def empty_dataset?(measures:, school:, academic_year:)
@empty_dataset ||= Hash.new do |memo, (school, academic_year)|
memo[[school, academic_year]] = measures.none? do |measure|
response_rate = measure.subcategory.response_rate(school:, academic_year:)
response_rate.meets_student_threshold || response_rate.meets_teacher_threshold || measure.sufficient_admin_data?(school:, academic_year:)
end
end
@empty_dataset[[school, academic_year]]
end
def empty_survey_dataset?(measures:, school:, academic_year:)
@empty_survey_dataset ||= Hash.new do |memo, (school, academic_year)|
memo[[school, academic_year]] = measures.none? do |measure|
response_rate = measure.subcategory.response_rate(school:, academic_year:)
response_rate.meets_student_threshold || response_rate.meets_teacher_threshold
end
end
@empty_survey_dataset[[school, academic_year]]
end
def base_url
analyze_subcategory_link(district: @district, school: @school, academic_year: @academic_year, category: @presenter.category,
subcategory: @presenter.subcategory)
end
end
end

View file

@ -0,0 +1,99 @@
# frozen_string_literal: true
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}"
end
end

View file

@ -0,0 +1,54 @@
# frozen_string_literal: true
module Dashboard
module VarianceHelper
def heading_gutter
30
end
def footer_gutter
50
end
def measure_row_height
40
end
def graph_height(number_of_rows)
number_of_rows * measure_row_height + heading_gutter + footer_gutter
end
def graph_background_height(number_of_rows:)
number_of_rows += 1 if @has_empty_dataset
graph_height(number_of_rows) - footer_gutter
end
def measure_row_bar_height
20
end
def label_width_percentage
30
end
def graph_width_percentage
100 - label_width_percentage
end
def zones
%w[warning watch growth approval ideal]
end
def zone_width_percentage
100.0 / zones.size
end
def availability_indicator_percentage
3
end
def partial_data_indicator_size
20
end
end
end