moodlesg.math package¶
Subpackages¶
Submodules¶
moodlesg.math.base module¶
Module base contains definitions required for building
moodle mathematical expressions.
-
class
moodlesg.math.base.Expression(expression)[source]¶ Implement a generic mathematical expression in moodle format.
Parameters: expression (str) – Math moodle expression. Returns: Moodle math object. Return type: ExpressionExamples
>>> str(mm.Expression('a')) 'a'
>>> a = mm.Expression('a') >>> b = mm.Expression('b')
>>> str(a + b) '(a + b)' >>> str(a + 1) '(a + 1)'
-
class
moodlesg.math.base.Settings[source]¶ Representation of moodle math parameters.
If you need change parameters, access to them throught
mmParams.-
decimal_sep= '.'¶
-
list_sep= ';'¶
-
math_type= 'grade'¶
-
-
moodlesg.math.base.answer_var(answer_variable)[source]¶ Implement a moodle variable for using in correct answer calculation.
Parameters: answer_variable (str) – Variable name string. Returns: Moodle variable ready for calculations. Return type: ExpressionExamples
We can create a moodle answer variable for calculation as follow:
>>> a = mm.answer_var('a') >>> str(a) '{a}'
See also
-
moodlesg.math.base.grade_var(id_activity)[source]¶ Implement a moodle variable for using in grade calculation.
Parameters: id_activity (str) – Moodle ID of the activity. Returns: Moodle ID ready for grade calculation. Return type: ExpressionExamples
We can create a moodle id activity for calculation as follow:
>>> a = mm.grade_var('a') >>> str(a) '[[a]]' >>> str(a + 1) '([[a]] + 1)'
See also
-
moodlesg.math.base.mmParams= <moodlesg.math.base.Settings instance>¶ Object that represents moodle math parameters and manages them.
Type: ( Settings)
-
moodlesg.math.base.moodle_var(name_variable)[source]¶ Create variable type according to
mmParams.math_type.Parameters: name_variable (str) – Identifier of the moodle variable. Returns: Moodle variable of correct type. Return type: ExpressionExamples
>>> mm.mmParams.grade() >>> mm.moodle_var('a') Expression('[[a]]')
>>> mm.mmParams.answer() >>> mm.moodle_var('a') Expression('{a}')
- See_Also:
Expressiongrade_var()answer_var()
moodlesg.math.constants module¶
Module constants define common math moodle constants between grade and
answer calculations.
In Moodle, actually there is no predefined constant that is allowed other than pi() as a function without parameter. With this module, is posible use \(\pi\) as a constant (not call to a function) and define others constants.
-
moodlesg.math.constants.PI= Expression('pi()')¶ Define \(\pi\).
moodlesg.math.settings module¶
Module contents¶
Module moodlesg.math implements a python interface to math manipulation
requiered in grade and answer moodle formulas.
You can use variable assigment, relation operators, mixing types (moodle expressions with python data types) and commons names of functions in both type of formulas, grade and answers.
References
| [grade] | Grade calculations. Moodle 3.4 Docs. |
| [answer] | Calculated question type Moodle 3.4 Docs. |