summaryrefslogtreecommitdiff
path: root/README.md
blob: c4eb503f35dca9ee351746d1e114470322b10610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
Yaksh
========
[![Build Status](https://travis-ci.org/FOSSEE/online_test.svg?branch=master)](https://travis-ci.org/FOSSEE/online_test)

#### Introduction

This project provides an "exam" app that lets users take an online
programming quiz. 

#### Features

 * Define fairly complicated programming problems and have users
 solve the problem. 
 * Immediate verification of code solution. 
 * Supports pretty much arbitrary coding questions in Python, C, C++ and 
 simple Bash and uses "test cases" to test the implementations of the students.
 * Supports simple multiple choice questions and File uploads.
 * Since it runs on your Python, you could technically test any Python based library.
 * Scales to over 500+ simultaneous users.
 * Distributed under the BSD license.

Quick Start
===========

#### Pre-Requisite

1. Ensure [pip](https://pip.pypa.io/en/latest/installing.html) is installed

#### Installation

1. Install the yaksh
    
        pip install yaksh

1. In the terminal run
        
            yaksh create_demo [-p PATH] project_name
    - ```project_name``` is the desired name of the django project
    - PATH is an optional argument to specify where the django project will be installed
    - If PATH is not provided, the project is created in the current directory

1. The script does the following;
	1. Creates a new django project called `projectname`
	1. Creates a new demo database
	1. Creates two users, test moderator and test examinee
	1. Loads demo questions
	1. Loads demo quiz

1. Run:

        yaksh run_demo

1. In a new terminal run:

        sudo yaksh run_code_server

1. Open your browser and open the URL ```http://localhost:8000/exam```

1. Login as a teacher to edit the quiz or as a student to take the quiz
	Credentials:
	- Student - Username: student | Password: student
	- Teacher - Username: teacher | Password: teacher

Production Deployment
======================

#### Pre-Requisite

 1. Install dependencies using
     pip install -r requirements.txt
 1. Install MySql Server
 1. Install Python MySql support
 1. Install Apache Server for deployment
 
#### Configure MySql server

 1. Create a database named ``yaksh`` by following the steps below
    
        $> mysql -u root -p    
        mysql> create database yaksh
 
 1. Add a user named ```yaksh_user``` and give access to it on the database ```yaksh``` by following the steps below
 
    1. mysql> grant usage on yaksh.* to yaksh_user@localhost identified by 'mysecretpassword';
    
    1. mysql> grant all privileges on yaksh.* to yaksh_user@localhost;
 
 1. Create a file named `local.py` in folder `testapp` and insert `DATABASE_PASSWORD = 'mysecretpassword'` and `DATABASE_USER = 'yaksh_user'`

To deploy this app follow the steps below:

 1. Clone this repository and cd to the cloned repo.
        git clone  https://github.com/FOSSEE/online_test.git

 1. Run:
        python manage.py syncdb
    
 1.  Add questions by editing the "docs/sample_questions.py" or any other file in the same format and then run the following:

        python manage.py load_exam docs/sample_questions.py

	 Note that you can supply multiple Python files as arguments and all of
	 those will be added to the database.
    
 1. First run the python server provided. This ensures that the code is executed in a safe environment.  Do this like so:
    
        $ sudo python testapp/yaksh/code_server.py
      
    Put this in the background once it has started since this will not
    return back the prompt.  It is important that the server be running
    *before* students start attempting the exam.  Using sudo is
    necessary since the server is run as the user "nobody".  This runs
    on the ports configured in the settings.py file in the variable
    "SERVER_PORTS".  The "SERVER_TIMEOUT" also can be changed there.
    This is the maximum time allowed to execute the submitted code.
    Note that this will likely spawn multiple processes as "nobody"
    depending on the number of server ports specified.
    
 1. The ```wsgi.py``` script should make it 
 	easy to deploy this using mod_wsgi.  You will need to add a line of the form:

        WSGIScriptAlias / "/online_test/wsgi.py"

	to your apache.conf.  For more details see the Django docs here:

	https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
	
 1. Go to http://desired_host_or_ip:desired_port/admin

 1. Login with your credentials and look at the questions and modify if
    needed.  Create a new Quiz, set the date and duration or
    activate/deactivate the quiz.

 1. Now ask users to login at:

        http://host:port/exam

    And you should be all set.
    
 1. Note that the directory "output" will contain directories, one for each
    user.  Users can potentially write output into these that can be used
    for checking later.

 1. As Moderator user you can visit http://host/exam/monitor  to view
     results and user data interactively. You could also "grade" the
     papers manually if needed.

 1. You may dump the results and user data using the results2csv and
     dump_user_data commands.
     
 1. The file docs/sample_questions.py is a template that you can use for your own questions.
     
 1. Sometimes you might be in the situation where you are not hosted as
    "host.org/exam/"  but as "host.org/foo/exam/" for whatever reason.  In
    this case edit "settings.py" and set the "URL_ROOT"  to the root you
    have to serve at.  In the above example for "host.org/foo/exam" set
    URL_ROOT='/foo'.
 
Development Settings
====================

To install this app follow the steps below:

 1. Clone this repository and cd to the cloned repo.
  		```git clone  https://github.com/FOSSEE/online_test.git```
 
 1. Run:
 
        python manage.py syncdb
    
 1.  Add questions by editing the "docs/sample_questions.py" or any other file in the same format and then run the following:

      python manage.py load_exam docs/sample_questions.py

     Note that you can supply multiple Python files as arguments and all of
     those will be added to the database.
    
 1. First run the python server provided. This ensures that the code is executed in a safe environment.  Do this like so:
    
      $ sudo python testapp/yaksh/code_server.py
      
    Put this in the background once it has started since this will not
    return back the prompt.  It is important that the server be running
    *before* students start attempting the exam.  Using sudo is
    necessary since the server is run as the user "nobody".  This runs
    on the ports configured in the settings.py file in the variable
    "SERVER_PORTS".  The "SERVER_TIMEOUT" also can be changed there.
    This is the maximum time allowed to execute the submitted code.
    Note that this will likely spawn multiple processes as "nobody"
    depending on the number of server ports specified.
    
 1. Now, Run:

        python manage.py runserver <desired_ip>:<desired_port>
	
 1. Go to http://desired_host_or_ip:desired_port/admin

 1. Login with your credentials and look at the questions and modify if
    needed.  Create a new Quiz, set the date and duration or
    activate/deactivate the quiz.

 1. Now ask users to login at:

        http://host:port/exam

    And you should be all set.
    
 1. Note that the directory "output" will contain directories, one for each
    user.  Users can potentially write output into these that can be used
    for checking later.

 1. As admin user you can visit http://host/exam/monitor  to view
     results and user data interactively. You could also "grade" the
     papers manually if needed.

 1. You may dump the results and user data using the results2csv and
     dump_user_data commands.
     
 1. The file docs/sample_questions.py is a template that you can use for your own questions.
     
 1. Sometimes you might be in the situation where you are not hosted as
    "host.org/exam/"  but as "host.org/foo/exam/" for whatever reason.  In
    this case edit "settings.py" and set the "URL_ROOT"  to the root you
    have to serve at.  In the above example for "host.org/foo/exam" set
    URL_ROOT='/foo'.

Additional commands available
==============================

We provide several convenient commands for you to use:

 - load_exam : load questions and a quiz from a python file.  See
   docs/sample_questions.py

 - load_questions_xml : load questions from XML file, see
   docs/sample_questions.xml  use of this is deprecated in favor of
   load_exam.

 - results2csv : Dump the quiz results into a CSV file for further
   processing.

 - dump_user_data : Dump out relevalt user data for either all users or
   specified users.

For more information on these do this:

        $ python manage.py help [command]

where [command] is one of the above.


Inspiration
===========

At FOSSEE, Nishanth had implemented a nice django based app to
test for multiple-choice questions. I was inspired by a
programming contest that I saw at PyCon APAC 2011.  Chris Boesch, who
administered the contest, used a nice web application 
[Singpath](http://singpath.com) that he had built on top of GAE that 
basically checked your Python code, live. This made it fun and interesting.

I wanted an implementation that was not tied to GAE and decided to write
one myself and the result is the "exam" app.  The idea being that I can
use this to test students programming skills and not have to worry about
grading their answers myself and I can do so on my machines.


Contact
=======

For further information and support you can contact

* Forum Link
* Email Address

License
=======

This is distributed under the terms of the BSD license.  Copyright
information is at the bottom of this file.

Authors
=======

Main author: Prabhu Ramachandran

I gratefully acknowledge help from the following:

 - Nishanth Amuluru originally from FOSSEE who wrote bulk of the
   login/registration code.  He wrote an initial first cut of a quiz app
   which supported only simple questions which provided motivation for
   this app.  The current codebase does not share too much from his
   implementation although there are plenty of similarities.

 - Harish Badrinath (FOSSEE) -- who provided a first cut of the bash
   related scripts.

 - Srikant Patnaik and Thomas Stephen Lee, who helped deploy and test
   the code.


Copyright (c) 2011 Prabhu Ramachandran and FOSSEE (fossee.in)