-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
50 lines (39 loc) · 1.47 KB
/
run
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
#! /usr/bin/env python3
import sqlite3
import sqlfluff
import inginious_container_api.input as ingi_input
import inginious_container_api.feedback as ingi_feedback
BASE_SCORE = 100
SAMPLE_VALUES = [
"('line0', 0, 0.1)",
"('line1', 1, 0.2)",
"('line2', 2, 0.3)"
]
# Generate and populate dummy table
con = sqlite3.connect('/tmp/test.db')
cur = con.cursor()
cur.execute('CREATE TABLE test_table(field1, field2, field3)')
cur.execute('INSERT INTO test_table VALUES %s' % ', '.join(SAMPLE_VALUES))
con.commit()
score = BASE_SCORE
# TODO: sanitize input code
student_code = ingi_input.get_input('first')
lint = sqlfluff.lint(student_code)
print(lint)
if len(lint) > 0:
score = score / 2
ingi_feedback.set_problem_feedback("Some syntax errors in the code: %s" % '\n'.join(map(str, lint)), 'first')
student_result = cur.execute(student_code)
student_result = student_result.fetchall()
if set(student_result) != set([('line0', 0, 0.1), ('line1', 1, 0.2), ('line2', 2, 0.3)]):
score = 0
ingi_feedback.set_problem_feedback("Your answer returns %s" % '\n'.join(map(str, student_result)), 'first', append=True)
if score < 50:
ingi_feedback.set_problem_feedback("\nFailed", 'first', append=True)
ingi_feedback.set_problem_result("failed", 'first')
ingi_feedback.set_global_result("failed")
else:
ingi_feedback.set_problem_feedback("Success", 'first', append=True)
ingi_feedback.set_problem_result("success", 'first')
ingi_feedback.set_global_result("success")
ingi_feedback.set_grade(score)