mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
Use modules to namespace classes for analyze page
This commit is contained in:
parent
c568e8bc06
commit
94a58a87d7
15 changed files with 246 additions and 213 deletions
|
|
@ -74,7 +74,7 @@ class AnalyzeController < SqmApplicationController
|
|||
end
|
||||
|
||||
def graphs
|
||||
@graphs ||= [AnalysisGraph::StudentsAndTeachers.new, AnalysisGraph::StudentsByGroup.new]
|
||||
@graphs ||= [Analyze::Graph::StudentsAndTeachers.new, Analyze::Graph::StudentsByGroup.new]
|
||||
end
|
||||
|
||||
def background
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module AnalysisGraph
|
||||
class StudentsAndTeachers
|
||||
def to_s
|
||||
'Students & Teachers'
|
||||
end
|
||||
|
||||
def value
|
||||
'students-and-teachers'
|
||||
end
|
||||
|
||||
def columns
|
||||
[StudentGroupedBarColumnPresenter, TeacherGroupedBarColumnPresenter, GroupedBarColumnPresenter]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
module AnalysisGraph
|
||||
class StudentsByGroup
|
||||
def to_s
|
||||
'Students by Group'
|
||||
end
|
||||
|
||||
def value
|
||||
'students-by-group'
|
||||
end
|
||||
|
||||
def columns
|
||||
[StudentGroupedBarColumnPresenter]
|
||||
end
|
||||
end
|
||||
end
|
||||
20
app/models/analyze/graph/students_and_teachers.rb
Normal file
20
app/models/analyze/graph/students_and_teachers.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Analyze
|
||||
module Graph
|
||||
class StudentsAndTeachers
|
||||
include Analyze::Graph::Column
|
||||
def to_s
|
||||
'Students & Teachers'
|
||||
end
|
||||
|
||||
def value
|
||||
'students-and-teachers'
|
||||
end
|
||||
|
||||
def columns
|
||||
[Student, Teacher, GroupedBarColumnPresenter]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/models/analyze/graph/students_by_group.rb
Normal file
25
app/models/analyze/graph/students_by_group.rb
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
module Analyze
|
||||
module Graph
|
||||
class StudentsByGroup
|
||||
def to_s
|
||||
'Students by Group'
|
||||
end
|
||||
|
||||
def value
|
||||
'students-by-group'
|
||||
end
|
||||
|
||||
def columns
|
||||
[Analyze::Graph::Column::Student,
|
||||
Analyze::Graph::Column::Student,
|
||||
Analyze::Graph::Column::Student,
|
||||
Analyze::Graph::Column::Student,
|
||||
Analyze::Graph::Column::Student,
|
||||
Analyze::Graph::Column::Student,
|
||||
Analyze::Graph::Column::Student,
|
||||
Analyze::Graph::Column::Student,
|
||||
Analyze::Graph::Column::Student]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Analyze
|
||||
module Graph
|
||||
module Column
|
||||
class GroupedBarColumnPresenter
|
||||
include AnalyzeHelper
|
||||
|
||||
attr_reader :measure_name, :measure_id, :category, :position, :measure, :school, :academic_years,
|
||||
:number_of_columns
|
||||
|
||||
def initialize(measure:, school:, academic_years:, position:, number_of_columns:)
|
||||
@measure = measure
|
||||
@measure_name = @measure.name
|
||||
@measure_id = @measure.measure_id
|
||||
@category = @measure.subcategory.category
|
||||
@school = school
|
||||
@academic_years = academic_years
|
||||
@position = position
|
||||
@number_of_columns = number_of_columns
|
||||
end
|
||||
|
||||
def score(year_index)
|
||||
measure.score(school:, academic_year: academic_years[year_index]) || 0
|
||||
end
|
||||
|
||||
def bars
|
||||
@bars ||= yearly_scores.map.each_with_index do |yearly_score, index|
|
||||
year = yearly_score.year
|
||||
AnalyzeBarPresenter.new(measure:, academic_year: year,
|
||||
score: yearly_score.score,
|
||||
x_position: bar_x(index),
|
||||
color: bar_color(year))
|
||||
end
|
||||
end
|
||||
|
||||
def label
|
||||
'All 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 column_midpoint
|
||||
zone_label_width + (grouped_chart_column_width * (position + 1)) - (grouped_chart_column_width / 2)
|
||||
end
|
||||
|
||||
def bar_width
|
||||
min_bar_width(10.5 / data_sources)
|
||||
end
|
||||
|
||||
def min_bar_width(number)
|
||||
min_width = 2
|
||||
number < min_width ? min_width : number
|
||||
end
|
||||
|
||||
def message_x
|
||||
column_midpoint - message_width / 2
|
||||
end
|
||||
|
||||
def message_y
|
||||
17
|
||||
end
|
||||
|
||||
def message_width
|
||||
20
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def grouped_chart_column_width
|
||||
graph_width / data_sources
|
||||
end
|
||||
|
||||
def bar_label_height
|
||||
(100 - ((100 - analyze_graph_height) / 2))
|
||||
end
|
||||
|
||||
def data_sources
|
||||
number_of_columns
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
YearlyScore = Struct.new(:year, :score)
|
||||
def yearly_scores
|
||||
yearly_scores = academic_years.each_with_index.map do |year, index|
|
||||
YearlyScore.new(year, score(index))
|
||||
end
|
||||
yearly_scores.reject do |yearly_score|
|
||||
yearly_score.score.blank?
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
33
app/presenters/analyze/graph/column/student.rb
Normal file
33
app/presenters/analyze/graph/column/student.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Analyze
|
||||
module Graph
|
||||
module Column
|
||||
class Student < GroupedBarColumnPresenter
|
||||
def label
|
||||
'All Students'
|
||||
end
|
||||
|
||||
def basis
|
||||
'student'
|
||||
end
|
||||
|
||||
def show_irrelevancy_message?
|
||||
!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_student_threshold? }
|
||||
end
|
||||
|
||||
def score(year_index)
|
||||
measure.student_score(school:, academic_year: academic_years[year_index])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
33
app/presenters/analyze/graph/column/teacher.rb
Normal file
33
app/presenters/analyze/graph/column/teacher.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Analyze
|
||||
module Graph
|
||||
module Column
|
||||
class Teacher < GroupedBarColumnPresenter
|
||||
def label
|
||||
'All Teachers'
|
||||
end
|
||||
|
||||
def basis
|
||||
'teacher'
|
||||
end
|
||||
|
||||
def show_irrelevancy_message?
|
||||
!measure.includes_teacher_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? }
|
||||
end
|
||||
|
||||
def score(year_index)
|
||||
measure.teacher_score(school:, academic_year: academic_years[year_index])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class GroupedBarColumnPresenter
|
||||
include AnalyzeHelper
|
||||
|
||||
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_years = academic_years
|
||||
@position = position
|
||||
end
|
||||
|
||||
def score(year_index)
|
||||
measure.score(school:, academic_year: academic_years[year_index]) || 0
|
||||
end
|
||||
|
||||
def bars
|
||||
@bars ||= yearly_scores.map.each_with_index do |yearly_score, index|
|
||||
year = yearly_score.year
|
||||
AnalyzeBarPresenter.new(measure:, academic_year: year,
|
||||
score: yearly_score.score,
|
||||
x_position: bar_x(index),
|
||||
color: bar_color(year))
|
||||
end
|
||||
end
|
||||
|
||||
def label
|
||||
'All 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 column_midpoint
|
||||
zone_label_width + (grouped_chart_column_width * (position + 1)) - (grouped_chart_column_width / 2)
|
||||
end
|
||||
|
||||
def bar_width
|
||||
3.5
|
||||
end
|
||||
|
||||
def message_x
|
||||
column_midpoint - message_width / 2
|
||||
end
|
||||
|
||||
def message_y
|
||||
17
|
||||
end
|
||||
|
||||
def message_width
|
||||
20
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def grouped_chart_column_width
|
||||
graph_width / data_sources
|
||||
end
|
||||
|
||||
def bar_label_height
|
||||
(100 - ((100 - analyze_graph_height) / 2))
|
||||
end
|
||||
|
||||
def data_sources
|
||||
3
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
YearlyScore = Struct.new(:year, :score)
|
||||
def yearly_scores
|
||||
yearly_scores = academic_years.each_with_index.map do |year, index|
|
||||
YearlyScore.new(year, score(index))
|
||||
end
|
||||
yearly_scores.reject do |yearly_score|
|
||||
yearly_score.score.blank?
|
||||
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
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class StudentGroupedBarColumnPresenter < GroupedBarColumnPresenter
|
||||
def label
|
||||
'All Students'
|
||||
end
|
||||
|
||||
def basis
|
||||
'student'
|
||||
end
|
||||
|
||||
def show_irrelevancy_message?
|
||||
!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_student_threshold? }
|
||||
end
|
||||
|
||||
def score(year_index)
|
||||
measure.student_score(school:, academic_year: academic_years[year_index])
|
||||
end
|
||||
end
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TeacherGroupedBarColumnPresenter < GroupedBarColumnPresenter
|
||||
def label
|
||||
'All Teachers'
|
||||
end
|
||||
|
||||
def basis
|
||||
'teacher'
|
||||
end
|
||||
|
||||
def show_irrelevancy_message?
|
||||
!measure.includes_teacher_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? }
|
||||
end
|
||||
|
||||
def score(year_index)
|
||||
measure.teacher_score(school:, academic_year: academic_years[year_index])
|
||||
end
|
||||
end
|
||||
|
|
@ -2,8 +2,6 @@
|
|||
<rect x="0" y="0" width="100%" height="<%= background.analyze_zone_height * 2 %>%" fill="#edecf0" />
|
||||
<rect x="0" y="<%= background.analyze_zone_height * 2 %>%" width="100%" height="<%= background.analyze_zone_height * 3 %>%" fill="#fffaee" />
|
||||
<rect x="0" y="0" width="100%" height="<%= background.analyze_graph_height %>%" fill="none" stroke="grey" />
|
||||
<line x1="<%= background.column_end_x(1) %>%" y1="0" x2="<%= background.column_end_x(1) %>%" y2="85%" stroke="grey" stroke-width="1" stroke-dasharray="5,2" />
|
||||
<line x1="<%= background.column_end_x(2) %>%" y1="0" x2="<%= background.column_end_x(2) %>%" y2="85%" stroke="grey" stroke-width="1" stroke-dasharray="5,2" />
|
||||
<rect x="0" y="<%= background.benchmark_y %>%" width="100%" height="<%= background.benchmark_height %>%" fill="black" />
|
||||
|
||||
<g id="zone-dividers" stroke-width="1">
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@
|
|||
<%= render partial: "graph_background", locals: {background: @background} %>
|
||||
|
||||
<%# <% columns = [StudentGroupedBarColumnPresenter, TeacherGroupedBarColumnPresenter, GroupedBarColumnPresenter] %1> %>
|
||||
<% number_of_columns = @graph.columns.length %>
|
||||
<% @graph.columns.each_with_index do |column, index| %>
|
||||
<% p = column.new(measure: measure, school: @school, academic_years: @selected_academic_years, position: index ) %>
|
||||
<% p = column.new(measure: measure, school: @school, academic_years: @selected_academic_years, position: index , number_of_columns:) %>
|
||||
<%= render partial: "grouped_bar_column", locals: {column: p} %>
|
||||
<% end %>
|
||||
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 516 B After Width: | Height: | Size: 586 B |
|
|
@ -10,6 +10,7 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<line x1="<%= column.column_start_x %>%" y1="0" x2="<%= column.column_start_x %>%" y2="85%" stroke="grey" stroke-width="1" stroke-dasharray="5,2" />
|
||||
<text class="graph-footer" x="<%= column.column_midpoint %>%" y="<%= column.bar_label_height %>%" text-anchor="middle" dominant-baseline="middle" data-grouped-bar-label="<%= column.label %>">
|
||||
<%= column.label %>
|
||||
</text>
|
||||
|
|
|
|||
|
|
@ -67,12 +67,7 @@ namespace :data do
|
|||
end
|
||||
desc 'load students'
|
||||
task load_students: :environment do
|
||||
files = ['2021-22_attleboro_student_survey_responses.csv',
|
||||
'2021-22_lowell_milford_student_survey_responses.csv',
|
||||
'2021-22_revere_somerville_wareham_student_survey_responses.csv',
|
||||
'2021-22_winchester_student_survey_responses.csv' ]
|
||||
files.each do |file|
|
||||
file = Rails.root.join('data', 'survey_responses', file)
|
||||
Dir.glob(Rails.root.join('data', 'survey_responses', '*.csv')).each do |file|
|
||||
puts "=====================> Loading student data from csv at path: #{file}"
|
||||
StudentLoader.load_data filepath: file
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue