def startNewAttendance(): if request.method == 'POST': attendance = Attendance(attendanceCollection) data = request.get_json() courseCode = data['courseCode'] date = helpers.getDate() attendanceExits = attendance.getAttendance(date, courseCode) attendanceExits = loads(attendanceExits) if (len(attendanceExits) > 0): res = jsonify('Attendace has already been taken for today') return res student = Students(studentCollection) students = student.getStudentsForParticleCourse(courseCode) stdAttendance = loads(students) for student in stdAttendance: student['present'] = False classAttendance = {'allStudents': stdAttendance, 'unknownStudents': []} obj = { 'courseCode': courseCode, 'date': date, 'classAttendance': classAttendance } att = attendance.addNewAttendance(obj) res = jsonify('New Attendance started.') return res
def findFaces(): if request.method == 'POST': attendance = Attendance(attendanceCollection) data = request.get_json() # img_data = data['image'] courseCode = data['courseCode'] path = f'api/currentFrame/imageFrame' # helpers.base64toImg(img_data, path) helpers.single_frame(path) # print(d) date = helpers.getDate() # Date of today currentClassAttendace = attendance.getAttendance(date, courseCode) currentClassAttendanceObj = loads(currentClassAttendace) markedAttendace = helpers.findFaces(path, currentClassAttendanceObj) attendance.updateStudentAttendance(currentClassAttendanceObj[0]['_id'], markedAttendace) if os.path.exists(f'{path}.jpg'): os.remove(f'{path}.jpg') else: print("The file does not exist") completeAttendace = attendance.getAttendanceById( currentClassAttendanceObj[0]['_id']) completeAttendaceObj = loads(completeAttendace) for student in completeAttendaceObj['classAttendance']['allStudents']: student.pop('encodings') return dumps(completeAttendaceObj)