Last active
August 26, 2021 11:08
-
-
Save defong/5937251388521981cb1f0963553fa906 to your computer and use it in GitHub Desktop.
[DfE] pe_allocations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####### | |
# This is the latest (previous courses) | |
# flatten exploded courses over allocations + leftover allocations | |
# to use rails c | |
# copy and paste dump tip | |
####### | |
courses = Subject.find_by(subject_code: "C6").courses.with_recruitment_cycle(RecruitmentCycle.next.year).with_funding_types(["fee"]) | |
from_courses = courses.map do |c| | |
provider_code = c.provider.provider_code | |
accredited_body_code = c.accredited_body_code == nil ? provider_code : c.accredited_body_code | |
allocation = RecruitmentCycle.current.allocations.find_by(provider_code: provider_code, accredited_body_code: accredited_body_code) | |
has_allocation = allocation != nil | |
has_declined = allocation&.declined? | |
action_notes = if has_allocation | |
if has_declined | |
"can delete course (declined allocation)" | |
else | |
"can keep course (has allocation)" | |
end | |
else | |
"can delete course (no allocation)" | |
end | |
url = "https://www.publish-teacher-training-courses.service.gov.uk/organisations/organisations/#{provider_code}/2022/courses/#{c.course_code}" | |
x = { | |
has_allocation: has_allocation, | |
has_course: true, | |
allocation__id: allocation&.id, | |
allocation__number_of_places: allocation&.number_of_places, | |
course__id: c.id, | |
course__course_code: c.course_code, | |
training_provider_code: provider_code, | |
accredited_body_code: accredited_body_code, | |
course__subjects_count: c.subjects.count, | |
course__notes: c.to_s, | |
training_provider__notes: c.provider.to_s, | |
accredited_body__notes: c.accrediting_provider&.to_s, | |
note: "sourced from pe courses to allocation", | |
action_notes: action_notes, | |
has_declined: has_declined, | |
allocation_request_type: allocation&.request_type, | |
url: url | |
} | |
x | |
end | |
end | |
from_allocations = (RecruitmentCycle.current.allocations.where.not id: (from_courses.collect do |c| c[:allocation__id] end).compact).map do |allocation| | |
provider_code = allocation.provider_code | |
accredited_body_code = allocation.accredited_body_code | |
provider = RecruitmentCycle.next.providers.find_by(provider_code: provider_code) | |
accrediting_provider = RecruitmentCycle.next.providers.find_by(provider_code: accredited_body_code) | |
has_declined = allocation&.declined? | |
action_notes = if has_declined | |
"can ignore create course (declined allocation)" | |
else | |
"can create course (has no course)" | |
end | |
url = "https://www.publish-teacher-training- courses.service.gov.uk/organisations/organisations/#{provider_code}/2022/courses" | |
x = { | |
has_allocation: true, | |
has_course: false, | |
allocation__id: allocation&.id, | |
allocation__number_of_places: allocation&.number_of_places, | |
course__id: nil, | |
course__course_code: nil, | |
training_provider_code: provider_code, | |
accredited_body_code: accredited_body_code, | |
course__subjects_count: nil, | |
course__notes: nil, | |
training_provider__notes: provider.to_s, | |
accredited_body__notes: accrediting_provider&.to_s, | |
note: "sourced from leftover allocation", | |
action_notes: "can create corpse (has no course)", | |
has_declined: has_declined, | |
allocation_request_type: allocation&.request_type, | |
url: url | |
} | |
x | |
end | |
xxxx = from_courses + from_allocations | |
CSV.open("#{Rails.configuration.database_configuration["development"]["database"]}-pe-courses-vs-allocations.csv", "wb") do |csv| | |
csv << xxxx.first.keys | |
xxxx.each do |hash| | |
csv << hash.values | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment