Merge pull request 'update(fe): speak name' (#150) from zelda.update-checkin-api into master
Reviewed-on: #150
This commit is contained in:
commit
6ccf5e9e8a
Binary file not shown.
|
|
@ -190,115 +190,6 @@ async def register_student(
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# @app.post("/checkin")
|
|
||||||
# async def checkin(background_tasks: BackgroundTasks, file: UploadFile = File(...), camera_id: str = Form("cam1"), db: Session = Depends(get_db)):
|
|
||||||
# image_data = await file.read()
|
|
||||||
# path = os.path.join(UPLOAD_DIR, "checkin.jpg")
|
|
||||||
# with open(path, "wb") as f:
|
|
||||||
# f.write(image_data)
|
|
||||||
|
|
||||||
# unknown_img = face_recognition.load_image_file(path)
|
|
||||||
# unknown_encodings = face_recognition.face_encodings(unknown_img)
|
|
||||||
|
|
||||||
# if not unknown_encodings:
|
|
||||||
# return {"message": "No face detected."}
|
|
||||||
|
|
||||||
# unknown_encoding = unknown_encodings[0]
|
|
||||||
|
|
||||||
# # Get all encodings with student info
|
|
||||||
# encodings = db.execute(
|
|
||||||
# text("""
|
|
||||||
# SELECT s.id, s.name, s.email, s.avatar, se.encoding
|
|
||||||
# FROM student_encodings se
|
|
||||||
# JOIN students s ON s.id = se.student_id
|
|
||||||
# """)
|
|
||||||
# ).fetchall()
|
|
||||||
|
|
||||||
# for encoding in encodings:
|
|
||||||
# known_encoding = np.frombuffer(encoding.encoding)
|
|
||||||
# result = face_recognition.compare_faces([known_encoding], unknown_encoding, tolerance=0.5)
|
|
||||||
# if result[0]:
|
|
||||||
# now = datetime.datetime.now()
|
|
||||||
|
|
||||||
# # Check recent checkin
|
|
||||||
# recent_check = db.execute(
|
|
||||||
# text("""
|
|
||||||
# SELECT id FROM checkin_logs
|
|
||||||
# WHERE student_id = :student_id
|
|
||||||
# AND time > :time_threshold
|
|
||||||
# """),
|
|
||||||
# {
|
|
||||||
# "student_id": encoding.id,
|
|
||||||
# "time_threshold": now - datetime.timedelta(minutes=0.5)
|
|
||||||
# }
|
|
||||||
# ).fetchone()
|
|
||||||
|
|
||||||
# if recent_check:
|
|
||||||
# return {
|
|
||||||
# "message": f"{encoding.name} already checked in recently.",
|
|
||||||
# "checking": False,
|
|
||||||
# "data": {
|
|
||||||
# "id": encoding.id,
|
|
||||||
# "name": encoding.name,
|
|
||||||
# "email": encoding.email,
|
|
||||||
# "avatar": encoding.avatar,
|
|
||||||
# "camera_id": camera_id,
|
|
||||||
# "time": now.isoformat()
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# # thêm dô đây
|
|
||||||
# # id_log = 0
|
|
||||||
# # ms_response = create_history({"name": encoding.name.split('\n')[0], "time_string": f"{datetime.datetime.now()}", "status": "check in"})
|
|
||||||
# # id_log = ms_response.get('data').get('id')
|
|
||||||
# # status = ms_response.get('data').get('status')
|
|
||||||
# status = "check in"
|
|
||||||
|
|
||||||
# # # reset pointer
|
|
||||||
# # file.file.seek(0)
|
|
||||||
|
|
||||||
# # background_tasks.add_task(
|
|
||||||
# # send_image,
|
|
||||||
# # id_log,
|
|
||||||
# # image_data, # truyền bytes, không phải UploadFile
|
|
||||||
# # encoding.name,
|
|
||||||
# # status
|
|
||||||
# # )
|
|
||||||
|
|
||||||
# # Insert new checkin
|
|
||||||
# db.execute(
|
|
||||||
# text("""
|
|
||||||
# INSERT INTO checkin_logs (student_id, time, camera_id, status)
|
|
||||||
# VALUES (:student_id, :time, :camera_id, :status)
|
|
||||||
# """),
|
|
||||||
# {
|
|
||||||
# "student_id": encoding.id,
|
|
||||||
# "time": now,
|
|
||||||
# "camera_id": camera_id,
|
|
||||||
# "status": status
|
|
||||||
# }
|
|
||||||
# )
|
|
||||||
# db.commit()
|
|
||||||
|
|
||||||
# return {
|
|
||||||
# "message": f"Check-in successful for {encoding.name}",
|
|
||||||
# "checking": True,
|
|
||||||
# "status": status,
|
|
||||||
# "data": {
|
|
||||||
# "id": encoding.id,
|
|
||||||
# "name": encoding.name,
|
|
||||||
# "email": encoding.email,
|
|
||||||
# "avatar": encoding.avatar,
|
|
||||||
# "camera_id": camera_id,
|
|
||||||
# "time": now.isoformat()
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
|
|
||||||
# return {"message": "No match found."}
|
|
||||||
|
|
||||||
@app.post("/checkin")
|
@app.post("/checkin")
|
||||||
async def checkin(background_tasks: BackgroundTasks, file: UploadFile = File(...), camera_id: str = Form("cam1"), db: Session = Depends(get_db)):
|
async def checkin(background_tasks: BackgroundTasks, file: UploadFile = File(...), camera_id: str = Form("cam1"), db: Session = Depends(get_db)):
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -431,7 +322,7 @@ async def checkin(background_tasks: BackgroundTasks, file: UploadFile = File(...
|
||||||
student_names.get(best_student),
|
student_names.get(best_student),
|
||||||
status
|
status
|
||||||
)
|
)
|
||||||
|
|
||||||
db.execute(
|
db.execute(
|
||||||
text("""
|
text("""
|
||||||
INSERT INTO checkin_logs (student_id, time, camera_id, status)
|
INSERT INTO checkin_logs (student_id, time, camera_id, status)
|
||||||
|
|
@ -445,7 +336,25 @@ async def checkin(background_tasks: BackgroundTasks, file: UploadFile = File(...
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
return {"message": f"Check-in successful for {student_names.get(best_student)} (dist={best_distance:.4f})", "status": True, "status_type":status}
|
|
||||||
|
|
||||||
|
student = db.execute(
|
||||||
|
text("""
|
||||||
|
SELECT id, name, email
|
||||||
|
FROM students
|
||||||
|
WHERE id = :id
|
||||||
|
"""),
|
||||||
|
{"id": best_student}
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
user_data = {
|
||||||
|
"id": student.id,
|
||||||
|
"name": student.name,
|
||||||
|
"email": student.email,
|
||||||
|
} if student else None
|
||||||
|
|
||||||
|
|
||||||
|
return {"message": f"Check-in successful for {student_names.get(best_student)} (dist={best_distance:.4f})", "status": True, "status_type":status, "data": user_data}
|
||||||
|
|
||||||
# Nếu không thỏa threshold/rule thì trả no match (và log lý do)
|
# Nếu không thỏa threshold/rule thì trả no match (và log lý do)
|
||||||
reasons = []
|
reasons = []
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -8,7 +8,7 @@
|
||||||
<script
|
<script
|
||||||
type="module"
|
type="module"
|
||||||
crossorigin
|
crossorigin
|
||||||
src="/camera/static/assets/index-BtpLNeIZ.js"
|
src="/camera/static/assets/index-JE9ABJ5_.js"
|
||||||
></script>
|
></script>
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue