Jump to navigation

Class: CustomPart

Numbas.parts.CustomPart

new CustomPart(pathopt, question, parentPart, storeopt)

Custom part - a part type defined in Numbas.custom_part_types.

Parameters:
Name Type Attributes Default Description
path Numbas.parts.partpath <optional>
'p0'
question Numbas.Question
parentPart Numbas.parts.Part
store Numbas.storage.BlankStorage <optional>
Source:

Members

alternativeFeedbackMessage :string

Feedback message shown if this part is used as an alternative.

Type:
Inherited From:
Source:

alternatives :Array.<Numbas.parts.Part>

Child alternative parts.

Type:
Inherited From:
Source:

answered :boolean

Has this part been answered?

Type:
Inherited From:
Source:

creditFraction :Numbas.math.Fraction

Credit as a fraction. Used to avoid simple floating point errors.

Type:
Inherited From:
Source:

customName :string

Custom name for this part, or null if none. Variables will be substituted into this string from the part's scope.

Type:
Inherited From:
Source:

display :Numbas.display.PartDisplay

Associated display object. It is not safe to assume this is always present - in the editor, parts have no display.

Type:
Inherited From:
Source:

doesMarking :boolean

Does this mark do any marking? False for information only parts.

Type:
Inherited From:
Source:

finalised_result :Numbas.marking.finalised_state

The result of the last marking run.

Type:
Inherited From:
Source:

gaps :Array.<Numbas.parts.Part>

Child gapfill parts.

Type:
Inherited From:
Source:

isDirty :boolean

Has the student changed their answer since last submitting?

Type:
Inherited From:
Source:

json :object

JSON defining this part.

Type:
Inherited From:
Source:

locked :boolean

Is this part locked? If false, the student can change and submit their answer.

Type:
Inherited From:
Source:

markingFeedback :Array.<Numbas.parts.feedbackmessage>

Messages explaining how marks were awarded.

Type:
Inherited From:
Source:

markingScript :Numbas.marking.MarkingScript

The script to mark this part - assign credit, and give messages and feedback.

Type:
Inherited From:
Source:

marks :number

Maximum marks available for this part.

Type:
Inherited From:
Source:

name :string

A readable name for this part, to show to the student. Change it with Numbas.parts.Part#setName.

Type:
Inherited From:
Source:

parentPart :Numbas.parts.Part

Reference to parent of this part, if this is a gap or a step.

Type:
Inherited From:
Source:

path :Numbas.parts.partpath

A question-wide unique 'address' for this part.

Type:
Inherited From:
Source:

question :Numbas.Question

The question this part belongs to.

Type:
Inherited From:
Source:

revealed :boolean

Has the answer to this part been revealed?

Type:
Inherited From:
Source:

score :number

Student's score on this part.

Type:
Inherited From:
Source:

settings :object

Properties set when the part is generated.

Type:
Properties:
Name Type Description
stepsPenalty number

Number of marks to deduct when the steps are shown.

enableMinimumMarks boolean

Is there a lower limit on the score the student can be awarded for this part?

minimumMarks number

Lower limit on the score the student can be awarded for this part.

showCorrectAnswer boolean

Show the correct answer on reveal?

showFeedbackIcon boolean

Show the tick/cross feedback symbol after this part is submitted?

hasVariableReplacements boolean

Does this part have any variable replacement rules?

variableReplacementStrategy string

'originalfirst' or 'alwaysreplace'.

exploreObjective string

Name of the objective that this part's score counts towards.

suggestGoingBack string

In explore mode, suggest to the student to go back to the previous part after completing this one?

adaptiveMarkingPenalty number

Number of marks to deduct when adaptive marking is used.

useAlternativeFeedback boolean

Show all feedback from an alternative answer? If false, only the alternative feedback message is shown.

errorCarriedForwardReplacements Array.<Numbas.parts.adaptive_variable_replacement_definition>

Variable replacements to make during adaptive marking.

Inherited From:
Source:

shouldResubmit :boolean

True if this part should be resubmitted because another part it depended on has changed.

Type:
Inherited From:
Source:

signals :Numbas.schedule.SignalBox

Signals produced while loading this part.

Type:
Inherited From:
Source:

stagedAnswer :Array.<string>

Student's answers as visible on the screen (not necessarily yet submitted).

Type:
Inherited From:
Source:

steps :Array.<Numbas.parts.Part>

Child step parts.

Type:
Inherited From:
Source:

stepsMarks :number

Marks available for the steps, if any.

Type:
Inherited From:
Source:

stepsOpen :boolean

Is the steps display open?

Type:
Inherited From:
Source:

stepsShown :boolean

Have the steps been show for this part?

Type:
Inherited From:
Source:

type :string

This part's type, e.g. "jme", "numberentry", ...

Type:
Inherited From:
Source:

useCustomName :boolean

Should a custom name be used?

Type:
Inherited From:
Source:

warnings :Array.<string>

Warnings shown next to the student's answer.

Type:
Inherited From:
Source:

xml :Element

XML defining this part.

Type:
Inherited From:
Source:

Methods

addAlternative(alternative, index)

Add an alternative to this part.

Parameters:
Name Type Description
alternative Numbas.parts.Part
index number

Position of the alternative.

Fires:
  • Numbas.Part#event:addAlternative
Inherited From:
Source:

addCredit(credit, message)

Add an absolute value to credit.

Parameters:
Name Type Description
credit number

Amount to add.

message string

Message to show in feedback to explain this action.

Fires:
  • Numbas.Part#event:addCredit
Inherited From:
Source:

addStep(step, index)

Add a step to this part.

Parameters:
Name Type Description
step Numbas.parts.Part
index number

Position of the step.

Fires:
  • Numbas.Part#event:addStep
Inherited From:
Source:

addVariableReplacement(variable, part, must_go_first)

Add a variable replacement for this part's adaptive marking.

Parameters:
Name Type Description
variable string

The name of the variable to replace.

part string

The path of the part to use.

must_go_first boolean

Must the referred part be answered before this part can be marked?

Fires:
  • Numbas.Part#event:addVariableReplacement
Inherited From:
Source:

allChildren() → {Array.<Numbas.jme.parts.Part>}

All children of this part: all gaps and steps, but not alternatives.

Returns:
Type Description
Array.<Numbas.jme.parts.Part>
Inherited From:
Source:

applyScoreLimits()

Make sure the awarded score is between the minimum and maximum available.

Inherited From:
Source:

apply_feedback(feedback)

Apply a finalised list of feedback states to this part.

Parameters:
Name Type Description
feedback Array.<Numbas.marking.feedback_item>
Inherited From:
Source:
See:

assignName(index, siblings) → {boolean}

Assign a name to this part, and then assign names to its children.

Parameters:
Name Type Description
index number

The number of parts before this one that have names.

siblings number

The number of siblings this part has.

Fires:
  • Numbas.Part#event:assignName
Returns:
Type Description
boolean

true if this part has a name that should increment the label counter.

Inherited From:
Source:

availableMarks() → {number}

The total marks available for this part, after applying adaptive marking and steps penalties.

Returns:
Type Description
number
Inherited From:
Source:

availableNextParts() → {Array.<Numbas.parts.NextPart>}

Currently available next parts.

Returns:
Type Description
Array.<Numbas.parts.NextPart>
Inherited From:
Source:

(abstract) baseMarkingScript() → {Numbas.marking.MarkingScript}

The base marking script for this part.

Returns:
Type Description
Numbas.marking.MarkingScript
Overrides:
Source:

calculateScore()

Calculate the student's score based on their submitted answers.

Calls the parent part's calculateScore method at the end.

Fires:
  • Numbas.Part#event:calculateScore
Inherited From:
Source:

do_pre_submit_tasks(studentAnswer, scope, exec_path) → {object}

Do all of the pre-submit tasks before marking an answer. Results are cached by exec_path and studentAnswer.

Parameters:
Name Type Description
studentAnswer Numbas.jme.token
scope Numbas.jme.Scope
exec_path string
Fires:
  • Numbas.Part#event:do_pre_submit_tasks
Returns:
Type Description
object
Inherited From:
Source:

error(message, args, originalErroropt)

Throw an error, with the part's identifier prepended to the message.

Parameters:
Name Type Attributes Description
message string
args object

Arguments for the error message.

originalError Error <optional>

If this is a re-thrown error, the original error object.

Fires:
  • Numbas.Part#event:error
Throws:
Inherited From:
Source:

errorCarriedForwardScope() → {Numbas.jme.Scope}

Replace variables with student's answers to previous parts.

Returns:
Type Description
Numbas.jme.Scope
Inherited From:
Source:

finaliseLoad()

Perform any tidying up or processing that needs to happen once the part's definition has been loaded.

Overrides:
Source:

(abstract) getCorrectAnswer(scope)

Compute the correct answer, based on the given scope. Anything to do with marking that depends on the scope should be in this method, and calling it with a new scope should update all the settings used by the marking algorithm.

Parameters:
Name Type Description
scope Numbas.jme.Scope
Overrides:
Source:

getErrorCarriedForwardReplacements() → {Array.<Numbas.parts.adaptive_variable_replacement_definition>}

Return the list of variable replacements to make for adaptive marking. For alternatives, the parent part is used, otherwise this part is used.

Returns:
Type Description
Array.<Numbas.parts.adaptive_variable_replacement_definition>
Inherited From:
Source:

getScope() → {Numbas.jme.Scope}

Get a JME scope for this part. If this.question is set, use the question's scope. Otherwise, use Numbas.jme.builtinScope.

Returns:
Type Description
Numbas.jme.Scope
Inherited From:
Source:

giveWarning(warning)

Give the student a warning about this part.

Parameters:
Name Type Description
warning string
Fires:
  • Numbas.Part#event:giveWarning
Inherited From:
Source:
See:

hasStagedAnswer() → {boolean}

Has the student entered an answer to this part?

Returns:
Type Description
boolean
Inherited From:
Source:
See:

hideSteps()

Close the steps box. This doesn't affect the steps penalty.

Fires:
  • Numbas.Part#event:hideSteps
Inherited From:
Source:

initDisplay()

Initialise this part's display object. Only called if the question this part belongs to has a display.

Overrides:
Source:

input_options() → {object}

Options for this part's input widget.

Returns:
Type Description
object
Overrides:
Source:

input_widget() → {string}

The name of the input widget this part uses, if any.

Returns:
Type Description
string
Overrides:
Source:

loadFromJSON(data)

Load the part's settings from a JSON object.

Parameters:
Name Type Description
data object
Overrides:
Source:

loadFromXML(xml)

Load the part's settings from an XML <part> node.

Parameters:
Name Type Description
xml Element
Overrides:
Source:

lock()

Lock this part.

Fires:
  • Numbas.Part#event:lock
Inherited From:
Source:

makeNextPart(np, indexopt)

Make an instance of the selected next part.

Parameters:
Name Type Attributes Description
np Numbas.parts.NextPart
index number <optional>

The position of the part in the question's parts list (added to the end if not given).

Fires:
  • Numbas.Part#event:makeNextPart
Inherited From:
Source:

makeScope(parentScopeopt) → {Numbas.jme.Scope}

Make the scope for this part.

Parameters:
Name Type Attributes Description
parentScope Numbas.jme.Scope <optional>

An optional parent scope. If not given, the following are tried: a parent part, the question this part belongs to, Numbas.jme.builtinScope.

Fires:
  • Numbas.Part#event:makeScope
Returns:
Type Description
Numbas.jme.Scope
Inherited From:
Source:

mark(scope, exec_path) → {Numbas.parts.mark_result}

Function which marks the student's answer: run this.settings.markingScript, which sets the credit for the student's answer to a number between 0 and 1 and produces a list of feedback messages and warnings. If the question has been answered in a way that can be marked, this.answered should be set to true.

Parameters:
Name Type Description
scope Numbas.jme.Scope
exec_path string

A description of the path of execution, for caching pre-submit tasks.

Fires:
  • Numbas.Part#event:pre-mark
  • Numbas.Part#event:post-mark
Returns:
Type Description
Numbas.parts.mark_result
Inherited From:
Source:
See:

markAdaptive() → {Numbas.parts.marking_results}

Mark this part, using adaptive marking when appropriate.

Fires:
  • Numbas.Part#event:pre-markAdaptive
  • Numbas.Part#event:post-markAdaptive
Returns:
Type Description
Numbas.parts.marking_results
Inherited From:
Source:

markAgainstScope(scope, feedback, exec_path) → {Numbas.parts.marking_results}

Mark the student's answer against the given scope.

Parameters:
Name Type Description
scope Numbas.jme.Scope

Scope in which to calculate the correct answer.

feedback Object.<Array.<string>>

Dictionary of existing warnings and markingFeedback lists, to add to - copies of these are returned with any additional feedback appended.

exec_path string

A description of the path of execution, for caching pre-submit tasks.

Fires:
  • Numbas.Part#event:markAgainstScope
Returns:
Type Description
Numbas.parts.marking_results
Inherited From:
Source:

markAlternatives(scope, feedback, exec_path) → {Numbas.parts.markAlternatives_result}

Mark the student's answer against this part and its alternatives, and return the feedback corresponding to the alternative awarding the most credit.

Parameters:
Name Type Description
scope Numbas.jme.Scope

Scope in which to calculate the correct answer.

feedback Object.<Array.<string>>

Dictionary of existing warnings and markingFeedback lists, to add to - copies of these are returned with any additional feedback appended.

exec_path string

A description of the path of execution, for caching pre-submit tasks.

Returns:
Type Description
Numbas.parts.markAlternatives_result
Inherited From:
Source:

mark_answer(studentAnswer, scope, exec_path) → {Numbas.marking.marking_script_result}

Run the marking script against the given answer. This does NOT apply the feedback and credit to the part object, it just returns it.

Parameters:
Name Type Description
studentAnswer Numbas.jme.token
scope Numbas.jme.Scope
exec_path string

A description of the path of execution, for caching pre-submit tasks.

Fires:
  • Numbas.Part#event:pre-mark_answer
  • Numbas.Part#event:post-mark_answer
Returns:
Type Description
Numbas.marking.marking_script_result
Inherited From:
Source:
See:

markingComment(message, reason, format)

Add a comment to the marking feedback.

Parameters:
Name Type Description
message string
reason string
format string

The format of the message: "html" or "string".

Fires:
  • Numbas.Part#event:markingComment
Inherited From:
Source:

marking_parameters(studentAnswer, pre_submit_parameters, exec_path) → {Object.<Numbas.jme.token>}

Get JME parameters to pass to the marking script.

Parameters:
Name Type Description
studentAnswer Numbas.jme.token

The student's answer to the part.

pre_submit_parameters Array.<Object.<Numbas.jme.token>>
exec_path string
Returns:
Type Description
Object.<Numbas.jme.token>
Overrides:
Source:

multCredit(factor, message)

Multiply credit by the given amount - use to apply penalties.

Parameters:
Name Type Description
factor number
message string

Message to show in feedback to explain this action.

Fires:
  • Numbas.Part#event:multCredit
Inherited From:
Source:

openSteps()

Open the steps, either because the student asked or the answers to the question are being revealed. This doesn't affect the steps penalty.

Fires:
  • Numbas.Part#event:openSteps
Inherited From:
Source:

pleaseResubmit()

Called by another part when its marking means that the marking for this part might change (i.e., when this part replaces a variable with the answer from the other part). Sets this part as dirty, and gives a warning explaining why the student must resubmit.

Inherited From:
Source:

(abstract) rawStudentAnswerAsJME() → {Numbas.jme.token}

Get the student's answer as it was entered as a JME data type, to be used in the marking script.

Returns:
Type Description
Numbas.jme.token
Overrides:
Source:

removeNextPart(np)

Remove the existing instance of the given next part.

Parameters:
Name Type Description
np Numbas.parts.NextPart
Fires:
  • Numbas.Part#event:removeNextPart
Inherited From:
Source:

removeWarnings()

Remove all warnings.

Inherited From:
Source:
See:

restore_feedback(feedback)

Restore a set of feedback messages.

Parameters:
Name Type Description
feedback Object.<Array.<string>>

Dictionary of existing warnings and markingFeedback lists, to add to - copies of these are returned with any additional feedback appended.

Inherited From:
Source:

resume()

Load saved data about this part from storage. The part is not resubmitted - you must do this afterwards, once any steps or gaps have been resumed.

Fires:
  • Numbas.Part#event:resume
Overrides:
Source:

revealAnswer(dontStore)

Reveal the correct answer to this part.

Parameters:
Name Type Description
dontStore boolean

Don't tell the storage that this is happening - use when loading from storage to avoid callback loops.

Fires:
  • Numbas.Part#event:revealAnswer
Inherited From:
Source:

setCredit(credit, message, reason)

Set the credit to an absolute value.

Parameters:
Name Type Description
credit number
message string

Message to show in feedback to explain this action.

reason string

Why was the credit set to this value? If given, either 'correct' or 'incorrect'.

Fires:
  • Numbas.Part#event:setCredit
Inherited From:
Source:

setDirty(dirty)

Call when the student changes their answer, or submits - update Numbas.parts.Part.isDirty.

Parameters:
Name Type Description
dirty boolean
Fires:
  • Numbas.Part#event:setDirty
Inherited From:
Source:

setMarkingScript(markingScriptString, extend_base)

Set this part's JME marking script.

Parameters:
Name Type Description
markingScriptString string
extend_base boolean

Does this script extend the built-in script?

Inherited From:
Source:

setScript(name, order, script)

Set a custom JavaScript script.

Parameters:
Name Type Description
name string

The name of the method to override.

order string

When should the script run? 'instead', 'before' or 'after'.

script string

The source code of the script.

Inherited From:
Source:
See:

(abstract) setStudentAnswer()

Save an answer entered by the student, for use in marking.

Overrides:
Source:

setWarnings(warnings)

Set the list of warnings.

Parameters:
Name Type Description
warnings Array.<string>
Inherited From:
Source:
See:

showSteps(dontStore)

Show the steps, as a result of the student asking to show them. If the answers have not been revealed, we should apply the steps penalty.

Parameters:
Name Type Description
dontStore boolean

Don't tell the storage that this is happening - use when loading from storage to avoid callback loops.

Fires:
  • Numbas.Part#event:showSteps
Inherited From:
Source:

storeAnswer(answer, dontStore)

Update the stored answer from the student (called when the student changes their answer, but before submitting).

Parameters:
Name Type Description
answer *
dontStore boolean

Don't tell the storage that this is happening - use when loading from storage to avoid callback loops.

Fires:
  • Numbas.Part#event:storeAnswer
Inherited From:
Source:
See:
  • {Numbas.parts.Part.stagedAnswer}

studentAnswerAsJME() → {Numbas.jme.token}

Get the student's answer as a JME data type, to be used in error-carried-forward calculations.

Returns:
Type Description
Numbas.jme.token
Inherited From:
Source:

subCredit(credit, message)

Subtract an absolute value from credit.

Parameters:
Name Type Description
credit number

Amount to subtract.

message string

Message to show in feedback to explain this action.

Fires:
  • Numbas.Part#event:subCredit
Inherited From:
Source:

submit()

Submit the student's answers to this part - remove warnings. save answer, calculate marks, update scores.

Fires:
  • Numbas.Part#event:pre-submit
  • Numbas.Part#event:post-submit
Inherited From:
Source:

submit_no_staged_answer()

Called when this part is submitted but it has no staged answer.

Overrides:
Source:

wait_for_pre_submit(promise)

Wait for a promise to resolve before submitting.

Parameters:
Name Type Description
promise Promise
Fires:
  • Numbas.Part#event:waiting_for_pre_submit
  • Numbas.Part#event:completed_pre_submit
Inherited From:
Source: