-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_comments.py
executable file
·131 lines (98 loc) · 3.92 KB
/
create_comments.py
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
import sqlite3 as lite
import sys
import random
def commentsType(comments, type):
commentsTypeList = []
for comment in comments:
if comment[2] == type:
commentsTypeList.append(comment)
return commentsTypeList
def selectComment(commentsTypeList, grade, pct):
strComment = ""
commentGrade = 0
gradeValue = (float(pct.strip('%')))
tries = 10
while not commentGrade > gradeValue and tries != 0:
comment = random.choice(commentsTypeList)
commentGrade = comment[3]
if commentGrade > gradeValue:
strComment = comment[1]
else:
tries -= 1
return strComment
def replaceTokens(comm, tokens, firstName, gender, form):
comm = comm.replace('<firstname>', firstName)
for token in tokens:
replaceValue = ''
if gender == 'M':
replaceValue = token[2]
elif gender == 'F':
replaceValue = token[3]
if token[1] == '<subject>':
if form == 'U6' or form == 'L6':
replaceValue = 'Computer Science'
comm = comm.replace(token[1], replaceValue)
return comm
def StudentReport(student, tokens, comments):
strTokens = []
strTokenFemale = []
strTokenMale = []
nRow = 0
for row in tokens:
strTokens.append(row[1])
strTokenMale.append(row[2])
strTokenFemale.append(row[3])
nRow += 1
studentGrade = student[4]
studentPct = student[5]
intStudentId = student[0]
strFirstName = student[1]
strGender = student[3]
strForm = student[6]
finalComment = []
finalComment.append(selectComment(commentsType(comments, 'Comment 1'), student[4], student[5]))
finalComment.append(selectComment(commentsType(comments, 'Comment 2'), student[4], student[5]))
finalComment.append(selectComment(commentsType(comments, 'Comment 3'), student[4], student[5]))
finalComment.append(selectComment(commentsType(comments, 'Comment 4'), student[4], student[5]))
finalComment.append(selectComment(commentsType(comments, 'Comment 5'), student[4], student[5]))
finalComment.append(selectComment(commentsType(comments, 'Target 1'), student[4], student[5]))
finalComment.append(selectComment(commentsType(comments, 'Target 2'), student[4], student[5]))
finalComment.append(selectComment(commentsType(comments, 'Target 3'), student[4], student[5]))
for index, comm in enumerate(finalComment):
finalComment[index] = replaceTokens(comm, tokens, strFirstName, strGender, strForm)
comment = ' '.join(finalComment)
return (intStudentId, comment)
def CreateReports(form, reportId):
con = None
try:
con = lite.connect('GGCommentsDB.db')
cur = con.cursor()
version = cur.execute('SELECT SQLITE_VERSION()').fetchall()
print(version)
comments = cur.execute('SELECT id,comentario,type,weight FROM Comments').fetchall()
print(comments)
tokens = cur.execute('SELECT id, token, male, female FROM Tokens').fetchall()
print(tokens)
students = cur.execute(
"SELECT Students.id AS id, firstname, surname, gender, grade, pct, form FROM Students,final_grade "
"WHERE Students.id = final_grade.student_id AND form=?", ('F2',)).fetchall()
print(students)
count = reportId
for student in students:
storeComment = StudentReport(student, tokens, comments)
print(storeComment)
cur.execute('INSERT INTO Results (id, student_id, term, final_comment) VALUES (?,?,?,?)',
(count, storeComment[0], 'G1', storeComment[1]))
count += 1
con.commit()
return count
except lite.Error as e:
print("Error %s:" % e.args[0])
sys.exit(1)
finally:
if con:
con.close()
groups = ["F1", "F2", "F3", "L6", "U6"]
reportId = 0
for group in groups:
reportId = CreateReports(groups, reportId)