From 14d2c36f925493afede853766942cad30a051b83 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 16 May 2024 11:19:00 +0100 Subject: [PATCH 1/5] Hide countries with no submissions This matches how the data extract works and makes it easier to compare. --- app/lib/analytics/publication_extract.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/lib/analytics/publication_extract.rb b/app/lib/analytics/publication_extract.rb index 14fd61a852..c512e61cc5 100644 --- a/app/lib/analytics/publication_extract.rb +++ b/app/lib/analytics/publication_extract.rb @@ -9,8 +9,11 @@ def initialize(from:, to:) end def call - countries.map do |country| + countries.filter_map do |country| submissions = submitted_application_forms(country) + + next if submissions.empty? + awards = awarded_application_forms(country) declines = declined_application_forms(country) withdraws = withdrawn_application_forms(country) From d109772c620bc4163c6b9c7038904217357d60a8 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 16 May 2024 11:19:31 +0100 Subject: [PATCH 2/5] Fix calculation for awaiting decision We were adding the declines rather than subtracting them. --- app/lib/analytics/publication_extract.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/analytics/publication_extract.rb b/app/lib/analytics/publication_extract.rb index c512e61cc5..89234ed455 100644 --- a/app/lib/analytics/publication_extract.rb +++ b/app/lib/analytics/publication_extract.rb @@ -33,7 +33,7 @@ def call declined: declines.count, withdrawn: withdraws.count, awaiting_decision: - submissions.count - awarded + declines.count - withdraws.count, + submissions.count - awarded - declines.count - withdraws.count, awardees_with_only_ebacc_subject_or_subjects: awards.count do |application_form| has_only_ebacc_subjects?(application_form) From 45aa6aa061b89758225fd9ecfe8f46f7aa47a9ab Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 16 May 2024 11:27:59 +0100 Subject: [PATCH 3/5] Fix induction required percentage calculation We were dividing two integer values which meant we weren't getting back a decimal number and it was being rounded too soon. --- app/lib/analytics/publication_extract.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/lib/analytics/publication_extract.rb b/app/lib/analytics/publication_extract.rb index 89234ed455..008a9e979c 100644 --- a/app/lib/analytics/publication_extract.rb +++ b/app/lib/analytics/publication_extract.rb @@ -25,6 +25,15 @@ def call .select { |application_form| requires_induction?(application_form) } .count + percent_induction_required = + ( + if awarded.zero? + 0 + else + ((induction_required.to_f / awarded) * 100).round + end + ) + { country_name: CountryName.from_country(country), applications: submissions.count, @@ -48,8 +57,7 @@ def call !has_no_ebacc_subjects?(application_form) end, induction_required:, - percent_induction_required: - awarded.zero? ? 0 : ((induction_required / awarded) * 100).round(1), + percent_induction_required:, } end end From e35d8fe52ee74facb8ed5949e24bdc4d0d530e19 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 16 May 2024 11:49:34 +0100 Subject: [PATCH 4/5] Refactor EBacc subjects This refactors how we determine whether a subject is an EBacc subject. --- app/models/subject.rb | 97 ++++++++++++++----------------------- spec/models/subject_spec.rb | 14 ++++++ 2 files changed, 51 insertions(+), 60 deletions(-) diff --git a/app/models/subject.rb b/app/models/subject.rb index 26392d859d..2062cf4711 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -3,40 +3,8 @@ class Subject include ActiveModel::Model - attr_accessor :value, :name - - def ebacc? - EBACC_VALUES.include?(value) - end - - EBACC_VALUES = %w[ - applied_biology - ancient_hebrew - applied_chemistry - applied_physics - arabic_languages - biology - chinese_languages - computer_science - english_studies - environmental_sciences - french_language - general_sciences - geography - german_language - history - italian_language - latin_language - materials_science - mathematics - portuguese_language - spanish_language - statistics - modern_languages - russian_languages - physics - chemistry - ].freeze + attr_accessor :value, :name, :ebacc + alias_method :ebacc?, :ebacc class << self def all @@ -50,27 +18,51 @@ def find(values) private def create(value:) - Subject.new(value:, name: I18n.t("subjects.#{value}")) + Subject.new( + value:, + name: I18n.t("subjects.#{value}"), + ebacc: EBACC_VALUES.include?(value), + ) end - ALL_VALUES = %w[ + EBACC_VALUES = %w[ ancient_hebrew applied_biology applied_chemistry - applied_computing applied_physics arabic_languages - art_and_design biology + chemistry + chinese_languages + computer_science + english_studies + environmental_sciences + french_language + general_sciences + geography + german_language + history + italian_language + latin_language + materials_science + mathematics + modern_languages + physics + portuguese_language + russian_languages + spanish_language + statistics + ].freeze + + NON_EBACC_VALUES = %w[ + applied_computing + art_and_design business_management business_studies - chemistry child_development - chinese_languages citizenship classical_greek_studies classical_studies - computer_science construction_and_the_built_environment dance design @@ -78,55 +70,40 @@ def create(value:) drama early_years_teaching economics - english_studies - environmental_sciences food_and_beverage_studies - french_language general_or_integrated_engineering - general_sciences - geography - german_language graphic_design hair_and_beauty_sciences health_and_social_care health_studies historical_linguistics - history hospitality information_technology - italian_language - latin_language law manufacturing_engineering - materials_science - mathematics media_and_communication_studies - modern_languages music_education_and_teaching performing_arts philosophy physical_education - physics - portuguese_language primary_teaching - production_and_manufacturing_engineering product_design + production_and_manufacturing_engineering psychology public_services recreation_and_leisure_studies religious_studies retail_management - russian_languages social_sciences - spanish_language specialist_teaching_primary_with_mathematics - sports_management sport_and_exercise_sciences - statistics + sports_management textiles_technology travel_and_tourism uk_government_parliamentary_studies welsh_language ].freeze + + ALL_VALUES = (EBACC_VALUES + NON_EBACC_VALUES).sort end end diff --git a/spec/models/subject_spec.rb b/spec/models/subject_spec.rb index e10a8b4df5..90c6bec0f2 100644 --- a/spec/models/subject_spec.rb +++ b/spec/models/subject_spec.rb @@ -18,4 +18,18 @@ expect(find.second.value).to eq("economics") end end + + describe "#ebacc?" do + subject(:ebacc?) { described_class.find([value]).first.ebacc? } + + context "with an EBacc subject" do + let(:value) { "ancient_hebrew" } + it { is_expected.to be true } + end + + context "with a non-EBacc subject" do + let(:value) { "applied_computing" } + it { is_expected.to be false } + end + end end From 623448b7c9579af76bc38c72ffd160b32b94f21d Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 16 May 2024 12:27:15 +0100 Subject: [PATCH 5/5] Count EBaac countries differently We want to count all the submissions, not just the awarded ones. --- app/lib/analytics/publication_extract.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/lib/analytics/publication_extract.rb b/app/lib/analytics/publication_extract.rb index 008a9e979c..0b6e4e271a 100644 --- a/app/lib/analytics/publication_extract.rb +++ b/app/lib/analytics/publication_extract.rb @@ -18,7 +18,7 @@ def call declines = declined_application_forms(country) withdraws = withdrawn_application_forms(country) - awarded = awards.count + submissions_with_subjects = submissions.where.not(subjects: []) induction_required = awards @@ -27,32 +27,32 @@ def call percent_induction_required = ( - if awarded.zero? + if awards.empty? 0 else - ((induction_required.to_f / awarded) * 100).round + ((induction_required.to_f / awards.count) * 100).round end ) { country_name: CountryName.from_country(country), applications: submissions.count, - assessed: awarded + declines.count, - awarded:, + assessed: awards.count + declines.count, + awarded: awards.count, declined: declines.count, withdrawn: withdraws.count, awaiting_decision: - submissions.count - awarded - declines.count - withdraws.count, + submissions.count - awards.count - declines.count - withdraws.count, awardees_with_only_ebacc_subject_or_subjects: - awards.count do |application_form| + submissions_with_subjects.count do |application_form| has_only_ebacc_subjects?(application_form) end, awardees_with_no_ebacc_subjects: - awards.count do |application_form| + submissions_with_subjects.count do |application_form| has_no_ebacc_subjects?(application_form) end, awardees_with_a_mix_of_subjects_at_least_one_is_ebacc: - awards.count do |application_form| + submissions_with_subjects.count do |application_form| !has_only_ebacc_subjects?(application_form) && !has_no_ebacc_subjects?(application_form) end,