43785de6
Miguel Barão
- added documenta...
|
1
|
# Getting Started
|
a96cd2c7
Miguel Barão
- added logging s...
|
2
|
|
1e8f0810
Miguel Barão
update setup.py a...
|
3
|
Latest review: 2021-11-08
|
5d859a41
Miguel Barão
update documentation
|
4
5
6
|
## Installation
|
93e13002
Miguel Barão
updates README.md.
|
7
|
To complete the installation we will need to perform the following steps:
|
a96cd2c7
Miguel Barão
- added logging s...
|
8
|
|
39126690
Miguel Barão
removes npm and n...
|
9
10
11
12
|
1. install python3 and pip
2. install aprendizations
3. generate SSL certificates
4. configure the firewall (optional)
|
f540e673
Miguel Barão
- added README.md
|
13
|
|
5d859a41
Miguel Barão
update documentation
|
14
15
|
To use the software we need to:
|
39126690
Miguel Barão
removes npm and n...
|
16
|
1. initialize a database
|
443a1eea
Miguel Barão
Update to latest ...
|
17
|
2. go to the demo directory (or an existing course)
|
39126690
Miguel Barão
removes npm and n...
|
18
|
3. run `aprendizations courses.yaml`
|
5d859a41
Miguel Barão
update documentation
|
19
20
|
Each of these steps is explained below.
|
43785de6
Miguel Barão
- added documenta...
|
21
|
|
39126690
Miguel Barão
removes npm and n...
|
22
|
### Install python3 with sqlite3 support
|
43785de6
Miguel Barão
- added documenta...
|
23
|
|
39126690
Miguel Barão
removes npm and n...
|
24
25
|
Minimum supported version is python3.8. The installed versions depend on the
operating system default.
|
c54ee176
Miguel Barão
update javascript...
|
26
27
|
```sh
|
39126690
Miguel Barão
removes npm and n...
|
28
29
|
sudo pkg install python3 py38-sqlite3 # FreeBSD
sudo apt install python3 # Linux (Ubuntu)
|
1e8f0810
Miguel Barão
update setup.py a...
|
30
|
sudo port install python39 # MacOS
|
93e13002
Miguel Barão
updates README.md.
|
31
32
|
```
|
43785de6
Miguel Barão
- added documenta...
|
33
|
### Install pip
|
59213008
Miguel Barão
- fixed user path...
|
34
|
|
443a1eea
Miguel Barão
Update to latest ...
|
35
|
Install `pip` from the system package manager:
|
a96cd2c7
Miguel Barão
- added logging s...
|
36
|
|
43785de6
Miguel Barão
- added documenta...
|
37
|
```sh
|
39126690
Miguel Barão
removes npm and n...
|
38
39
|
sudo pkg install py38-pip # FreeBSD
sudo apt install python3-pip # Linux (Ubuntu)
|
1e8f0810
Miguel Barão
update setup.py a...
|
40
|
sudo port install py39-pip # MacOS
|
43785de6
Miguel Barão
- added documenta...
|
41
|
```
|
f540e673
Miguel Barão
- added README.md
|
42
|
|
443a1eea
Miguel Barão
Update to latest ...
|
43
44
|
In the end you should be able to run `pip --version` and `python3 -c "import
sqlite3"` without errors.
|
39126690
Miguel Barão
removes npm and n...
|
45
|
In some systems, `pip` can be named `pip3`, `pip3.8` or `pip-3.8`, etc.
|
5d859a41
Miguel Barão
update documentation
|
46
|
|
1e8f0810
Miguel Barão
update setup.py a...
|
47
48
49
50
51
|
Packages should **not** be installed system-wide. To install locally in the user
area, edit the configuration file `~/.config/pip/pip.conf` (FreeBSD, Linux) or
`Library/Application Support/pip/pip.conf` (MacOS) and add the lines
```ini
|
5dae401a
Miguel Barão
update README.md
|
52
|
[global]
|
f540e673
Miguel Barão
- added README.md
|
53
|
user = yes
|
43785de6
Miguel Barão
- added documenta...
|
54
55
56
57
|
```
### Install aprendizations
|
f540e673
Miguel Barão
- added README.md
|
58
|
```sh
|
39126690
Miguel Barão
removes npm and n...
|
59
|
pip install git+https://git.xdi.uevora.pt/mjsb/aprendizations.git
|
f540e673
Miguel Barão
- added README.md
|
60
|
```
|
43785de6
Miguel Barão
- added documenta...
|
61
|
|
39126690
Miguel Barão
removes npm and n...
|
62
|
Python packages are usually installed in:
|
43785de6
Miguel Barão
- added documenta...
|
63
|
|
f540e673
Miguel Barão
- added README.md
|
64
|
* `~/.local/lib/python3.8/site-packages/` in Linux/FreeBSD.
|
c3eba869
Miguel Barão
update README.md
|
65
|
* `~/Library/python/3.9/lib/python/site-packages/` in MacOS.
|
a96cd2c7
Miguel Barão
- added logging s...
|
66
|
|
443a1eea
Miguel Barão
Update to latest ...
|
67
|
When aprendizations is installed with pip, all the dependencies are also
|
1e8f0810
Miguel Barão
update setup.py a...
|
68
|
installed.
|
a96cd2c7
Miguel Barão
- added logging s...
|
69
|
|
443a1eea
Miguel Barão
Update to latest ...
|
70
|
At this point, the commands `aprendizations` and `initdb-aprendizations` are
|
39126690
Miguel Barão
removes npm and n...
|
71
|
installed in
|
f540e673
Miguel Barão
- added README.md
|
72
|
|
39126690
Miguel Barão
removes npm and n...
|
73
74
|
```sh
~/.local/bin # Linux/FreeBSD
|
5dae401a
Miguel Barão
update README.md
|
75
76
|
~/Library/Python/3.9/bin # MacOS
```
|
93e13002
Miguel Barão
updates README.md.
|
77
|
|
1e8f0810
Miguel Barão
update setup.py a...
|
78
|
and can be run from the terminal:
|
5dae401a
Miguel Barão
update README.md
|
79
80
|
```sh
|
93e13002
Miguel Barão
updates README.md.
|
81
|
aprendizations --version
|
b4ceb7fc
Miguel Barão
minor change in l...
|
82
|
aprendizations --help
|
93e13002
Miguel Barão
updates README.md.
|
83
84
85
|
initdb-aprendizations --help
```
|
39126690
Miguel Barão
removes npm and n...
|
86
|
### SSL Certificates
|
93e13002
Miguel Barão
updates README.md.
|
87
|
|
f540e673
Miguel Barão
- added README.md
|
88
|
We need certificates for https. Certificates can be self-signed or validated by
|
59213008
Miguel Barão
- fixed user path...
|
89
90
|
a trusted authority.
|
443a1eea
Miguel Barão
Update to latest ...
|
91
92
|
Self-signed can be used locally for development and testing, but browsers will
complain. LetsEncrypt issues trusted and free certificates, but the server must
|
c288f8c6
Miguel Barao
- updated documen...
|
93
|
have a registered publicly accessible domain name.
|
443a1eea
Miguel Barão
Update to latest ...
|
94
95
96
|
#### Generating selfsigned certificates
|
c288f8c6
Miguel Barao
- updated documen...
|
97
|
Generate a selfsigned certificate and place it in `~/.local/share/certs`.
|
93e13002
Miguel Barão
updates README.md.
|
98
|
|
f540e673
Miguel Barão
- added README.md
|
99
|
```sh
|
b4ceb7fc
Miguel Barão
minor change in l...
|
100
|
openssl req -x509 -newkey rsa:4096 -keyout privkey.pem -out cert.pem -days 365 -nodes
|
59213008
Miguel Barão
- fixed user path...
|
101
|
```
|
43785de6
Miguel Barão
- added documenta...
|
102
103
104
|
#### LetsEncrypt certificates
|
59213008
Miguel Barão
- fixed user path...
|
105
|
Install the certbot from LetsEncrypt:
|
93e13002
Miguel Barão
updates README.md.
|
106
107
108
|
```sh
sudo pkg install py38-certbot # FreeBSD
|
bbc1c506
Miguel Barão
- documentation u...
|
109
|
sudo apt install certbot # Ubuntu
|
43785de6
Miguel Barão
- added documenta...
|
110
|
```
|
443a1eea
Miguel Barão
Update to latest ...
|
111
|
|
5d859a41
Miguel Barão
update documentation
|
112
|
To generate or renew the certificates, ports 80 and 443 must be accessible.
|
43785de6
Miguel Barão
- added documenta...
|
113
|
**Any firewall and webserver have to be stopped**.
|
bbc1c506
Miguel Barão
- documentation u...
|
114
|
|
443a1eea
Miguel Barão
Update to latest ...
|
115
116
|
```sh
sudo certbot certonly --standalone -d www.example.com # first time
|
bbc1c506
Miguel Barão
- documentation u...
|
117
|
sudo certbot renew # renew
|
43785de6
Miguel Barão
- added documenta...
|
118
|
```
|
93e13002
Miguel Barão
updates README.md.
|
119
120
|
Certificates are saved under
|
43785de6
Miguel Barão
- added documenta...
|
121
|
`/usr/local/etc/letsencrypt/live/www.example.com/`. Copy them to
|
bbc1c506
Miguel Barão
- documentation u...
|
122
|
`~/.local/share/certs` and change permissions to be readable:
|
443a1eea
Miguel Barão
Update to latest ...
|
123
124
125
|
```sh
cd ~/.local/share/certs
|
bbc1c506
Miguel Barão
- documentation u...
|
126
|
sudo cp /usr/local/etc/letsencrypt/live/www.example.com/cert.pem .
|
43785de6
Miguel Barão
- added documenta...
|
127
|
sudo cp /usr/local/etc/letsencrypt/live/www.example.com/privkey.pem .
|
443a1eea
Miguel Barão
Update to latest ...
|
128
|
chmod 400 cert.pem privkey.pem
|
43785de6
Miguel Barão
- added documenta...
|
129
130
131
132
|
```
## Configuration
|
bbc1c506
Miguel Barão
- documentation u...
|
133
|
### Database
|
5d859a41
Miguel Barão
update documentation
|
134
135
136
137
|
User data is maintained in a sqlite3 database which has to be created manually
using the `initdb-aprendizations` command. The database file should be located
in the same directory as the main YAML configuration file (`courses.yaml`).
|
443a1eea
Miguel Barão
Update to latest ...
|
138
139
|
For example, to run the included demo do:
|
39126690
Miguel Barão
removes npm and n...
|
140
|
|
5d859a41
Miguel Barão
update documentation
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
```sh
cd demo # contains a small example
initdb-aprendizations # show or initialize database
initdb-aprendizations --admin # add admin user
initdb-aprendizations inscricoes.csv # add students from CSV
initdb-aprendizations --add 1184 "Aladino da Silva" # add new user
initdb-aprendizations --update 1184 --pw alibaba # update password
initdb-aprendizations --help # for available options
```
The default password is equal to the user name, if left undefined.
### Running the demo
The application includes a small example in `demo/courses.yaml` that can be used
|
93e13002
Miguel Barão
updates README.md.
|
156
|
for initial testing. Run it with
|
c55940af
Miguel Barão
- minor change in...
|
157
|
|
39126690
Miguel Barão
removes npm and n...
|
158
|
```sh
|
443a1eea
Miguel Barão
Update to latest ...
|
159
|
cd demo
|
f540e673
Miguel Barão
- added README.md
|
160
|
aprendizations courses.yaml
|
43785de6
Miguel Barão
- added documenta...
|
161
|
```
|
3ec49458
Miguel Barão
fix README.md and...
|
162
|
|
39126690
Miguel Barão
removes npm and n...
|
163
|
Open the browser at [https://127.0.0.1:8443](https://127.0.0.1:8443).
|
43785de6
Miguel Barão
- added documenta...
|
164
|
If everything looks good, check at the correct address
|
59213008
Miguel Barão
- fixed user path...
|
165
|
`https://www.example.com:8443`.
|
443a1eea
Miguel Barão
Update to latest ...
|
166
167
|
The option `--debug` provides more verbose logging and might be useful during
testing.
|
93e13002
Miguel Barão
updates README.md.
|
168
|
|
443a1eea
Miguel Barão
Update to latest ...
|
169
170
|
### Firewall configuration
|
c288f8c6
Miguel Barao
- updated documen...
|
171
|
Ports 80 and 443 are only usable by root. For security reasons the server runs
|
59213008
Miguel Barão
- fixed user path...
|
172
173
|
as an unprivileged user on port 8443 for https. To access the server in the
default https port (443), port forwarding must be configured in the firewall.
|
443a1eea
Miguel Barão
Update to latest ...
|
174
175
176
|
#### FreeBSD and pf
|
59213008
Miguel Barão
- fixed user path...
|
177
178
179
180
181
|
Edit `/etc/pf.conf`:
```sh
ext_if="em0" # change em0 to the correct network interface
rdr on $ext_if proto tcp from any to any port 80 -> 127.0.0.1 port 8080
|
43785de6
Miguel Barão
- added documenta...
|
182
|
rdr on $ext_if proto tcp from any to any port 443 -> 127.0.0.1 port 8443
|
93e13002
Miguel Barão
updates README.md.
|
183
|
```
|
43785de6
Miguel Barão
- added documenta...
|
184
185
186
|
Virtualbox with guest additions uses `ext_if="vtnet0"`.
|
59213008
Miguel Barão
- fixed user path...
|
187
|
Edit `/etc/rc.conf`
|
5d859a41
Miguel Barão
update documentation
|
188
|
|
59213008
Miguel Barão
- fixed user path...
|
189
|
```sh
|
43785de6
Miguel Barão
- added documenta...
|
190
|
pf_enable="YES"
|
59213008
Miguel Barão
- fixed user path...
|
191
|
pf_flags=""
|
43785de6
Miguel Barão
- added documenta...
|
192
193
194
195
|
pf_rules="/etc/pf.conf"
# optional logging:
pflog_enable="YES"
|
59213008
Miguel Barão
- fixed user path...
|
196
|
pflog_flags=""
|
43785de6
Miguel Barão
- added documenta...
|
197
198
199
200
201
|
pflog_logfile="/var/log/pflog"
```
Reboot or `sudo service pf start`.
|
59213008
Miguel Barão
- fixed user path...
|
202
|
Example configuration files are in the `freebsd` directory.
|
ea4ff4d2
Miguel Barão
- radio: added su...
|
203
|
|
59213008
Miguel Barão
- fixed user path...
|
204
|
### Testing the system
|
39126690
Miguel Barão
removes npm and n...
|
205
206
|
Make sure the following steps have been done:
|
93e13002
Miguel Barão
updates README.md.
|
207
208
209
210
|
* installed python3 and pip
* installed aprendizations using pip
* initialized database with at least 1 user
|
39126690
Miguel Barão
removes npm and n...
|
211
212
|
* generate and copy certificates to the appropriate place
* (optional) configure the firewall to do port forwarding
|
443a1eea
Miguel Barão
Update to latest ...
|
213
214
215
|
* run `aprendizations courses.yaml --check`
## Keeping aprendizations updated
|
39126690
Miguel Barão
removes npm and n...
|
216
|
|
a203d3cc
Miguel Barão
- new http server...
|
217
|
To update aprendizations to the latest version do:
|
5d859a41
Miguel Barão
update documentation
|
218
219
220
221
222
|
```sh
pip install -U git+https://git.xdi.uevora.pt/mjsb/aprendizations.git
```
|
39126690
Miguel Barão
removes npm and n...
|
223
|
## Troubleshooting
|
5d859a41
Miguel Barão
update documentation
|
224
225
|
To help with troubleshooting, use the option `--debug` when running the server.
|
59213008
Miguel Barão
- fixed user path...
|
226
227
|
This will increase logs in the terminal and will present the python exception
errors in the browser.
|
443a1eea
Miguel Barão
Update to latest ...
|
228
229
|
Logging levels can be adjusted in `~/.config/aprendizations/logger.yaml` and
|
5dae401a
Miguel Barão
update README.md
|
230
|
`~/.config/aprendizations/logger-debug.yaml`.
|
43785de6
Miguel Barão
- added documenta...
|
231
|
|
443a1eea
Miguel Barão
Update to latest ...
|
232
|
If these files do not yet exist, there are examples in `aprendizations/config`
|
5dae401a
Miguel Barão
update README.md
|
233
|
that can be copied to `~/.config/aprendizations`.
|
43785de6
Miguel Barão
- added documenta...
|
234
|
|
443a1eea
Miguel Barão
Update to latest ...
|
235
236
|
### UnicodeEncodeError
|
43785de6
Miguel Barão
- added documenta...
|
237
|
The server should not generate this error, but when using external scripts to
|
443a1eea
Miguel Barão
Update to latest ...
|
238
|
generate questions or to correct, these scripts can print unicode strings to
|
59213008
Miguel Barão
- fixed user path...
|
239
|
stdout. If the terminal does not support unicode, python will generate an
|
443a1eea
Miguel Barão
Update to latest ...
|
240
241
242
|
exception.
* FreeBSD fix: edit `~/.login_conf` to use UTF-8, for example:
|
5dae401a
Miguel Barão
update README.md
|
243
|
|
59213008
Miguel Barão
- fixed user path...
|
244
|
```sh
|
443a1eea
Miguel Barão
Update to latest ...
|
245
|
me:\
|
59213008
Miguel Barão
- fixed user path...
|
246
|
:charset=UTF-8:\
|
43785de6
Miguel Barão
- added documenta...
|
247
248
249
250
251
|
:lang=en_US.UTF-8:
```
* Debian fix: check `locale`...
|
f75a344f
Miguel Barão
- README.md updat...
|
252
|
### The application runs but questions do not show up
|
443a1eea
Miguel Barão
Update to latest ...
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
Some operating systems have an option to disable animations to try to avoid
motion sickness in some people. Browsers will check this option with the OS and
prevent animate.css library to work. Since questions have several animations,
these will will not work and nothing is shown on the page.
To fix this issue you need to allow animations in the Operating System:
* On windows 10, go to System Preferences, search for "Show animations in
windows" and turn it **ON**.
* On MacOS or iOS search for reduced motion and switch it **OFF**
(Preferences -> Acessibility -> Display -> Reduce motion).
## FAQ
|
db04e658
Miguel Barão
- added option to...
|
268
|
Common database manipulations:
|
43785de6
Miguel Barão
- added documenta...
|
269
|
|
f75a344f
Miguel Barão
- README.md updat...
|
270
|
```sh
|
93e13002
Miguel Barão
updates README.md.
|
271
|
initdb-aprendizations -u 12345 --pw alibaba # reset student password
|
f75a344f
Miguel Barão
- README.md updat...
|
272
|
initdb-aprendizations -a 007 "James Bond" --pw mi6 # add new student "007"
|
43785de6
Miguel Barão
- added documenta...
|
273
|
```
|
d187aad4
Miguel Barão
- adds courses
|
274
275
|
Some common database queries:
|
43785de6
Miguel Barão
- added documenta...
|
276
|
|
f75a344f
Miguel Barão
- README.md updat...
|
277
|
```sh
|
d187aad4
Miguel Barão
- adds courses
|
278
|
# Which students did at least one topic?
|
f75a344f
Miguel Barão
- README.md updat...
|
279
|
sqlite3 students.db "select distinct student_id from studenttopic"
|
43785de6
Miguel Barão
- added documenta...
|
280
|
|
93e13002
Miguel Barão
updates README.md.
|
281
282
|
# How many topics has each student done?
sqlite3 students.db "select student_id, count(topic_id) from studenttopic \
|
f75a344f
Miguel Barão
- README.md updat...
|
283
|
group by student_id order by count(topic_id) desc"
|
93e13002
Miguel Barão
updates README.md.
|
284
|
|
443a1eea
Miguel Barão
Update to latest ...
|
285
286
|
# Which questions have more wrong answers?
sqlite3 students.db "select count(ref), ref from answers where grade<1.0 \
|
f75a344f
Miguel Barão
- README.md updat...
|
287
|
group by ref order by count(ref) desc"
|
93e13002
Miguel Barão
updates README.md.
|
288
|
```
|
443a1eea
Miguel Barão
Update to latest ...
|
|
|
93e13002
Miguel Barão
updates README.md.
|
|
|