File size: 6,587 Bytes
bee9bbb | 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 | """Deterministic offline catalog seed access."""
from __future__ import annotations
import json
import sqlite3
from pathlib import Path
from typing import Any
CATALOG_SEED_PATH = Path(__file__).resolve().parent / "data" / "catalog.json"
_OBSERVED_DEEP_LEARNING = {
"deep-learning-specialization": {
"level": "Intermediate",
"topic": "Deep Learning",
"duration": "3 months at 10 hours a week",
"rating": 4.8,
"provider": "DeepLearning.AI",
"instructors": ["Andrew Ng", "Two additional instructors"],
"prerequisites": "Recommended experience",
"reviews_summary": "4.8 from 147,224 reviews of courses in this program",
"pricing": "Enroll for free; paid totals unavailable in anonymous source evidence",
"enrollment_tracks": ["Enroll for free", "Paid option details unavailable"],
"syllabus": [
"Neural Networks and Deep Learning",
"Improving Deep Neural Networks",
"Structuring Machine Learning Projects",
"Convolutional Neural Networks",
"Sequence Models",
],
"source_evidence_classification": "directly-observed",
},
"neural-networks-deep-learning": {
"level": "Intermediate",
"topic": "Neural Networks",
"duration": "3 weeks at 10 hours a week",
"rating": 4.9,
"provider": "DeepLearning.AI",
"instructors": ["Andrew Ng", "Two additional instructors"],
"prerequisites": "Recommended experience",
"reviews_summary": "4.9 from 123,795 reviews",
"pricing": "Enroll for free; paid totals unavailable in anonymous source evidence",
"enrollment_tracks": ["Enroll for free", "Paid option details unavailable"],
"syllabus": [
"Neural network foundations",
"Shallow neural networks",
"Deep neural networks",
"Model parameters and assignments",
],
"source_evidence_classification": "directly-observed",
},
}
_OBSERVED_COMPONENT_IDS = {
"improving-deep-neural-networks",
"structuring-machine-learning-projects",
"convolutional-neural-networks",
}
_LANGUAGE_BY_ID = {
"algorithms": "Spanish",
"business-strategy": "Spanish",
"digital-marketing": "French",
"nutrition-wellness": "Spanish",
"public-health": "French",
"spanish-beginners": "Spanish",
"french-communication": "French",
"web-development": "French",
}
_SCHEDULE_BY_ID = {
"algorithms": "Self-paced",
"business-strategy": "Self-paced",
"financial-accounting": "Fixed schedule",
"mandarin-basics": "Self-paced",
"medical-neuroscience": "Fixed schedule",
"nutrition-wellness": "Self-paced",
"spanish-beginners": "Fixed schedule",
"web-development": "Fixed schedule",
}
def _complete_record(record: dict[str, Any], index: int) -> dict[str, Any]:
"""Add explicit offline detail fields without claiming unavailable source facts."""
completed = dict(record)
observed = _OBSERVED_DEEP_LEARNING.get(record["id"])
if observed is not None:
completed.update(observed)
else:
levels = ("Beginner", "Intermediate", "Advanced")
completed.update(
{
"level": levels[index % len(levels)],
"topic": record["title"],
"duration": f"{4 + (index % 3) * 2} weeks at 4 hours a week",
"rating": float(record.get("rating", 4.5 + (index % 5) / 10)),
"provider": record.get("provider") or (
"DeepLearning.AI"
if record.get("parent_specialization_id")
else "Coursera Offline Catalog"
),
"instructors": record.get("instructors") or (
["Andrew Ng", "Offline course team"]
if record.get("parent_specialization_id")
else ["Offline Faculty"]
),
"prerequisites": record.get("prerequisites") or "No prior experience required",
"reviews_summary": (
"Source exposed this component title; review details are an offline simulation"
if record["id"] in _OBSERVED_COMPONENT_IDS
else "Deterministic synthetic learner summary"
),
"pricing": "Free offline preview; local-sandbox paid track available",
"enrollment_tracks": [
"Free offline preview",
"Paid certificate (local sandbox)",
],
"syllabus": [
f"Foundations of {record['title']}",
"Guided practice",
"Offline capstone review",
],
"source_evidence_classification": (
"structural-only"
if record["id"] in _OBSERVED_COMPONENT_IDS
else "inferred-architecture"
if record["id"] == "sequence-models"
else "truthful-simulation"
),
}
)
completed["language"] = _LANGUAGE_BY_ID.get(record["id"], "English")
completed["schedule"] = _SCHEDULE_BY_ID.get(record["id"], "Flexible schedule")
return completed
def load_catalog_seed() -> list[dict[str, Any]]:
"""Load a fresh copy of the site-owned catalog seed."""
value = json.loads(CATALOG_SEED_PATH.read_text(encoding="utf-8"))
if not isinstance(value, list):
raise ValueError("catalog seed must be an array")
return [_complete_record(record, index) for index, record in enumerate(value)]
def reset_catalog(connection: sqlite3.Connection) -> None:
"""Replace catalog state with the canonical site-owned seed."""
records = load_catalog_seed()
with connection:
connection.execute(
"""
CREATE TABLE IF NOT EXISTS coursera_catalog (
id TEXT PRIMARY KEY,
title TEXT NOT NULL,
record_json TEXT NOT NULL
)
"""
)
connection.execute("DELETE FROM coursera_catalog")
connection.executemany(
"INSERT INTO coursera_catalog (id, title, record_json) VALUES (?, ?, ?)",
[
(
record["id"],
record["title"],
json.dumps(record, ensure_ascii=False, sort_keys=True, separators=(",", ":")),
)
for record in records
],
)
|