我正在使用 Pyqt5 制作人脸考勤系统,即使该人已登录,该系统也会多次写入考勤

  • 本文关键字:系统 登录 制作人 Pyqt5 考勤系统 python
  • 更新时间 :
  • 英文 :


我正在Youtube上学习制作人脸识别考勤系统的教程,该系统将姓名和时间写入csv文件,当我尝试运行时,它会在考勤表上多次写入人员姓名。我试着使用逻辑来避免多次写名字,但现在即使我重新开始,它也不会多次写人名。相机有点慢,可能是电脑还是代码。

def face_rec_(self, frame, encode_list_known, class_names):
def mark_attendance(ID):
"""
:taking attendance
"""
self.already_in_file = set()
date_time_string = datetime.datetime.now().strftime("%y/%m/%d, %H:%M")
with open('Attendance1.csv',"r") as f:
for line in f:
self.already_in_file.add(line.split(",")[0])
if ID and date_time_string not in self.already_in_file:
with open ("Attendance1.csv", "a") as f:
f.writelines(f'n{ID},{date_time_string}')

我建议修改if块中的date_time_string——在我看来这就是问题所在。if块检查文件中是否有确切的时间,但时间会随着时间的推移而变化,正如我们所知。

让我也把它放在代码中,这样我的答案就不会太短了!

def face_rec_(self, frame, encode_list_known, class_names):
def mark_attendance(ID):
"""
:taking attendance
"""
self.already_in_file = set()
#this at a minimum, but I believe it'll make the same mistake next hour
date_time_string = datetime.datetime.now().strftime("%y/%m/%d, %H")
#alternatively, use the one below
#date_time_string = datetime.datetime.now().strftime("%y/%m/%d")
with open('Attendance1.csv',"r") as f:
for line in f:
self.already_in_file.add(line.split(",")[0])
if ID and date_time_string not in self.already_in_file:
with open ("Attendance1.csv", "a") as f:
f.writelines(f'n{ID},{date_time_string}')

最新更新