Skip to content

Instantly share code, notes, and snippets.

@carvil
Last active December 19, 2016 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carvil/20cb1aa5f49524d95afd6c1adbb7fcde to your computer and use it in GitHub Desktop.
Save carvil/20cb1aa5f49524d95afd6c1adbb7fcde to your computer and use it in GitHub Desktop.
hierarchy = {}
content_id = 'c58fdadd-7743-46d6-9629-90bb3ccc4ef0'
def guidance_document_types
[
'statutory_guidance',
'answer',
'guidance',
'detailed_guidance',
'detailed_guide',
'form',
'guide',
'licence',
'local_transaction',
'map',
'notice',
'programme',
'promotional',
'regulation',
'simple_smart_answer',
'smartanswer',
'manual',
'manual_section',
]
end
def make_it(hierarchy, content_id)
taxon = Taxonomy::BuildTaxon.call(content_id: content_id)
tagged_content = Services.publishing_api.get_linked_items(
content_id,
link_type: "taxons",
fields: %w(base_path document_type)
)
tagged_guidance_content = tagged_content.select do |content|
guidance_document_types.include?(content['document_type'])
end
hierarchy[:name] = taxon.title
puts taxon.title
parents = taxon.parent_taxons.map do |parent|
Taxonomy::BuildTaxon.call(content_id: parent)
end
hierarchy[:parents] = parents.map(&:title)
taxonomy = ExpandedTaxonomy.new(content_id)
taxonomy.build_child_expansion
hierarchy[:children] = []
hierarchy[:number_of_tagged_content] = tagged_content.count
hierarchy[:number_of_tagged_guidance_content] = tagged_guidance_content.count
taxonomy.child_expansion.children.each do |child|
hierarchy[:children] << make_it({}, child.content_id)
end
hierarchy
end
tree = make_it(hierarchy, content_id)
puts tree.to_json
{
"name": "Education, training and skills",
"parents": [
],
"children": [
{
"name": "School education from 5 to 18 years",
"parents": [
"Education, training and skills"
],
"children": [
{
"name": "School curriculum, assessments and performance",
"parents": [
"School education from 5 to 18 years"
],
"children": [
{
"name": "Primary curriculum, key stage 1",
"parents": [
"School curriculum, assessments and performance"
],
"children": [
{
"name": "Phonics",
"parents": [
"Early years curriculum from birth to 5 years",
"Primary curriculum, key stage 1"
],
"children": [
],
"number_of_tagged_content": 81,
"number_of_tagged_guidance_content": 54
},
{
"name": "Assessments",
"parents": [
"Primary curriculum, key stage 1"
],
"children": [
],
"number_of_tagged_content": 19,
"number_of_tagged_guidance_content": 19
},
{
"name": "English",
"parents": [
"Primary curriculum, key stage 1"
],
"children": [
],
"number_of_tagged_content": 13,
"number_of_tagged_guidance_content": 13
},
{
"name": "Maths",
"parents": [
"Primary curriculum, key stage 1"
],
"children": [
],
"number_of_tagged_content": 6,
"number_of_tagged_guidance_content": 6
},
{
"name": "Programmes of study",
"parents": [
"Primary curriculum, key stage 1"
],
"children": [
],
"number_of_tagged_content": 11,
"number_of_tagged_guidance_content": 11
},
{
"name": "Science",
"parents": [
"Primary curriculum, key stage 1"
],
"children": [
],
"number_of_tagged_content": 1,
"number_of_tagged_guidance_content": 1
},
{
"name": "Tests",
"parents": [
"Primary curriculum, key stage 1"
],
"children": [
],
"number_of_tagged_content": 17,
"number_of_tagged_guidance_content": 17
}
],
"number_of_tagged_content": 208,
"number_of_tagged_guidance_content": 83
},
{
"name": "Primary curriculum, key stage 2",
"parents": [
"School curriculum, assessments and performance"
],
"children": [
{
"name": "Phonics",
"parents": [
"Primary curriculum, key stage 2"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Assessments",
"parents": [
"Primary curriculum, key stage 2"
],
"children": [
],
"number_of_tagged_content": 9,
"number_of_tagged_guidance_content": 9
},
{
"name": "English",
"parents": [
"Primary curriculum, key stage 2"
],
"children": [
],
"number_of_tagged_content": 14,
"number_of_tagged_guidance_content": 14
},
{
"name": "Maths",
"parents": [
"Primary curriculum, key stage 2"
],
"children": [
],
"number_of_tagged_content": 6,
"number_of_tagged_guidance_content": 6
},
{
"name": "Programmes of study",
"parents": [
"Primary curriculum, key stage 2"
],
"children": [
],
"number_of_tagged_content": 11,
"number_of_tagged_guidance_content": 11
},
{
"name": "Science",
"parents": [
"Primary curriculum, key stage 2"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Tests",
"parents": [
"Primary curriculum, key stage 2"
],
"children": [
],
"number_of_tagged_content": 32,
"number_of_tagged_guidance_content": 32
}
],
"number_of_tagged_content": 7,
"number_of_tagged_guidance_content": 7
},
{
"name": "Secondary curriculum, key stage 3 and key stage 4",
"parents": [
"School curriculum, assessments and performance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Spiritual, moral, social and cultural development",
"parents": [
"School curriculum, assessments and performance"
],
"children": [
{
"name": "Cultural education",
"parents": [
"Spiritual, moral, social and cultural development"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Religious education",
"parents": [
"Spiritual, moral, social and cultural development"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Promoting British values and citizenship in schools",
"parents": [
"Spiritual, moral, social and cultural development"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Personal, social, health and economic education",
"parents": [
"School curriculum, assessments and performance"
],
"children": [
{
"name": "Sex and relationship education",
"parents": [
"Personal, social, health and economic education"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Physical education",
"parents": [
"School curriculum, assessments and performance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Administration of exams and tests in schools",
"parents": [
"School curriculum, assessments and performance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Key stage 5, AS and A Levels",
"parents": [
"School curriculum, assessments and performance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 28,
"number_of_tagged_guidance_content": 2
},
{
"name": "Governing and managing schools",
"parents": [
"School education from 5 to 18 years"
],
"children": [
{
"name": "Managing school data",
"parents": [
"Governing and managing schools"
],
"children": [
],
"number_of_tagged_content": 14,
"number_of_tagged_guidance_content": 14
},
{
"name": "Copyright for schools",
"parents": [
"Governing and managing schools"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Procurement for schools",
"parents": [
"Governing and managing schools"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School buildings and premises",
"parents": [
"Governing and managing schools"
],
"children": [
],
"number_of_tagged_content": 134,
"number_of_tagged_guidance_content": 45
},
{
"name": "Setting up or shutting down a school",
"parents": [
"Governing and managing schools"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Changing the status of a school",
"parents": [
"Governing and managing schools"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Dealing with complaints about a school",
"parents": [
"Governing and managing schools"
],
"children": [
],
"number_of_tagged_content": 2,
"number_of_tagged_guidance_content": 2
},
{
"name": "Whistleblowing in schools",
"parents": [
"Governing and managing schools"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School insurance and risk management",
"parents": [
"Governing and managing schools"
],
"children": [
],
"number_of_tagged_content": 21,
"number_of_tagged_guidance_content": 16
},
{
"name": "School governance",
"parents": [
"Governing and managing schools"
],
"children": [
{
"name": "Governance partnerships for multiple schools",
"parents": [
"School governance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Pupil participation in school governance",
"parents": [
"School governance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Recruiting and managing school staff",
"parents": [
"Governing and managing schools",
"Teachers and school staff"
],
"children": [
],
"number_of_tagged_content": 12,
"number_of_tagged_guidance_content": 8
}
],
"number_of_tagged_content": 46,
"number_of_tagged_guidance_content": 25
},
{
"name": "Teachers and school staff",
"parents": [
"School education from 5 to 18 years"
],
"children": [
{
"name": "Recruiting and managing school staff",
"parents": [
"Governing and managing schools",
"Teachers and school staff"
],
"children": [
],
"number_of_tagged_content": 12,
"number_of_tagged_guidance_content": 8
},
{
"name": "Teaching standards, conduct and practice",
"parents": [
"Teachers and school staff"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Teacher records",
"parents": [
"Teachers and school staff"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Teacher pay and conditions",
"parents": [
"Teachers and school staff"
],
"children": [
{
"name": "Teacher pensions",
"parents": [
"Teacher pay and conditions"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Teacher training and professional development",
"parents": [
"Teachers and school staff"
],
"children": [
{
"name": "Qualified Teacher Status (QTS)",
"parents": [
"Teacher training and professional development"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Initial Teacher Training (ITT)",
"parents": [
"Teacher training and professional development"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Subject Knowledge Enhancement (SKE)",
"parents": [
"Teacher training and professional development"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "National Professional Qualification for Headship (NPQH)",
"parents": [
"Teacher training and professional development"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Extra-curricular activities for schools",
"parents": [
"School education from 5 to 18 years"
],
"children": [
{
"name": "School trips",
"parents": [
"Extra-curricular activities for schools"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School links with home, community and business",
"parents": [
"School education from 5 to 18 years"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School behaviour and attendance",
"parents": [
"School education from 5 to 18 years"
],
"children": [
{
"name": "School discipline and exclusions",
"parents": [
"School behaviour and attendance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School leaving age",
"parents": [
"School behaviour and attendance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School bullying",
"parents": [
"School behaviour and attendance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Equality and diversity in schools",
"parents": [
"School behaviour and attendance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School absence and truancy",
"parents": [
"School behaviour and attendance"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Careers guidance in schools",
"parents": [
"School education from 5 to 18 years"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School admissions and pupil censuses",
"parents": [
"School education from 5 to 18 years"
],
"children": [
{
"name": "Access to education for minority groups",
"parents": [
"School admissions and pupil censuses"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School meals, transport and uniform",
"parents": [
"School education from 5 to 18 years"
],
"children": [
{
"name": "School meals",
"parents": [
"School meals, transport and uniform"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School transport",
"parents": [
"School meals, transport and uniform"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School uniform",
"parents": [
"School meals, transport and uniform"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Health, safety and pupil wellbeing",
"parents": [
"School education from 5 to 18 years"
],
"children": [
{
"name": "Safeguarding pupils",
"parents": [
"Health, safety and pupil wellbeing"
],
"children": [
{
"name": "Prevent duty for schools",
"parents": [
"Safeguarding pupils"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "e-safety",
"parents": [
"Safeguarding pupils"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Alternatives to school",
"parents": [
"School education from 5 to 18 years"
],
"children": [
{
"name": "Alternative provision and Pupil Referral Units",
"parents": [
"Alternatives to school"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Home schooling",
"parents": [
"Alternatives to school"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "School inspections",
"parents": [
"School education from 5 to 18 years"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 42,
"number_of_tagged_guidance_content": 10
},
{
"name": "Early years curriculum from birth to 5 years",
"parents": [
"Education, training and skills",
"Running a childcare business"
],
"children": [
{
"name": "Phonics",
"parents": [
"Early years curriculum from birth to 5 years",
"Primary curriculum, key stage 1"
],
"children": [
],
"number_of_tagged_content": 81,
"number_of_tagged_guidance_content": 54
}
],
"number_of_tagged_content": 112,
"number_of_tagged_guidance_content": 30
},
{
"name": "Funding and finance for education providers",
"parents": [
"Education, training and skills"
],
"children": [
{
"name": "Funding and finance for schools",
"parents": [
"Funding and finance for education providers"
],
"children": [
{
"name": "16 to 19 funding",
"parents": [
"Funding and finance for schools"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Pupil premium",
"parents": [
"Funding and finance for schools"
],
"children": [
],
"number_of_tagged_content": 33,
"number_of_tagged_guidance_content": 9
},
{
"name": "Schools forums",
"parents": [
"Funding and finance for schools"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 180,
"number_of_tagged_guidance_content": 65
},
{
"name": "Funding and finance for further education providers",
"parents": [
"Funding and finance for education providers"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Funding for special educational needs and disability support",
"parents": [
"Funding and finance for education providers"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 12,
"number_of_tagged_guidance_content": 1
},
{
"name": "Further education, skills and vocational training",
"parents": [
"Education, training and skills"
],
"children": [
{
"name": "Adult and community learning",
"parents": [
"Further education, skills and vocational training"
],
"children": [
{
"name": "Basic skills education",
"parents": [
"Adult and community learning"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Apprenticeships, traineeships and internships",
"parents": [
"Further education, skills and vocational training"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Further education, courses and qualifications",
"parents": [
"Further education, skills and vocational training"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Inspection and performance of further education providers",
"parents": [
"Further education, skills and vocational training"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "University and higher education",
"parents": [
"Education, training and skills"
],
"children": [
{
"name": "Higher education courses and qualifications",
"parents": [
"University and higher education"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Governance and management for higher education institutions",
"parents": [
"University and higher education"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Funding and finance for students",
"parents": [
"Education, training and skills"
],
"children": [
{
"name": "Student loans",
"parents": [
"Funding and finance for students"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Student sponsorship",
"parents": [
"Funding and finance for students"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Financial help for students who are parents",
"parents": [
"Funding and finance for students"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Financial help for international students in the UK",
"parents": [
"Funding and finance for students"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Students with special needs, disabilities or disadvantages",
"parents": [
"Education, training and skills"
],
"children": [
{
"name": "Able, gifted and talented pupils",
"parents": [
"Students with special needs, disabilities or disadvantages"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Special educational needs and disability support in schools",
"parents": [
"Students with special needs, disabilities or disadvantages"
],
"children": [
{
"name": "Assessing pupils with special educational needs",
"parents": [
"Special educational needs and disability support in schools"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "SEND code of practice",
"parents": [
"Special educational needs and disability support in schools"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Vulnerable and disadvantaged pupils",
"parents": [
"Students with special needs, disabilities or disadvantages"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Funding for special educational needs and disability",
"parents": [
"Students with special needs, disabilities or disadvantages"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
},
{
"name": "Support for education work in other countries",
"parents": [
"Education, training and skills"
],
"children": [
],
"number_of_tagged_content": 0,
"number_of_tagged_guidance_content": 0
}
],
"number_of_tagged_content": 29,
"number_of_tagged_guidance_content": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment