.. _BackendSpecs:

Back-end web services and user interface
========================================

The OpenDSA "backend" API provides access to resources stored
in the database. OpenDSA implements RESTful (REpresentional State Transfer)
service server-side. Information is transferred to/from the back end using JSON.

Users Resources
---------------
Create new user
^^^^^^^^^^^^^^^
``HTTP method:``  POST

``POST parameters:``

        +-------------------------+----------------------------+
        |   Parameters            |   Description              |
        +=========================+============================+
        |   username              |   username of user         |
        +-------------------------+----------------------------+
        |   password              | new user password          |
        +-------------------------+----------------------------+
        |   email                 | new user email address     |
        +-------------------------+----------------------------+

``Server Response:`` HTTP status[bad request], [error message].

Login user
^^^^^^^^^^
``HTTP method:``  POST

``POST parameters:``

        +-------------------------+----------------------------+
        |   Parameters            |   Description              |
        +=========================+============================+
        |   username              |   username of user         |
        +-------------------------+----------------------------+
        |   password              | new user password          |
        +-------------------------+----------------------------+

``Server Response:`` HTTP status[bad request|unauthorized|forbidden], [session key]

Logout user
^^^^^^^^^^^
``HTTP method:``  POST

``POST parameters:``

        +-------------------------+----------------------------+
        |   Parameters            |   Description              |
        +=========================+============================+
        |   key                   | session key (generated by  |
        |                         |  the server)               |
        +-------------------------+----------------------------+

``Server Response:`` HTTP status[bad request|unauthorized]


Books Resources
---------------

Add new book
^^^^^^^^^^^^
``HTTP method:``  POST

``POST parameters:``

        +-------------------------+----------------------------+
        |   Parameters            |   Description              |
        +=========================+============================+
        |   book_name             |   Name of the book         |
        +-------------------------+----------------------------+
        |   book_url              |   BOOK'S URL               |
        +-------------------------+----------------------------+

``Server Response:`` HTTP status[bad request|unauthorized]

Modules Resources
-----------------
Add new Module
^^^^^^^^^^^^^^
``HTTP method:``  POST

``POST parameters:``

        +-------------------------+----------------------------+
        |   Parameters            |   Description              |
        +=========================+============================+
        |   name                  |   Name of the module       |
        +-------------------------+----------------------------+
        |   exercises             |   names of the exercises   |
        |                         |   in the module            |
        +-------------------------+----------------------------+

``Server Response:`` HTTP status[bad request|unauthorized]

Exercises Resources
-------------------
``HTTP method:``  POST

``POST parameters:``

        +-------------------------+----------------------------+
        |   Parameters            |   Description              |
        +=========================+============================+
        |   name                  |   Name of the exercise     |
        +-------------------------+----------------------------+
        |   description	          | Description of the exercise|
        +-------------------------+----------------------------+
        |   author                | Exercise author            |
        +-------------------------+----------------------------+
        |   covers                |  Topic covered by the      |
        |                         |      exercise              |
        +-------------------------+----------------------------+
        |   ex_type               | Type of exercise: Khan     |
        |                         | academy, JSAV proficiency, |
        |                         | or JSAV slide shows        |
        +-------------------------+----------------------------+
        |   streak (KA exercises) | streak of correct exercise |
        |                         | for proficiency            |
        +-------------------------+----------------------------+

``Server Response:`` HTTP status[bad request|unauthorized]



UserModule Resources
^^^^^^^^^^^^^^^^^^^^
``Endpoint:`` ismoduleproficient

``HTTP method:``  POST

``POST parameters:``

        +-------------------------+----------------------------+
        |   Parameters            |   Description              |
        +=========================+============================+
        |   key                   | session key                |
        +-------------------------+----------------------------+
        |   module                | module name                |
        +-------------------------+----------------------------+

``HTTP Response:`` HTTP status[bad request|unauthorized], user module proficiency status

UserExercises Resources
-----------------------

userexercise logs (KA exercises)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``HTTP method:`` POST

``POST Parameters:``

        +-------------------------+----------------------------+
        |   Parameters            |   Description              |
        +=========================+============================+
        |   key                   |  session key               |
        +-------------------------+----------------------------+
        |   exercise              |  exercise name             |
        +-------------------------+----------------------------+
        |   module                | module name                |
        +-------------------------+----------------------------+
        |   attempt_number        |  Counter for how many time |
        |                         |  the exercise has been     |
        |                         |  attempted                 |
        +-------------------------+----------------------------+
        |  attempt_content        |  Student answer            |
        +-------------------------+----------------------------+
        |  complete               |  1 if the answer is correct|
        |                         |  0 otherwise               |
        +-------------------------+----------------------------+
        |  count_hints            | Counter for how many time  |
        |                         | hints were use             |
        +-------------------------+----------------------------+
        |  time_taken             | Time taken to complete     |
        |                         |  the exercise              |
        +-------------------------+----------------------------+
        |   remote_adrr           | IP address                 |
        +-------------------------+----------------------------+


``Action triggered:`` Update proficiency field accordingly.

``HTTP Response:`` HTTP status[bad request|unauthorized], proficiency status.


userexercise logs (JSAV exercises)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``HTTP method:`` POST

``POST Parameters:``

        +-------------------------+----------------------------+
        |   Parameters            |   Description              |
        +=========================+============================+
        |   key                   |  session key               |
        +-------------------------+----------------------------+
        |   exercise              |  exercise name             |
        +-------------------------+----------------------------+
        |   uiid                  |  exercise unique id        |
        +-------------------------+----------------------------+
        |   module                | module name                |
        +-------------------------+----------------------------+
        |   tstamp                | time the exercise was done |
        +-------------------------+----------------------------+
        |  score                  |  number of correct steps   |
        +-------------------------+----------------------------+
        |  total_time             | Time taken to complete     |
        |                         |  the exercise              |
        +-------------------------+----------------------------+
        |   remote_adrr           | IP address                 |
        +-------------------------+----------------------------+


``Action triggered:`` Update proficiency field accordingly.

``HTTP Response:`` HTTP status[bad request|unauthorized], proficiency status.


Userinterface Resources
-----------------------

userinterface logs
^^^^^^^^^^^^^^^^^^
``HTTP method:`` POST

``POST Parameters:``

        +-------------------------+----------------------------+
        |   Parameters            |   Description              |
        +=========================+============================+
        |   key                   |  session key               |
        +-------------------------+----------------------------+
        |   exercise              |  exercise name             |
        +-------------------------+----------------------------+
        |   module                | module name                |
        +-------------------------+----------------------------+
        |   book                  | book name                  |
        +-------------------------+----------------------------+
        |   type                  |  type of interaction       |
        +-------------------------+----------------------------+
        |  uiid                   |  exercise unique id        |
        +-------------------------+----------------------------+
        |  desc                   |  description of the        |
        |                         |  interaction               |
        +-------------------------+----------------------------+
        |   tstamp                | time the exercise was done |
        +-------------------------+----------------------------+
        |   remote_adrr           | IP address                 |
        +-------------------------+----------------------------+


``HTTP Response:`` HTTP status[bad request|unauthorized], starage status.


Scheduled Tasks
---------------

Daily summary logs
^^^^^^^^^^^^^^^^^^
We use ``celery`` (http://celeryproject.org/) to run scripts that create daily activity log files.
The scripts run at the same time everyday. The scripts query the database and update the logs files
that are used by the visualization webpage. 

