|
| 1 | +# Response Areas |
| 2 | + |
| 3 | +A **response area** is where a student answers part of a question and how that |
| 4 | +answer is auto-marked. in2lambda can carry response areas from the source |
| 5 | +document all the way into the imported Lambda Feedback JSON. |
| 6 | + |
| 7 | +## The model |
| 8 | + |
| 9 | +{class}`in2lambda.api.response_area.ResponseArea` holds four things: |
| 10 | + |
| 11 | +| Field | Meaning | Import JSON | |
| 12 | +| --- | --- | --- | |
| 13 | +| `response_type` | input widget - `EXPRESSION`, `NUMBER`, `NUMERIC_UNITS`, `BOOLEAN`, `TEXT`, `ESSAY`, `CODE`, ... | `response.responseInput.responseType` | |
| 14 | +| `answer` | the reference answer, as a string | `response.responseInput.answer` | |
| 15 | +| `evaluation_function` | which evaluation function grades the response | `evaluationFunctionName` | |
| 16 | +| `grade_params` | that function's parameters | `gradeParams` | |
| 17 | + |
| 18 | +`config` (extra `responseInput` settings, e.g. `{"language": "python"}` for |
| 19 | +`CODE`) and `pre_response_text` / `post_response_text` round it out. Everything |
| 20 | +else in the on-import entry - feedback colours, `inputSymbols`, `tests`, |
| 21 | +`cases`, ... - comes from |
| 22 | +`in2lambda/json_convert/minimal_template_response_area.json` and is not something |
| 23 | +a filter sets. |
| 24 | + |
| 25 | +A filter attaches one with |
| 26 | +{meth}`~in2lambda.api.question.Question.add_response_area`: |
| 27 | + |
| 28 | +```python |
| 29 | +from in2lambda.api.response_area import ResponseArea |
| 30 | + |
| 31 | +set.current_question.add_response_area( |
| 32 | + ResponseArea("EXPRESSION", "pi*d", "compareExpressions", {"rtol": 0.01}) |
| 33 | +) |
| 34 | +``` |
| 35 | + |
| 36 | +Parts with no response area import exactly as before, with `"responseAreas": []`. |
| 37 | + |
| 38 | +## The evaluation-function registry |
| 39 | + |
| 40 | +{data}`in2lambda.response_areas.EVALUATION_FUNCTIONS` is in2lambda's model of the |
| 41 | +functions documented in the [Lambda Feedback evaluation-function |
| 42 | +reference](https://docs.lambdafeedback.com/teacher/reference/evaluation_functions/). |
| 43 | +Each entry lists the response types it pairs with and its parameters (name, |
| 44 | +type, default, help). It drives what `in2lambda wizard` proposes and what its |
| 45 | +confirmation prompt offers. |
| 46 | + |
| 47 | +`compareExpressions` and `comparePhysicalQuantities` have complete parameter |
| 48 | +lists; the others carry their common parameters and a `TODO` pointing at the |
| 49 | +per-function docs page. Nothing is *enforced* - `json_convert` passes an unknown |
| 50 | +function or parameter straight through, so a newer function still imports, it |
| 51 | +just is not offered in the menu. |
| 52 | + |
| 53 | +## The `lambda-feedback` block |
| 54 | + |
| 55 | +The [`Markdown` filter](../filters/_autosummary/Markdown) reads a fenced code |
| 56 | +block whose info string is `lambda-feedback`, placed under the part or its |
| 57 | +`## Solution`: |
| 58 | + |
| 59 | +````markdown |
| 60 | +## Solution |
| 61 | + |
| 62 | +$C = \pi d$. |
| 63 | + |
| 64 | +```lambda-feedback |
| 65 | +{ |
| 66 | + "responseType": "EXPRESSION", |
| 67 | + "answer": "pi*d", |
| 68 | + "evaluationFunction": "compareExpressions", |
| 69 | + "gradeParams": {"rtol": 0.01} |
| 70 | +} |
| 71 | +``` |
| 72 | +```` |
| 73 | + |
| 74 | +The body is JSON with the keys `responseType`, `answer`, `evaluationFunction`, |
| 75 | +`gradeParams`, and optionally `config`, `preResponseText`, `postResponseText`. |
| 76 | +`in2lambda wizard` writes these blocks after you confirm its suggestions (see |
| 77 | +[Wizard](../wizard)); you can also hand-write or edit them. Malformed blocks are |
| 78 | +reported by {func}`in2lambda.validation.check_markdown` as a warning - conversion |
| 79 | +still goes ahead, the block is just ignored. |
0 commit comments