Coder Social home page Coder Social logo

moodleteacher's Introduction

The moodleteacher library

This Python library is intended for teachers with courses in the Moodle learning management system. They can easily automate their grading or course management procedures, so that clicking around on the web page is no longer neccessary.

Getting Started

These instructions will get you the library up and running on your local machine.

Installation

The library demands Python 3. Install the software with

pip3 install moodleteacher

Start an interactive Python session and load the library:

(venv) shaw:moodleteacher ptroeger$ python
Python 3.6.5 (default, Apr 25 2018, 14:23:58) 
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import moodleteacher as mt

First, you need to provide the neccessary connection information. The host name is the web server where your Moodle installation lives. The token can be retrieved from your Moodle user settings (Preferences -> User account -> Security keys -> Service "Moodle mobile web service"):

>>> conn=mt.MoodleConnection(moodle_host="https://lms.beuth-hochschule.de", token="aaaaabbbbbcccccdddddeeeee12345")

You can now fetch the list of assignments that are accesssible for you:

>>> assignments=mt.MoodleAssignments(conn)
>>> for assign in assignments:
...     print(assign)
... 

You can filter for particular assignments or courses, based on the Moodle IDs for them:

>>> assignments=mt.MoodleAssignments(conn, course_filter=[4711], assignment_filter=[1234])
>>> for assign in assignments:
...     print(assign)
... 

Assignment objects provide a list of submissions. Each submission object provides the files (or text) submitted by the student:

>>> for assignment in assignments:
...     for submission in assignment.submissions():
...         print("User {0} submitted {1} files.".format(submission.userid, len(submission.files)))

Student file uploads can be downloaded with the MoodleSubmissionFile class and previewed with a small integrated GUI application. The preview supports:

  • HTML text
  • PDF files
  • Images
  • Any other content, just shown in text form
  • ZIP files of any of the above
>>> for assignment in assignments:
...     for submission in assignment.submissions():
...             for file_url in submission.files:
...                     print(file_url)
... 
https://lms.beuth-hochschule.de/webservice/pluginfile.php/725647/assignsubmission_file/submission_files/32245/task03_ft.pdf
https://lms.beuth-hochschule.de/webservice/pluginfile.php/725647/assignsubmission_file/submission_files/75356/Fehlerbaum.jpg
https://lms.beuth-hochschule.de/webservice/pluginfile.php/725647/assignsubmission_file/submission_files/23454/Faultchar%2B-fertig.png
>>> stud_upload=mt.MoodleSubmissionFile(conn=conn, url="https://lms.beuth-hochschule.de/webservice/pluginfile.php/725647/assignsubmission_file/submission_files/75356/Fehlerbaum.jpg")
>>> stud_upload.is_pdf
False
>>> stud_upload.is_image
True
>>> from moodleteacher import preview
>>> mt.preview.show_preview("Preview Window", [stud_upload])

Submissions can be trivially graded:

>>> for assignment in assignments:
...     for submission in assignment.submissions:
...         submission.save_grade(0.0, "Everybody fails in this assignment. You too.")

There is also support for:

  • Running submitted files locally as shell script, for testing purposes.
  • Running submitted files remotely on another machine, for testing purposes.

Take a look at the complex usage example in the grader.py script, which shows nearly all features of the library in action.

Real documentation is planned.

License

This project is licensed under the GPL3 License - see the LICENSE file for details.

moodleteacher's People

Contributors

loewis avatar troeger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

moodleteacher's Issues

Group grading is broken

Grading groups leads to the problem that after grading the first member, the second group member still shows up as to be graded.

This is mainly a caching problem, since alle gradings to be done are fetched as one at the beginning. The library should internally determine the groups and their members, and should consider already graded groups explicitely during the iteration process.

Keep manual feedback on re-validation

A re-validation overwrites the feedback box for the submission completely, so manual additions for the first validation run are gone.

The feedback saving should use some 'magic' markers in the text, put the validation result inside them and replace only this part of the text.

Compiler output needs to be HTML escaped

[this might be a moodleteacher issue]

Currently, the moodle comments contain text like

ostern.c:1:10: fatal error: Windows.h: No such file or directory
 #include 
          ^~~~~~~~~
compilation terminated.

The problem is that the source fragment '<windows.h>' is copied literally into the HTML comment, which is then rendered by the browser with ignorance.

Set maximum number of connection attempts

In automated processes (cron), if the Moodle server is down, the connection attempt is made infinitely, which may not be convenient.

Perhaps allowing a configuration of maximum connection attempts would allow in such cases a controlled exit by, for example, an exception.

Maybe, something like this:

class BaseRequest():

  def __init__(self, conn, url, attempts = 0):
    self.conn = conn
    self.url = url
    self.attempts = attempts

 def get_absolute(self, params=None):
    [...]

    _logger.debug("Performing web service GET call ...")
    nattempt = 0
    while (nattempt < self.attempts or self.attempts == 0):
      nattempt += 1
      try:
        result = requests.get(self.url, params=params, timeout=self.conn.timeout)
      except requests.exceptions.Timeout:
        _logger.error("Timeout for GET request to {0} after {1} seconds, trying again.".format(self.url, self.conn.timeout))
        continue
      break

    if nattempt == self.attempts:
      raise Exception('Max. number of connection ({0}) attempts reached'.format(self.attempts))

     [...] 

    return result

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.