Graduate

Update flask

......@@ -128,15 +128,15 @@ def verify():
if verified_id != None:
sql = "SELECT DATE(attendance_time) FROM student_attendance WHERE (lecture_id=%s) AND (student_id=%s) AND (DATE(attendance_time) = CURDATE());"
cursor.execute(sql, ('0', verified_id))
sql = "SELECT student_name FROM student WHERE student_id = %s"
cursor.execute(sql, (verified_id))
row_data = cursor.fetchone()
verified_name = row_data['student_name']
if cursor.rowcount == 0:
sql = "INSERT INTO student_attendance(lecture_id, student_id, status) VALUES (%s, %s, %s)"
# TODO: attend / late 처리
cursor.execute(sql, ('0', verified_id, 'attend'))
attendance_db.commit()
sql = "SELECT student_name FROM student WHERE student_id = %s"
cursor.execute(sql, (verified_id))
row_data = cursor.fetchone()
verified_name = row_data['student_name']
# log 작성
msg='[{id}] verification success'.format(id=verified_id)
print(msg)
......@@ -144,7 +144,7 @@ def verify():
else:
msg='[{id}] verification failed: already verified'.format(id=verified_id)
print(msg)
send = jsonify({'status': 'already', 'student_id': verified_id})
send = jsonify({'status': 'already', 'student_id': verified_id, 'student_name': verified_name})
else:
# 인증 실패
msg='[0000000000] verification failed'
......
......@@ -105,6 +105,7 @@ function processVideo() {
let msize = new cv.Size(120, 120);
classifier.detectMultiScale(gray, faces, 1.1, 3, 0, msize);
// draw faces.
console.log('draw faces');
for (let i = 0; i < faces.size(); ++i) {
let face = faces.get(i);
let point1 = new cv.Point(face.x, face.y);
......@@ -115,18 +116,26 @@ function processVideo() {
cropped = src.roi(rect);
let tempCanvas = document.createElement("canvas");
cv.imshow(tempCanvas,cropped);
console.log('b64encode');
if (tracker.register(face.x, face.y, face.width, face.height, Date.now())){
let b64encoded = tempCanvas.toDataURL("image/jpeg", 1.0);
b64encoded = b64encoded.replace('data:image/jpeg;base64,', '')
console.log('ajax post');
$.ajax({
type: "POST",
url: "/verify",
dataType: "json",
data: {'image':b64encoded},
success: function(data){
if (data.status == "success"){
if (data.status == "attend"){
var newDiv = document.createElement("div");
var newContent = document.createTextNode("출석");
var newContent = document.createTextNode('[' + data.student_id + '/' + data.student_name + ']' + "출석");
newDiv.appendChild(newContent);
document.body.appendChild(newDiv);
}
else if (data.status == "already"){
var newDiv = document.createElement("div");
var newContent = document.createTextNode('[' + data.student_id + '/' + data.student_name + ']' + "이미 출석처리 되었습니다.");
newDiv.appendChild(newContent);
document.body.appendChild(newDiv);
}
......