Skip to content

Commit

Permalink
Merge pull request #2208 from DFE-Digital/improve-analytics-task
Browse files Browse the repository at this point in the history
Further improvements to data publication task
  • Loading branch information
thomasleese authored May 16, 2024
2 parents 4c8d7c0 + 623448b commit 6f5cea2
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 70 deletions.
31 changes: 21 additions & 10 deletions app/lib/analytics/publication_extract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,55 @@ 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)

awarded = awards.count
submissions_with_subjects = submissions.where.not(subjects: [])

induction_required =
awards
.select { |application_form| requires_induction?(application_form) }
.count

percent_induction_required =
(
if awards.empty?
0
else
((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,
induction_required:,
percent_induction_required:
awarded.zero? ? 0 : ((induction_required / awarded) * 100).round(1),
percent_induction_required:,
}
end
end
Expand Down
97 changes: 37 additions & 60 deletions app/models/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,83 +18,92 @@ 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
design_and_technology
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
14 changes: 14 additions & 0 deletions spec/models/subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6f5cea2

Please sign in to comment.