Welcome to Moodle String Generator’s documentation!¶
Moodle String Generator¶
Python package to generate common strings used in moodle for users (not admin level) and manage exported files from moodle and generate files for import.
- Free software: MIT license
- Documentation: https://moodlesg.readthedocs.io.
Description¶
MoodleSG (Moodle String Generator) is a python package with the purpose of help to generate common strings using for users (not admin level) when manage a course in moodle, e.g. answer formulas, grade formulas and question generation in markdown or XML.
This package is not intended to use as admin level and is developed because management of some formulas are very uncomfortable because not variable is available as user level (some universities has very strange methods for grade calculation and vary each semester or some math problems has many substitutions). So, you finish with a longer formula with pattern repetitions that you add manually and many brackets and then your math expression for grade or answer formula is very susceptible to fail.
Also, you can think in some automatic question generation that Moodle not support but you can create and export as a question database of questions (not calculated questions that support numeric or text variables only -not both in the same question-) or import from a question database backup and modify that.
Features¶
n: null support
b: basic support
p: partial support
f: full support
- [p] String generation of moodle math formulas.
- [f] Grade calculations.
- [p] Calculated question.
- [n] String generation of questions for text plain moodle editor (not XML nor HTML).
- [n] String manipulation of question bank.
- [n] Export of question strings to moodle supported question import formats.
- [n] Import of question strings from moodle question export formats.
- [n] Management question bank locally and generate from collections of question strings.
Credits¶
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Installation¶
Stable release¶
To install Moodle String Generator, run this command in your terminal:
$ pip install moodlesg
This is the preferred method to install Moodle String Generator, as it will always install the most recent stable release.
If you don’t have pip installed, this Python installation guide can guide you through the process.
From sources¶
The sources for Moodle String Generator can be downloaded from the Github repo.
You can either clone the public repository:
$ git clone git://github.com/cosmoscalibur/moodlesg
Or download the tarball:
$ curl -OL https://github.com/cosmoscalibur/moodlesg/tarball/master
Once you have a copy of the source, you can install it with:
$ python setup.py install
Usage¶
To use Moodle String Generator in a project:
import moodlesg
At this moment only works the math
module.
Math module¶
To use Moodle String Generator math utility
import moodlesg.math as mm
You can find in mm
all [intended] public members as a common
and easy interface to grade and answer calculation, with names that
remember python math core.
Not all is finished but is usable (grade calculation is full supported).
moodlesg¶
moodlesg package¶
Subpackages¶
moodlesg.math package¶
Subpackages¶
This module implement moodle math functions that are common between grade and answer calculation.
-
moodlesg.math.functions.common.
acos
(expr)[source]¶ Arc cosine – output in radians.
It is the same that
arccos
moodle math function.
-
moodlesg.math.functions.common.
acosh
(expr)[source]¶ Inverse hyperbolic cosine – output in radians.
It is the same that
arccosh
moodle math function.
-
moodlesg.math.functions.common.
asin
(expr)[source]¶ Arc sine – output in radians.
It is the same that
arcsin
moodle math function.
-
moodlesg.math.functions.common.
asinh
(expr)[source]¶ Inverse hyperbolic sine.– output in radians.
It is the same that
arcsinh
moodle math function.
-
moodlesg.math.functions.common.
atan
(expr)[source]¶ Arc tangent – output in radians.
It is the same that
arctan
moodle math function.
-
moodlesg.math.functions.common.
atanh
(expr)[source]¶ Inverse hyperbolic tangent– output in radians.
It is the same that
arctanh
moodle math function.
-
moodlesg.math.functions.common.
average
(expr1, *expr2)[source]¶ Returns the average of the values in a list of arguments.
-
moodlesg.math.functions.common.
ceil
(expr)[source]¶ Maps a real number to the smallest following integer.
-
moodlesg.math.functions.common.
cos
(expr)[source]¶ Cosine – in radians!!! Convert your degree measurement to radians before you take the cos of it.
-
moodlesg.math.functions.common.
cosh
(expr)[source]¶ Hyperbolic cosine – in radians!!! Convert your degree measurement to radians before you take the cosh of it.
-
moodlesg.math.functions.common.
floor
(expr)[source]¶ Maps a real number to the largest previous integer.
-
moodlesg.math.functions.common.
max
(expr1, *expr2)[source]¶ Returns the maximum value in a list of arguments.
-
moodlesg.math.functions.common.
min
(expr1, *expr2)[source]¶ Returns the minimum value in a list of arguments.
-
moodlesg.math.functions.common.
sin
(expr)[source]¶ Sine – in radians!!! Convert your degree measurement to radians before you take the sin of it.
-
moodlesg.math.functions.common.
sinh
(expr)[source]¶ Hyperbolic sine – in radians!!! Convert your degree measurement to radians before you take the sinh of it.
This module create a common interface to call math functions of grade and answer calculation. Some functions in moodle version has different names and other cases has no equivalent (grade calculation support less functions).
Examples
In Moodle you can evaluate a natural logarithm in both, grade and answer
calculation, but the function has different name. If you need to evaluate
in grade calculation ln
is the function but in answer calculation
is log
. With MoodleSG both cases are covered with log()
(common convention in programming languages).
>>> mm.mmParams.grade()
>>> a = mm.moodle_var('a')
>>> mm.log(a)
Expression('ln([[a]])')
>>> mm.mmParams.answer()
>>> b = mm.moodle_var('b')
>>> mm.log(b)
Expression('log({b})')
-
moodlesg.math.functions.compatibility.
log10
(expr)[source]¶ Return base-10 logarithm of a expression.
Module functions
contains submodules of functions
that grouping supported functions for moodle (native and extended).
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: Expression
Examples
>>> 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: Expression
Examples
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: Expression
Examples
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>¶ (
Settings
) – Object that represents moodle math parameters and manages them.
-
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: Expression
Examples
>>> mm.mmParams.grade() >>> mm.moodle_var('a') Expression('[[a]]')
>>> mm.mmParams.answer() >>> mm.moodle_var('a') Expression('{a}')
- See_Also:
Expression
grade_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. |
Module contents¶
Top-level package for Moodle String Generator.
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/cosmoscalibur/moodlesg/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.
Write Documentation¶
Moodle String Generator could always use more documentation, whether as part of the official Moodle String Generator docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/cosmoscalibur/moodlesg/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up moodlesg for local development.
Fork the moodlesg repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/moodlesg.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv moodlesg $ cd moodlesg/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 moodlesg tests $ python setup.py test or py.test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 2.7, 3.4, 3.5 and 3.6, and for PyPy. Check https://travis-ci.org/cosmoscalibur/moodlesg/pull_requests and make sure that the tests pass for all supported Python versions.
Deploying¶
A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.rst). Then run:
$ bumpversion patch # possible: major / minor / patch
$ git push
$ git push --tags
Travis will then deploy to PyPI if tests pass.
Credits¶
Development Lead¶
- Edward Villegas-Pulgarin <cosmoscalibur@gmail.com>
Contributors¶
None yet. Why not be the first?
History¶
0.3.1 (2018-05-17)¶
- Define changes according to mmParams.
- Remove sdist distribution from travis deployment.
- Update classifiers.
- Support moodle math setting: decimal and list separator, math type.
0.3.0 (2018-05-13)¶
- Fix installation wheels: Removed wheels for python2.7.
- Caps convention for constant: pi → PI.
- Better documentation.
- Full support of common functions between grade and answer calculations.
0.2.2 (2018-05-11)¶
- Fix docstrings.
- Added new math functions and docstrings (common and extended module).
0.2.0 (2018-05-06)¶
- Full implementation of moodle math expressions.
- Added pi constant.
- Some math functions common between grade and answer calculation.
0.1.2 (2018-03-14)¶
- Use super method for init of derived classes.
- Removed support of python 3.3.
- Added basic definition of moodle mathematical variable classes (since 0.1.1).
0.1.0 (2018-03-08)¶
- First release on PyPI.