Spaces:
Running
Running
File size: 23,475 Bytes
f36156f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 | """
Seed syllabus structure trees for every subject in the registry.
Why this exists
---------------
The data API ships with a SUBJECT_REGISTRY (24 Cambridge/ZIMSEC subjects) but the
syllabus trees in Firebase were never populated. With no tree, the app server has
nothing to scaffold a learning path on, so every subject showed empty topic lists
and "0 of 0 lessons". Lessons and quizzes are generated by AI at runtime per node,
so a subject only needs a faithful tree of topic -> [lessons] to become usable.
This script holds an AI-authored structure for each subject (real syllabus topics
and the sub-lessons under them), turns it into the tree shape the app expects, and
POSTs the whole batch to the data API's /v1/admin/seed-structures endpoint.
Tree node shape consumed by the app:
{ "id": "...", "title": "...", "type": "topic" | "lesson", "children": [...] }
Usage
-----
python seed_syllabi.py # seed the live data API
DATA_API_BASE_URL=http://localhost:7860/v1 python seed_syllabi.py
python seed_syllabi.py --dry-run # print what would be sent, send nothing
"""
import os
import sys
import json
import requests
DATA_API_BASE_URL = os.environ.get(
"DATA_API_BASE_URL", "https://rairo-marka-data-api.hf.space/v1"
)
# -----------------------------------------------------------------------------
# Authored syllabus content.
# remote_id -> { topic_title: [lesson_title, ...], ... }
# Topic order is the intended teaching order; lessons sit under each topic.
# -----------------------------------------------------------------------------
SYLLABI = {
# ===================== A-LEVEL =====================
"A_9706": { # Accounting
"The Accounting Cycle": [
"Double-entry bookkeeping", "Books of prime entry",
"The ledger and trial balance", "Accounting concepts and conventions",
],
"Financial Statements": [
"Income statement", "Statement of financial position",
"Accruals and prepayments", "Depreciation of non-current assets",
"Irrecoverable and doubtful debts",
],
"Partnership Accounts": [
"Appropriation of profit", "Capital and current accounts",
"Goodwill", "Admission and retirement of partners",
],
"Company Accounts": [
"Share capital and reserves", "Issue of shares and debentures",
"Published financial statements", "Statement of cash flows",
],
"Cost and Management Accounting": [
"Cost classification", "Marginal costing", "Absorption costing",
"Break-even analysis", "Budgeting and budgetary control",
],
"Analysis and Communication": [
"Accounting ratios", "Interpretation of financial statements",
],
},
"A_9700": { # Biology
"Cell Structure": [
"Microscopy and magnification", "Prokaryotic and eukaryotic cells",
"Cell organelles", "Cell membranes and transport",
],
"Biological Molecules": [
"Carbohydrates", "Lipids", "Proteins", "Water and inorganic ions", "Enzymes",
],
"Genetic Information": [
"DNA structure and replication", "Protein synthesis",
"Mitosis and the cell cycle", "Meiosis and variation",
],
"Transport Systems": [
"Transport in plants", "Transport in mammals",
"The mammalian heart", "Haemoglobin and gas transport",
],
"Disease and Immunity": [
"Infectious diseases", "Antibiotics", "The immune system", "Vaccination",
],
"Energy and Coordination": [
"Photosynthesis", "Respiration", "Homeostasis", "Nervous coordination",
],
},
"A_9609": { # Business
"Business and its Environment": [
"Enterprise and entrepreneurs", "Business structure",
"Size of business", "Business objectives", "Stakeholders in business",
],
"Human Resource Management": [
"Motivation theories", "Leadership and management styles",
"Human resource planning", "Organisation structure",
],
"Marketing": [
"Marketing planning", "Market research", "The marketing mix", "Marketing strategy",
],
"Operations Management": [
"Operations planning", "Inventory management",
"Capacity utilisation", "Quality management", "Lean production",
],
"Finance and Accounting": [
"Sources of finance", "Costs and break-even",
"Budgets and variances", "Investment appraisal",
],
"Strategic Management": [
"Strategic analysis (SWOT and PEST)", "Strategic choice", "Managing change",
],
},
"A_9701": { # Chemistry
"Atomic Structure": [
"Atoms and isotopes", "Electronic configuration",
"Ionisation energies", "Mass spectrometry",
],
"Chemical Bonding": [
"Ionic bonding", "Covalent bonding", "Shapes of molecules",
"Intermolecular forces", "Metallic bonding",
],
"Chemical Energetics": [
"Enthalpy changes", "Hess's law", "Bond energies", "Born-Haber cycles",
],
"Equilibria": [
"Reversible reactions", "Kc and Kp", "Le Chatelier's principle",
"Acids and bases", "pH and buffer calculations",
],
"Reaction Kinetics": [
"Rates of reaction", "Rate equations", "Reaction mechanisms", "Catalysis",
],
"Organic Chemistry": [
"Hydrocarbons", "Halogenoalkanes", "Alcohols and esters",
"Carbonyl compounds", "Organic analysis",
],
},
"A_9618": { # Computer Science
"Information Representation": [
"Number systems", "Binary and hexadecimal", "Data types",
"Character sets and image representation",
],
"Communication and Networking": [
"Networks and topologies", "Internet technologies", "Protocols",
],
"Hardware and Processors": [
"Logic gates", "Boolean algebra", "CPU architecture", "Assembly language",
],
"System Software": [
"Operating systems", "Language translators", "Memory management",
],
"Databases": [
"Relational databases", "Normalisation", "SQL", "Database management systems",
],
"Algorithms and Programming": [
"Programming paradigms", "Data structures", "Searching and sorting",
"Recursion", "Abstract data types",
],
},
"A_9708": { # Economics
"Basic Economic Ideas": [
"Scarcity and choice", "Factors of production",
"Production possibility curves", "Specialisation and exchange",
],
"The Price System": [
"Demand and supply", "Elasticities", "Market equilibrium",
"Consumer and producer surplus",
],
"Market Failure": [
"Externalities", "Public goods", "Information failure",
"Government intervention",
],
"The Macroeconomy": [
"Aggregate demand and supply", "National income", "Economic growth",
"Inflation and unemployment",
],
"Government Macro Policy": [
"Fiscal policy", "Monetary policy", "Supply-side policy",
"Balance of payments",
],
"International Economics": [
"Exchange rates", "Trade and protectionism", "Globalisation",
],
},
"A_9231": { # Further Mathematics
"Further Pure 1": [
"Roots of polynomial equations", "Rational functions and graphs",
"Summation of series", "Matrices", "Polar coordinates",
],
"Further Pure 2": [
"Hyperbolic functions", "Further integration",
"Complex numbers", "Differential equations",
],
"Further Mechanics": [
"Momentum and impulse", "Circular motion",
"Work, energy and power", "Simple harmonic motion",
],
"Further Probability and Statistics": [
"Continuous random variables", "Poisson distribution",
"Hypothesis testing", "Chi-squared tests",
],
},
"A_9489": { # History
"Modern Europe 1750-1921": [
"The French Revolution", "The Industrial Revolution",
"Nationalism and unification", "The Russian Revolution",
],
"International Relations 1871-1945": [
"Origins of the First World War", "The Treaty of Versailles",
"Rise of dictatorships", "Origins of the Second World War",
],
"The Cold War": [
"Origins of the Cold War", "Berlin and Cuba crises",
"Détente", "The end of the Cold War",
],
"African History": [
"Colonialism in Africa", "African nationalism",
"Decolonisation", "Post-independence Africa",
],
},
"A_9695": { # Literature in English
"Poetry": [
"Reading and responding to poetry", "Form and structure",
"Imagery and language", "Comparative analysis",
],
"Prose": [
"The novel and narrative voice", "Characterisation",
"Themes and context", "Critical interpretation",
],
"Drama": [
"Dramatic techniques", "Tragedy", "Comedy", "Staging and performance",
],
"Shakespeare": [
"Shakespearean language", "Themes and ideas",
"Character study", "Critical perspectives",
],
"Critical Skills": [
"Unseen criticism", "Contextual analysis", "Essay writing",
],
},
"A_9709": { # Mathematics
"Pure Mathematics 1": [
"Quadratics", "Functions", "Coordinate geometry", "Circular measure",
"Trigonometry", "Series", "Differentiation", "Integration",
],
"Pure Mathematics 3": [
"Algebra", "Logarithmic and exponential functions",
"Trigonometry", "Differentiation and integration",
"Numerical solution of equations", "Vectors",
"Differential equations", "Complex numbers",
],
"Mechanics": [
"Forces and equilibrium", "Kinematics of motion",
"Newton's laws of motion", "Energy, work and power", "Momentum",
],
"Probability and Statistics": [
"Representation of data", "Permutations and combinations",
"Probability", "Discrete random variables", "The normal distribution",
],
},
"A_9702": { # Physics
"Mechanics": [
"Kinematics", "Dynamics", "Forces and equilibrium",
"Work, energy and power", "Momentum",
],
"Matter and Materials": [
"Density and pressure", "Deformation of solids", "Phases of matter",
],
"Oscillations and Waves": [
"Wave properties", "Superposition", "Stationary waves",
"Simple harmonic motion", "The Doppler effect",
],
"Electricity and Magnetism": [
"Electric fields", "Current electricity", "D.C. circuits",
"Magnetic fields", "Electromagnetic induction",
],
"Modern Physics": [
"Quantum physics", "The photoelectric effect",
"Atomic and nuclear physics", "Radioactivity",
],
"Thermal Physics": [
"Temperature and thermal energy", "Ideal gases", "Thermodynamics",
],
},
"A_9699": { # Sociology
"Socialisation and Identity": [
"Culture and identity", "Socialisation",
"Social control", "Nature versus nurture",
],
"Sociological Theory": [
"Functionalism", "Marxism", "Feminism", "Social action theory",
],
"Family": [
"Family forms and diversity", "Changing family roles",
"Marriage and divorce", "Childhood",
],
"Education": [
"The role of education", "Educational achievement",
"The hidden curriculum", "Education policy",
],
"Research Methods": [
"Quantitative methods", "Qualitative methods",
"Sampling", "Reliability and validity",
],
"Social Inequality": [
"Class inequality", "Gender inequality", "Ethnicity", "Poverty",
],
},
"A_9395": { # Travel & Tourism
"The Travel and Tourism Industry": [
"Structure of the industry", "Types of tourism",
"Travel organisations", "Sustainable tourism",
],
"Features of Destinations": [
"Destination appeal", "Tourist motivations and typologies",
"Destination management",
],
"Customer Service": [
"Customer needs", "Quality service", "Handling complaints", "Selling skills",
],
"Marketing in Travel and Tourism": [
"The marketing mix", "Market research", "Promotion", "Branding",
],
"Tourism Development": [
"Economic impacts", "Social and cultural impacts",
"Environmental impacts", "Managing tourism",
],
},
# ===================== O-LEVEL / IGCSE =====================
"O_0452": { # Accounting
"Introduction to Accounting": [
"The accounting equation", "Double entry bookkeeping",
"Books of prime entry", "The ledger and trial balance",
],
"Financial Statements": [
"Income statement", "Statement of financial position",
"Accruals and prepayments", "Depreciation",
],
"Accounting for Different Entities": [
"Sole traders", "Partnerships", "Limited companies",
"Non-profit organisations",
],
"Verification and Control": [
"Bank reconciliation statements", "Control accounts",
"Correction of errors", "Suspense accounts",
],
"Analysis and Interpretation": [
"Accounting ratios", "Interpreting accounts",
],
},
"O_0610": { # Biology
"Characteristics and Cells": [
"Characteristics of living organisms", "Cell structure",
"Movement in and out of cells", "Classification",
],
"Molecules and Nutrition": [
"Biological molecules", "Enzymes",
"Nutrition in plants", "Nutrition in humans",
],
"Transport and Respiration": [
"Transport in plants", "Transport in animals",
"Gas exchange", "Respiration",
],
"Coordination and Homeostasis": [
"The nervous system", "Hormones", "Homeostasis", "Excretion",
],
"Reproduction and Inheritance": [
"Reproduction in plants", "Reproduction in humans",
"Inheritance", "Variation and selection",
],
"Ecology and Human Impact": [
"Organisms and their environment",
"Human influences on ecosystems", "Biotechnology",
],
},
"O_0450": { # Business Studies
"Business Activity": [
"Purpose and nature of business", "Classification of business",
"Enterprise and entrepreneurs", "Business growth",
],
"People in Business": [
"Motivation", "Organisation and management",
"Recruitment and training", "Communication",
],
"Marketing": [
"Market research", "The marketing mix", "Marketing strategy",
],
"Operations Management": [
"Production methods", "Costs and break-even",
"Achieving quality", "Location decisions",
],
"Finance": [
"Sources of finance", "Cash flow forecasting",
"Financial statements", "Ratio analysis",
],
},
"O_0620": { # Chemistry
"Matter and Atoms": [
"Particulate nature of matter", "Atomic structure",
"The periodic table", "Chemical bonding",
],
"Stoichiometry": [
"Formulae and equations", "The mole concept", "Reacting masses",
],
"Electrochemistry and Energetics": [
"Electrolysis", "Energy changes", "Rates of reaction",
"Reversible reactions",
],
"Acids, Bases and Salts": [
"Acids and bases", "Preparation of salts", "Identification of ions",
],
"Metals and Periodicity": [
"Properties of metals", "The reactivity series", "Extraction of metals",
],
"Organic and Environmental Chemistry": [
"Fuels", "Alkanes and alkenes", "Alcohols", "Air and water",
],
},
"O_0478": { # Computer Science
"Data Representation": [
"Binary systems", "Hexadecimal", "Data storage and compression",
],
"Communication and Networking": [
"Data transmission", "Networks", "The internet", "Security",
],
"Hardware": [
"Logic gates", "Input and output devices", "Storage devices", "The CPU",
],
"Software": [
"System software", "Application software", "Operating systems",
],
"Programming and Databases": [
"Algorithm design", "Pseudocode and flowcharts",
"Programming concepts", "Databases",
],
},
"O_0500": { # English Language
"Reading Skills": [
"Comprehension", "Summary writing",
"Extended response to reading", "Analysing language",
],
"Directed Writing": [
"Writing for purpose", "Audience and tone",
"Discursive writing", "Argumentative writing",
],
"Composition": [
"Descriptive writing", "Narrative writing", "Planning and structure",
],
"Language Techniques": [
"Vocabulary and style", "Grammar and accuracy", "Punctuation",
],
},
"O_0475": { # English Literature
"Poetry": [
"Reading poetry", "Imagery and figurative language",
"Form and structure", "Comparing poems",
],
"Prose": [
"Studying the novel", "Character and theme",
"Setting and context", "Close reading",
],
"Drama": [
"Studying plays", "Dramatic devices",
"Character and conflict", "Themes",
],
"Critical Writing": [
"Essay structure", "Using quotations", "Personal response",
],
},
"O_0680": { # Environmental Management
"The Lithosphere": [
"Rocks and minerals", "Mining and extraction", "Soil and its management",
],
"The Atmosphere": [
"Atmosphere and climate", "Air pollution", "Climate change",
],
"The Hydrosphere": [
"Water resources", "Water pollution", "Managing water", "The oceans",
],
"The Biosphere": [
"Ecosystems", "Biodiversity", "Human impact", "Conservation",
],
"Population and Sustainability": [
"Population dynamics", "Resources and energy", "Sustainable development",
],
},
"O_0460": { # Geography
"Population and Settlement": [
"Population dynamics", "Migration", "Settlement patterns", "Urbanisation",
],
"The Natural Environment": [
"Plate tectonics", "Rivers", "Coasts", "Weather and climate", "Ecosystems",
],
"Economic Development": [
"Agriculture", "Industry", "Tourism", "Energy", "Development",
],
"Geographical Skills": [
"Map skills", "Data collection", "Interpreting data",
],
},
"O_0470": { # History
"The Nineteenth Century": [
"International relations", "Nationalism", "Empire and colonialism",
],
"The First World War": [
"Causes of the First World War", "The course of the war", "Peace treaties",
],
"Between the Wars": [
"The League of Nations", "Rise of dictatorships",
"Causes of the Second World War",
],
"The Cold War": [
"Origins of the Cold War", "Crises and conflicts", "End of the Cold War",
],
"Depth Study": [
"Germany 1918-1945", "Russia and the USSR", "The United States",
],
},
"O_0625": { # Physics
"General Physics": [
"Measurements", "Motion", "Mass, weight and density",
"Forces", "Energy, work and power", "Pressure",
],
"Thermal Physics": [
"Kinetic theory", "Thermal properties", "Transfer of thermal energy",
],
"Waves": [
"General wave properties", "Light", "Sound",
"The electromagnetic spectrum",
],
"Electricity and Magnetism": [
"Magnetism", "Static electricity", "Current electricity",
"Electrical circuits", "Electromagnetic effects",
],
"Atomic Physics": [
"The nuclear atom", "Radioactivity",
],
},
}
def _slug(text: str) -> str:
keep = [c.lower() if c.isalnum() else "_" for c in text]
out = "".join(keep)
while "__" in out:
out = out.replace("__", "_")
return out.strip("_")[:40]
def build_tree(subject_content: dict) -> list:
"""Convert {topic: [lessons]} into the app's tree node shape."""
tree = []
for t_index, (topic_title, lessons) in enumerate(subject_content.items(), start=1):
topic_id = f"t{t_index}_{_slug(topic_title)}"
children = []
for l_index, lesson_title in enumerate(lessons, start=1):
children.append({
"id": f"{topic_id}_l{l_index}",
"title": lesson_title,
"type": "lesson",
})
tree.append({
"id": topic_id,
"title": topic_title,
"type": "topic",
"children": children,
})
return tree
def main():
dry_run = "--dry-run" in sys.argv
structures = {rid: {"tree": build_tree(content)} for rid, content in SYLLABI.items()}
total_topics = sum(len(s["tree"]) for s in structures.values())
total_lessons = sum(
len(node["children"]) for s in structures.values() for node in s["tree"]
)
print(f"Prepared {len(structures)} subjects, "
f"{total_topics} topics, {total_lessons} lessons.")
if dry_run:
print(json.dumps(structures["A_9709"], indent=2))
print("\n[dry-run] Nothing sent.")
return
url = f"{DATA_API_BASE_URL}/admin/seed-structures"
print(f"POST {url}")
resp = requests.post(url, json={"structures": structures}, timeout=120)
print(f"HTTP {resp.status_code}")
try:
results = resp.json().get("results", {})
ok = sum(1 for r in results.values() if r.get("ok"))
print(f"Seeded OK: {ok}/{len(results)}")
failures = {k: v for k, v in results.items() if not v.get("ok")}
if failures:
print("Failures:", json.dumps(failures, indent=2))
except Exception:
print(resp.text[:1000])
if __name__ == "__main__":
main()
|