DocDoeAI / src /video-engine /physics /production /chapterHomework.ts
asnannp's picture
deploy: sync backend to Space root (learn-lesson HF cache fix)
65d68f5
Raw History Blame Contribute Delete
11.5 kB
/**
* CHAPTER-SCOPED HOMEWORK DATA
*
* Each chapter has its own homework tasks derived from that chapter's
* official SCERT topics, formulae and exam-question families.
*
* This module prevents the cross-chapter homework data leak where
* Sound Waves homework was incorrectly appended to all 7 chapters.
*/
export type HomeworkTaskType = "explanation" | "diagram" | "numerical" | "comparison";
export interface HomeworkTask {
/** Unique identifier for this task. */
id: string;
/** Task type: explanation, diagram, numerical, or comparison. */
type: HomeworkTaskType;
/** Short imperative instruction. */
text: string;
/** The topic key from the course manifest that this task covers. */
topicKey: string;
/** Formula keys from the course manifest that this task uses. */
formulaKeys: string[];
/** Expected marks for this task. */
marks: number;
}
export interface ChapterHomework {
chapterId: string;
chapterTitle: string;
tasks: HomeworkTask[];
}
const HOMEWORK: Record<string, ChapterHomework> = {
"phy-p1-c1": {
chapterId: "phy-p1-c1",
chapterTitle: "Sound Waves",
tasks: [
{
id: "hw-c1-01",
type: "explanation",
text: "Explain how sound travels through air using the terms compression, rarefaction and longitudinal wave.",
topicKey: "Longitudinal and transverse waves",
formulaKeys: ["v = fλ"],
marks: 4,
},
{
id: "hw-c1-02",
type: "numerical",
text: "A person claps near a cliff and hears the echo after 1.5 seconds. If the speed of sound is 340 m/s, find the distance to the cliff.",
topicKey: "Reflection of sound, echo and reverberation",
formulaKeys: ["distance = vt/2"],
marks: 3,
},
{
id: "hw-c1-03",
type: "comparison",
text: "Distinguish between longitudinal and transverse waves with one example each.",
topicKey: "Longitudinal and transverse waves",
formulaKeys: [],
marks: 3,
},
],
},
"phy-p1-c2": {
chapterId: "phy-p1-c2",
chapterTitle: "Lenses",
tasks: [
{
id: "hw-c2-01",
type: "diagram",
text: "Draw the ray diagram for image formation when an object is placed beyond 2F of a convex lens. Label F, 2F and the image.",
topicKey: "Image formation by convex lens",
formulaKeys: [],
marks: 4,
},
{
id: "hw-c2-02",
type: "numerical",
text: "An object is placed 30 cm from a convex lens of focal length 15 cm. Using the lens formula, find the image distance and magnification.",
topicKey: "Lens formula and magnification",
formulaKeys: ["1/f = 1/v − 1/u"],
marks: 4,
},
{
id: "hw-c2-03",
type: "comparison",
text: "Explain the difference between convex and concave lenses. Give two uses of each.",
topicKey: "Types of lenses",
formulaKeys: [],
marks: 3,
},
{
id: "hw-c2-04",
type: "numerical",
text: "A lens has a focal length of 25 cm. Find its power in dioptres.",
topicKey: "Power of a lens",
formulaKeys: ["P = 1/f"],
marks: 2,
},
],
},
"phy-p1-c3": {
chapterId: "phy-p1-c3",
chapterTitle: "The World of Colours and Vision",
tasks: [
{
id: "hw-c3-01",
type: "explanation",
text: "Explain why the sky appears blue during the day and red at sunrise and sunset.",
topicKey: "Scattering of light",
formulaKeys: [],
marks: 4,
},
{
id: "hw-c3-02",
type: "diagram",
text: "Draw a neat diagram showing the dispersion of white light through a glass prism. Label the colours of the spectrum.",
topicKey: "Dispersion of light",
formulaKeys: [],
marks: 4,
},
{
id: "hw-c3-03",
type: "explanation",
text: "What are the primary colours of light? Explain how white light can be obtained by mixing them.",
topicKey: "Colours of light",
formulaKeys: [],
marks: 3,
},
{
id: "hw-c3-04",
type: "comparison",
text: "Differentiate between myopia and hypermetropia. How is each corrected using lenses?",
topicKey: "Defects of vision",
formulaKeys: [],
marks: 4,
},
],
},
"phy-p1-c4": {
chapterId: "phy-p1-c4",
chapterTitle: "Magnetic Effect of Electric Current",
tasks: [
{
id: "hw-c4-01",
type: "explanation",
text: "Describe Oersted's experiment and explain what it demonstrates about the relationship between electricity and magnetism.",
topicKey: "Oersted's experiment",
formulaKeys: [],
marks: 4,
},
{
id: "hw-c4-02",
type: "explanation",
text: "State Fleming's left-hand rule. Explain the direction of force on a current-carrying conductor placed in a magnetic field.",
topicKey: "Force on a current-carrying conductor",
formulaKeys: [],
marks: 3,
},
{
id: "hw-c4-03",
type: "diagram",
text: "Draw a neat labelled diagram of a simple DC motor and explain its working.",
topicKey: "Electric motor",
formulaKeys: [],
marks: 4,
},
{
id: "hw-c4-04",
type: "comparison",
text: "Differentiate between a solenoid and an electromagnet. Give two applications of electromagnets.",
topicKey: "Solenoid and electromagnet",
formulaKeys: [],
marks: 3,
},
],
},
"phy-p2-c5": {
chapterId: "phy-p2-c5",
chapterTitle: "Electric Energy: Consumption and Conservation",
tasks: [
{
id: "hw-c5-01",
type: "explanation",
text: "State Joule's law of heating and explain the factors on which heat produced depends.",
topicKey: "Heating effect of electric current",
formulaKeys: ["H = I²Rt"],
marks: 4,
},
{
id: "hw-c5-02",
type: "explanation",
text: "Explain why Nichrome is used as the heating element in electrical appliances.",
topicKey: "Heating effect of electric current",
formulaKeys: [],
marks: 2,
},
{
id: "hw-c5-03",
type: "numerical",
text: "A 1500 W electric kettle is used for 2 hours daily for 30 days. Calculate the energy consumed in kWh and the electricity bill if the rate is ₹6 per unit.",
topicKey: "Electric energy and power",
formulaKeys: ["E = Pt"],
marks: 4,
},
{
id: "hw-c5-04",
type: "explanation",
text: "Explain TOD (Time of Day) billing and suggest two ways to reduce your household carbon footprint through energy conservation.",
topicKey: "Conservation of electric energy",
formulaKeys: [],
marks: 3,
},
],
},
"phy-p2-c6": {
chapterId: "phy-p2-c6",
chapterTitle: "Electromagnetic Induction in Daily Life",
tasks: [
{
id: "hw-c6-01",
type: "explanation",
text: "Describe the electromagnetic induction experiment using a bar magnet and a coil connected to a galvanometer.",
topicKey: "Electromagnetic induction",
formulaKeys: [],
marks: 4,
},
{
id: "hw-c6-02",
type: "diagram",
text: "Draw a neat labelled diagram of an AC generator and explain its working principle.",
topicKey: "Electric generator",
formulaKeys: [],
marks: 4,
},
{
id: "hw-c6-03",
type: "comparison",
text: "Differentiate between a step-up transformer and a step-down transformer with a diagram.",
topicKey: "Transformer",
formulaKeys: ["Vₛ/Vₚ = Nₛ/Nₚ"],
marks: 4,
},
{
id: "hw-c6-04",
type: "explanation",
text: "Explain why electric power is transmitted at high voltage over long distances.",
topicKey: "Power transmission",
formulaKeys: [],
marks: 3,
},
],
},
"phy-p2-c7": {
chapterId: "phy-p2-c7",
chapterTitle: "Mechanical Advantage in Action",
tasks: [
{
id: "hw-c7-01",
type: "diagram",
text: "Explain the three orders of levers with one example each. Draw diagrams showing the position of fulcrum, load and effort.",
topicKey: "Levers",
formulaKeys: [],
marks: 4,
},
{
id: "hw-c7-02",
type: "comparison",
text: "Compare a fixed pulley and a movable pulley in terms of mechanical advantage and the direction of effort.",
topicKey: "Pulley systems",
formulaKeys: [],
marks: 3,
},
{
id: "hw-c7-03",
type: "explanation",
text: "Explain the principle of no gain in work using the example of a lever.",
topicKey: "No gain in work",
formulaKeys: ["load × load arm = effort × effort arm"],
marks: 3,
},
{
id: "hw-c7-04",
type: "numerical",
text: "A box of weight 500 N is pushed up a 5 m inclined plane to a height of 2 m. Find the effort required and the mechanical advantage.",
topicKey: "Inclined plane",
formulaKeys: [],
marks: 3,
},
],
},
};
/**
* Get the chapter-scoped homework for a given chapterId.
* Returns undefined if the chapterId is not recognised.
*/
export function getChapterHomework(chapterId: string): ChapterHomework | undefined {
return HOMEWORK[chapterId];
}
/**
* QA validation: verify homework belongs to the correct chapter.
* Returns a list of issues found.
*/
export function validateHomework(chapterId: string, homeworkText: string): string[] {
const issues: string[] = [];
const chapter = HOMEWORK[chapterId];
if (!chapter) {
issues.push(`Unknown chapterId: ${chapterId}`);
return issues;
}
const lower = homeworkText.toLowerCase();
// Cross-chapter leak detection
const crossChapterPatterns: Array<[string, RegExp, string]> = [
["phy-p1-c1", /sound travels through air|v\s*=\s*f[λl]/i, "Sound Waves"],
["phy-p1-c2", /lens formula|1\/f\s*=\s*1\/v|convex lens/i, "Lenses"],
["phy-p1-c3", /dispersion|prism|sky.*blue|primary colour/i, "Colours and Vision"],
["phy-p1-c4", /oersted|fleming|solenoid|dc motor/i, "Magnetic Effect"],
["phy-p2-c5", /joule.*law|nichrome|kwh|tod billing/i, "Electric Energy"],
["phy-p2-c6", /electromagnetic induction|ac generator|transformer/i, "Electromagnetic Induction"],
["phy-p2-c7", /lever.*order|pulley|inclined plane|mechanical advantage/i, "Mechanical Advantage"],
];
for (const [otherChapterId, pattern, name] of crossChapterPatterns) {
if (otherChapterId !== chapterId && pattern.test(lower)) {
issues.push(`Homework contains ${name} content but chapterId is ${chapterId}`);
}
}
// Check task count
if (chapter.tasks.length < 2 || chapter.tasks.length > 4) {
issues.push(`Chapter ${chapterId} has ${chapter.tasks.length} tasks (expected 2-4)`);
}
return issues;
}
/**
* Format homework tasks for display in the HomeworkVisual.
*/
export function formatHomeworkTasks(chapterId: string): string[] {
const chapter = HOMEWORK[chapterId];
if (!chapter) return [];
return chapter.tasks.map((task) => task.text);
}