File size: 11,481 Bytes
65d68f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * 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);
}