-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tex
289 lines (222 loc) · 10 KB
/
main.tex
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
\documentclass{beamer}
\usepackage{minted}
\usepackage{hyperref}
\usepackage{xcolor}
\usetheme{metropolis}
\definecolor{cvutblue}{RGB}{1,44,86} % Defining a custom color
\setbeamercolor{palette primary}{bg=cvutblue,fg=white}
\title{Flask web evaluation for QtRvSim}
% March 16th 2024
\date{16.3.2024}
\author{Jakub Pelc}
\institute{Faculty of Electrical Engineering, Czech Technical University in Prague \par Installfest 2024}
\begin{document}
\maketitle
\section{Goals of this project}
\begin{frame}{Bonus task evaluation}
The main aim for this project is to allow external participants (as well as students) to improve their skills in computer architectures, by solving tasks in RISC-V assembly. \par
The original way involved students of \href{https://cw.fel.cvut.cz/wiki/courses/b35apo/en/start}{\texttt{B35APO}} solving a set of \href{https://cw.fel.cvut.cz/wiki/courses/b35apo/en/homeworks/bonus/start}{\texttt{bonus tasks}},
which were available to submit through GitLab and subsequently evaluated using \href{https://github.com/cvut/qtrvsim}{\texttt{QtRvSim}}. \par
This is unfortunately not available to the general public, and that is the reason why this project was created.
\end{frame}
\begin{frame}{Current state}
Registered users can register and submit solutions to the problems displayed on the frontpage and get immediate feedback on their solution.
Local scoreboard is displayed for each task.\par
This is done by running a local evaluation procedure (with the use of \href{https://github.com/cvut/qtrvsim}{\texttt{QtRvSim CLI}}), which evaluates the correctness of the code submitted and yields the performance as a score.
The project needed to be rather simple, for it to allow easy modularity and optional modification in the future. It can be expanded by
more features, language support, or task types. \par
This is why Flask was chosen as the web framework.
\end{frame}
\begin{frame}{User interface}
\centering
\includegraphics[width=1.0\textwidth]{images/ui.png}
\href{http://eval.comparch.edu.cvut.cz}{\texttt{eval.comparch.edu.cvut.cz}}
\end{frame}
\section{A little bit about Flask}
\begin{frame}{Flask}
Flask is a micro web framework written in Python. It provides a simple way to create web applications. \par
As opposed to Django, Flask is not an all-inclusive framework. It is designed to be simple and easy to use. \par
To start creating a web application, the only thing needed is to have Flask installed and to have a simple python script.
\end{frame}
\begin{frame}[fragile]
\begin{minted}{python}
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "<p>Hello, World!</p>"
\end{minted}
\end{frame}
\begin{frame}{Loading template files}
We can utilize Flask to load HTML templates, instead of writing all of our HTML code in the \texttt{app.py} file. \par
These template files should be located in the \texttt{templates} directory. \par
For this example, we will use a standard HTML register page.
\end{frame}
\begin{frame}[fragile]
\small
\inputminted{python}{examples/2/app.py}
\end{frame}
\begin{frame}{Jinja2 templating}
This is still not ideal, as we need to create a completely new HTML page for every route. \par
For this problem, we can utilize the Jinja2 templating engine to create a base template, and then inherit from this template.
Static files (such as CSS stylesheets, or images) can also be included. \par
\end{frame}
\begin{frame}[fragile]
\tiny
\inputminted{html}{examples/3/templates/base.html}
\end{frame}
\begin{frame}[fragile]
\small
\inputminted{html}{examples/3/templates/register.html}
\end{frame}
\begin{frame}{Flask sessions}
The session system allows the storage of information about the user across multiple requests. \par
Variables can also be passed to the template which are then used while rendering the page. \par
This can be demonstrated by creating a simple login system.
\end{frame}
\begin{frame}[fragile]
\tiny
\inputminted{python}{examples/4/app.py}
\end{frame}
\section{Database}
\begin{frame}{Communication with the database}
In the web application, a PostgreSQL database is used. \par
Only a few tables are needed to store the information about the users, tasks, submissions and results. \par
PostgreSQL triggers are used to automatically update the best score and source code.
\end{frame}
\begin{frame}{Users Table}
\centering
\begin{tabular}{|l|l|l|l|}
\hline
Field & Type & Length & Default \\
\hline
id & int & 32 & AUTO\_INCREMENT \\
username & varchar & 128 & None \\
password & varchar & 128 & None \\
email & varchar & 128 & None \\
salt & varchar & 128 & None \\
verification\_code & varchar & 128 & None \\
user\_verified & tinyint & 1 & 0 \\
\hline
\end{tabular}
\end{frame}
\begin{frame}{GDPR}
Email adresses of the users are not being saved (due to GDPR), but during the registration process, the users are required to provide an email address for verification purposes. So how is that achieved?\par
The email address is saved as a salted \texttt{SHA-256} hash. This way, the email address can we verified, but cannot be reverse engineered to obtain the original email address. \par
This also allows for password reset functionality, without the need to store the email address in a readable format. Users always need to provide the email address, which is then checked against the hash in the database.
\end{frame}
\begin{frame}{Submissions Table}
\centering
\begin{tabular}{|l|l|l|l|}
\hline
Field & Type & Length & Default \\
\hline
id & int & 64 & AUTO\_INCREMENT \\
userid & int & 64 & None \\
taskid & int & 64 & None \\
file & text & 64 & None \\
evaluated & tinyint & 1 & 0 \\
time & datetime & None & current\_timestamp() \\
\hline
\end{tabular}
\end{frame}
\begin{frame}{Results Table}
\small
\centering
\begin{tabular}{|l|l|l|}
\hline
Field & Type & Default \\
\hline
userid & bigint & PRIMARY \\
taskid & bigint & PRIMARY \\
result\_file & text & NULL \\
last\_source & text & NULL \\
best\_source & text & NULL \\
score\_last & integer & -1 \\
score\_best & integer & -1 \\
time & timestamp with time zone & CURRENT\_TIMESTAMP \\
result & smallint & -1 \\
\hline
\end{tabular}
\end{frame}
\begin{frame}[fragile]
\begin{minted}{python}
import psycopg2
import os
db_config = {
'user': os.getenv('DB_USER'),
'password': os.getenv('DB_PASSWORD'),
'host': os.getenv('DB_HOST'),
'database': os.getenv('DB_DATABASE'),
'port': os.getenv('DB_PORT'),
'sslmode': 'require',
'connect_timeout': 10
}
\end{minted}
\end{frame}
\begin{frame}[fragile]
\begin{minted}{python}
def connect():
db = psycopg2.connect(**db_config)
cursor = db.cursor()
return (db, cursor)
def get_user(username):
(db, cursor) = connect()
cursor.execute('SELECT password FROM \
users WHERE username = %s', (username,))
user = cursor.fetchone()
cursor.close()
db.close()
return user
\end{minted}
\end{frame}
\section{Evaluation using QtRvSim}
\begin{frame}{Submission evaluation}
Each of the submissions is being evaluated by a \texttt{qtrvsim\_cli} python
wrapper \href{https://gitlab.fel.cvut.cz/b35apo/qtrvsim-eval-web/-/blob/main/evaluator/qtrvsim.py}{\texttt{qtrvsim.py}}. \par
For each task, a \texttt{.toml} file defines its structure, this file is then parsed using an \href{https://gitlab.fel.cvut.cz/b35apo/qtrvsim-eval-web/-/blob/main/evaluator/evaluator.py}{\texttt{evaluator.py}} script. A new QtRvSim instance is initialized with needed parameters,
the instance evaluates all the testcases declared in the task file and measures the performance of the user's submission. \par
The result, score, and the log are then displayed to the user.
\end{frame}
\begin{frame}[fragile]
\tiny
\inputminted{python}{examples/5/evaluate.py}
\end{frame}
\begin{frame}[fragile]
\tiny
\inputminted{toml}{examples/5/task.toml}
\end{frame}
\begin{frame}{Advanced tasks}
The evaluator is also able to set a cache for the task, whose parameters are configurable as a part of the task. This is done by setting the maximum cache size for the task, users are then required to configure the cache parameters. \par
Serial input and output can also be used. \par
It is also possible, to create a task in \texttt{C}, but this also requires a custom Makefile to be provided in the taskfile. If custom files need to be present at compile time, they can also be provided. \par
\end{frame}
\begin{frame}[fragile]
\small
\inputminted{toml}{examples/5/cache.toml}
\end{frame}
\begin{frame}[fragile]
\tiny
\inputminted{toml}{examples/5/complex.toml}
\end{frame}
\section{Mini Competition}
\begin{frame}{Mini Competition}
On the page \par
{\centering \texttt{\href{http://eval.comparch.edu.cvut.cz}{eval.comparch.edu.cvut.cz}} \par}
you can try out your skills in RISC-V assembly. \par
For each task the best five users will acquire $(6 - p)$ points, where p is the place they finished (according to the cycles needed to execute their solution).\par
If two users finish with the same amount of cycles, their solution will be scored with the higher amount of points. \par
We offer FEE CTU merch for the best users overall, who submit their solutions before 17.3. 12:45. \par
\end{frame}
\section{References}
\begin{frame}{References}
Links and references: \par
{\centering \texttt{\href{https://flask.palletsprojects.com/en/3.0.x/}{Flask}} \par}
{\centering \texttt{\href{http://eval.comparch.edu.cvut.cz}{eval.comparch.edu.cvut.cz}} \par}
{\centering \texttt{\href{http://comparch.edu.cvut.cz}{comparch.edu.cvut.cz}} \par}
{\centering \texttt{\href{https://github.com/cvut/qtrvsim}{QtRvSim repository}} \par}
{\centering \texttt{\href{https://gitlab.fel.cvut.cz/b35apo/qtrvsim-eval-web}{Web Eval repository}} \par}
{\centering \texttt{\href{https://github.com/kubakubakuba/if24-flask-web-eval}{Slides with examples}} \par}
{\centering \texttt{\href{https://swpelc.eu}{Jakub Pelc}} \par}
\end{frame}
\end{document}