Seed db with Professional Qualifications construct

pull/1/head
Alex Basson 4 years ago
parent c5bd1a9b3f
commit acac8f67b0

@ -4,7 +4,7 @@ class DashboardController < ApplicationController
def index
authenticate(district.name.downcase, "#{district.name.downcase}!")
@construct_graph_row_presenters = [
ConstructGraphRowPresenter.new(construct: professional_qualifications_construct, score: 4.8)
ConstructGraphRowPresenter.new(construct: Construct.find_by_construct_id('1A-i'), score: 4.8)
]
end
@ -22,8 +22,4 @@ class DashboardController < ApplicationController
@district ||= @school.district
end
def professional_qualifications_construct
Construct.new title: "Professional Qualifications", watch_low_benchmark: 2.48, growth_low_benchmark: 2.99, approval_low_benchmark: 3.49, ideal_low_benchmark: 4.7
end
end

@ -1,19 +1,28 @@
class Construct
class Construct < ActiveRecord::Base
Zone = Struct.new(:low_benchmark, :high_benchmark, :type) do
def includes_score?(score)
score > low_benchmark and score < high_benchmark
end
end
attr_reader :title, :warning_zone, :watch_zone, :growth_zone, :approval_zone, :ideal_zone
def warning_zone
Zone.new(1, watch_low_benchmark, :warning)
end
def watch_zone
Zone.new(watch_low_benchmark, growth_low_benchmark, :watch)
end
def growth_zone
Zone.new(growth_low_benchmark, approval_low_benchmark, :growth)
end
def approval_zone
Zone.new(approval_low_benchmark, ideal_low_benchmark, :approval)
end
def initialize(title:, watch_low_benchmark:, growth_low_benchmark:, approval_low_benchmark:, ideal_low_benchmark:)
@title = title
@warning_zone = Zone.new(1, watch_low_benchmark, :warning)
@watch_zone = Zone.new(watch_low_benchmark, growth_low_benchmark, :watch)
@growth_zone = Zone.new(growth_low_benchmark, approval_low_benchmark, :growth)
@approval_zone = Zone.new(approval_low_benchmark, ideal_low_benchmark, :approval)
@ideal_zone = Zone.new(ideal_low_benchmark, 5, :ideal)
def ideal_zone
Zone.new(ideal_low_benchmark, 5.0, :ideal)
end
def zone_for_score(score)

@ -5,8 +5,8 @@ class ConstructGraphRowPresenter
@score = score
end
def construct_title
@construct.title
def construct_name
@construct.name
end
def bar_color

@ -41,7 +41,7 @@
<g id="construct-rows">
<svg id="construct-row-labels" x="0" y=<%= heading_gutter %>>
<%= @construct_graph_row_presenters.each_with_index do |presenter, index| %>
<text x="25%" dx=<%= -1 * label_padding_right %> y=<%= index * construct_row_height + construct_row_height / 2 %> text-anchor="end" dominant-baseline="middle"><%= presenter.construct_title %></text>
<text x="25%" dx=<%= -1 * label_padding_right %> y=<%= index * construct_row_height + construct_row_height / 2 %> text-anchor="end" dominant-baseline="middle"><%= presenter.construct_name %></text>
<% end %>
</svg>

@ -0,0 +1,12 @@
class CreateConstructs < ActiveRecord::Migration[5.0]
def change
create_table :constructs do |t|
t.string :construct_id
t.string :name
t.float :watch_low_benchmark
t.float :growth_low_benchmark
t.float :approval_low_benchmark
t.float :ideal_low_benchmark
end
end
end

@ -10,11 +10,10 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20181221180917) do
ActiveRecord::Schema.define(version: 20210915151547) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "pg_stat_statements"
create_table "attempts", force: :cascade do |t|
t.integer "recipient_id"
@ -49,6 +48,15 @@ ActiveRecord::Schema.define(version: 20181221180917) do
t.index ["slug"], name: "index_categories_on_slug", unique: true, using: :btree
end
create_table "constructs", force: :cascade do |t|
t.string "construct_id"
t.string "name"
t.float "watch_low_benchmark"
t.float "growth_low_benchmark"
t.float "approval_low_benchmark"
t.float "ideal_low_benchmark"
end
create_table "districts", force: :cascade do |t|
t.string "name"
t.integer "state_id"

@ -6,6 +6,8 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
Construct.destroy_all
Construct.create construct_id: '1A-i', name: 'Professional Qualifications', watch_low_benchmark: 2.5, growth_low_benchmark: 3.0, approval_low_benchmark: 3.5, ideal_low_benchmark: 4.7
# questions = Category.find_by_name('Family Subcategory').child_categories.map(&:questions).flatten
# QuestionList.create(name: 'Family Questions', question_id_array: questions.map(&:id))

@ -20,6 +20,7 @@ feature "School dashboard", type: feature do
visit "/districts/winchester/schools/#{school.slug}/dashboard?year=2020-21"
expect(page).to have_text(school.name)
expect(page).to have_text('Professional Qualifications')
end
let(:username) { 'winchester' }

@ -0,0 +1,14 @@
require 'rails_helper'
describe Construct, type: :model do
it 'returns the construct for the given construct id' do
construct = Construct.find_by_construct_id('1A-i')
expect(construct.name).to eq 'Professional Qualifications'
expect(construct.warning_zone).to eq Construct::Zone.new(1.0, 2.5, :warning)
expect(construct.watch_zone).to eq Construct::Zone.new(2.5, 3.0, :watch)
expect(construct.growth_zone).to eq Construct::Zone.new(3.0, 3.5, :growth)
expect(construct.approval_zone).to eq Construct::Zone.new(3.5, 4.7, :approval)
expect(construct.ideal_zone).to eq Construct::Zone.new(4.7, 5.0, :ideal)
end
end

@ -9,7 +9,7 @@ RSpec.describe "construct graph row presenter" do
let(:construct) {
Construct.new(
title: 'Some Title',
name: 'Some Title',
watch_low_benchmark: watch_low_benchmark,
growth_low_benchmark: growth_low_benchmark,
approval_low_benchmark: approval_low_benchmark,
@ -23,7 +23,7 @@ RSpec.describe "construct graph row presenter" do
shared_examples_for 'construct_title' do
it('returns the construct title') do
expect(presenter.construct_title).to eq 'Some Title'
expect(presenter.construct_name).to eq 'Some Title'
end
end

@ -50,6 +50,10 @@ RSpec.configure do |config|
config.include Capybara::DSL
config.before(:suite) do
Rails.application.load_seed # loading seeds
end
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin

Loading…
Cancel
Save