Skip to content

Instantly share code, notes, and snippets.

@defong
Last active July 21, 2022 09:54
Show Gist options
  • Save defong/b70f7c2f1605105f1b8ef817dd30f2cc to your computer and use it in GitHub Desktop.
Save defong/b70f7c2f1605105f1b8ef817dd30f2cc to your computer and use it in GitHub Desktop.
[DfE] accredited-body-courses-to-csv.rb
ap = RecruitmentCycle.current.providers.find_by(provider_code: "E75")
nap = {
"1KM": RecruitmentCycle.current.providers.find_by( provider_code: "M82"),
"1K8": RecruitmentCycle.current.providers.find_by( provider_code: "E69"),
"3H5": RecruitmentCycle.current.providers.find_by( provider_code: "E69"),
"285": RecruitmentCycle.current.providers.find_by( provider_code: "F82"),
"1ZH": RecruitmentCycle.current.providers.find_by( provider_code: "F82"),
"2G1": RecruitmentCycle.current.providers.find_by( provider_code: "F82"),
"2D6": RecruitmentCycle.current.providers.find_by( provider_code: "F82")
}
items = ap.current_accredited_courses.map do |c|
p = c.provider
new_accredited_provider_name = "Do nothing"
new_accredited_provider_code = "Do nothing"
if nap[p.provider_code] != nil
new_accredited_provider_name = nap[p.provider_code].provider_name
new_accredited_provider_code = nap[p.provider_code].provider_code
else
end
if ("1KM" == p.provider_code && c.secondary_course?)
new_accredited_provider_name = "Do nothing"
new_accredited_provider_code = "Do nothing"
end
if ["2G1", "2D6"].include?(p.provider_code)
new_accredited_provider_name = "Cannot find Billericay scitt"
new_accredited_provider_code = "Cannot find Billericay scitt"
end
{
course_content_status: c.content_status,
course_name: c.name,
course_code: c.course_code,
provider_name: p.provider_name,
provider_code: p.provider_code,
accredited_provider_name: ap.provider_name,
accredited_provider_code: ap.provider_code,
find: c.findable? ? "https://www.find-postgraduate-teacher-training.service.gov.uk/course/#{p.provider_code}/#{c.course_code}" : "need pub",
pub: "https://www.publish-teacher-training-courses.service.gov.uk/publish/organisations/#{p.provider_code}/2022/courses/#{c.course_code}",
new_accredited_provider_name: new_accredited_provider_name,
new_accredited_provider_code: new_accredited_provider_code,
}
end
CSV.open("#{Rails.configuration.database_configuration["development"]["database"]}-masters-of-sql.csv", "wb") do |csv|
csv << items.first.keys
items.each do |hash|
csv << hash.values
end
end
items = RecruitmentCycle.current.providers.find_by(provider_code: "U80").courses.map do |course|
course.attributes.merge(
{
"Course_Enrichment": course.latest_published_enrichment,
"status": course.latest_published_enrichment&.status,
about_course: course.latest_published_enrichment&.about_course,
course_length: course.latest_published_enrichment&.course_length,
fee_details: course.latest_published_enrichment&.fee_details,
fee_international: course.latest_published_enrichment&.fee_international,
fee_uk_eu: course.latest_published_enrichment&.fee_uk_eu,
financial_support: course.latest_published_enrichment&.financial_support,
how_school_placements_work: course.latest_published_enrichment&.how_school_placements_work,
interview_process: course.latest_published_enrichment&.interview_process,
other_requirements: course.latest_published_enrichment&.other_requirements,
personal_qualities: course.latest_published_enrichment&.personal_qualities,
required_qualifications: course.latest_published_enrichment&.required_qualifications,
salary_details: course.latest_published_enrichment&.salary_details,
last_published_timestamp_utc: course.latest_published_enrichment&.last_published_timestamp_utc,
updated_at: course.latest_published_enrichment&.updated_at,
created_at: course.latest_published_enrichment&.created_at,
}
)
end
CSV.open("#{Rails.configuration.database_configuration["development"]["database"]}-ucl.csv", "wb") do |csv|
csv << items.first.keys
items.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