Graduate

Change query checking method

...@@ -30,7 +30,7 @@ async def send_face(face_list, image_list): ...@@ -30,7 +30,7 @@ async def send_face(face_list, image_list):
30 async with websockets.connect(uri) as websocket: 30 async with websockets.connect(uri) as websocket:
31 for face, image in zip(face_list, image_list): 31 for face, image in zip(face_list, image_list):
32 #type: np.float32 32 #type: np.float32
33 - send = json.dumps({'action': 'register', 'student_id':'2014104149', 'student_name':'정해갑', 'MTCNN': face.tolist()}) 33 + send = json.dumps({'action': 'register', 'student_id':'2014101898', 'student_name':'김다솜', 'MTCNN': face.tolist()})
34 await websocket.send(send) 34 await websocket.send(send)
35 recv = await websocket.recv() 35 recv = await websocket.recv()
36 data = json.loads(recv) 36 data = json.loads(recv)
......
...@@ -86,10 +86,10 @@ async def thread(websocket, path): ...@@ -86,10 +86,10 @@ async def thread(websocket, path):
86 86
87 # 학생을 찾음 87 # 학생을 찾음
88 sql = "SELECT student_id FROM student WHERE student_id = %s;" 88 sql = "SELECT student_id FROM student WHERE student_id = %s;"
89 - cursor.execute(sql, (student_id)) 89 + rows_count = cursor.execute(sql, (student_id))
90 90
91 # DB에 학생이 없으면 등록 91 # DB에 학생이 없으면 등록
92 - if not cursor.fetchone(): 92 + if rows_count == 0:
93 sql = "INSERT INTO student(student_id, student_name) VALUES (%s, %s)" 93 sql = "INSERT INTO student(student_id, student_name) VALUES (%s, %s)"
94 cursor.execute(sql, (student_id, student_name)) 94 cursor.execute(sql, (student_id, student_name))
95 sql = "INSERT INTO lecture_students(lecture_id, student_id) VALUES (%s, %s)" 95 sql = "INSERT INTO lecture_students(lecture_id, student_id) VALUES (%s, %s)"
...@@ -141,10 +141,10 @@ async def thread(websocket, path): ...@@ -141,10 +141,10 @@ async def thread(websocket, path):
141 # 인증 성공 141 # 인증 성공
142 # 오늘 이미 출석 됐는지 확인 142 # 오늘 이미 출석 됐는지 확인
143 sql = "SELECT DATE(timestamp) FROM student_attendance WHERE (lecture_id=%s) AND (student_id=%s) AND (DATE(timestamp) = CURDATE());" 143 sql = "SELECT DATE(timestamp) FROM student_attendance WHERE (lecture_id=%s) AND (student_id=%s) AND (DATE(timestamp) = CURDATE());"
144 - cursor.execute(sql, ('0', verified_id)) 144 + rows_count = cursor.execute(sql, ('0', verified_id))
145 145
146 # 출석 기록이 없는 경우에만 146 # 출석 기록이 없는 경우에만
147 - if not cursor.fetchone(): 147 + if rows_count == 0:
148 # 테이블 맨 뒤에 datetime attribute가 있음. 서버 시간 가져오게 default로 설정해둠. 148 # 테이블 맨 뒤에 datetime attribute가 있음. 서버 시간 가져오게 default로 설정해둠.
149 sql = "INSERT INTO student_attendance(lecture_id, student_id, status) VALUES (%s, %s, %s)" 149 sql = "INSERT INTO student_attendance(lecture_id, student_id, status) VALUES (%s, %s, %s)"
150 # TODO: attend / late 처리 150 # TODO: attend / late 처리
......