简体   繁体   English

opencv 考勤系统将学生标记为存在于 csv 问题

[英]opencv attendance system mark student as present in csv problem

i have an attendee system made with opencv, it works but my problem is with mark student in csv file, the goal is to mark student only once a day我有一个用 opencv 制作的参加者系统,它可以工作,但我的问题是在 csv 文件中标记学生,目标是每天只标记学生一次

///////// after reading more about csv ive found that my logic was bad. ///////// 在阅读了有关 csv 的更多信息后,我发现我的逻辑很糟糕。

here is the latest code to solve my problem这是解决我的问题的最新代码

def markAttendance(name):
today = datetime.now().strftime("%d-%m-%Y")
if not path.exists('opencv/prezente/'+today+'.csv'):
    with open('opencv/prezente/'+today+'.csv', 'w') as file:
        file.write(f'{"nume"},{"timestamp"}')

    with open('opencv/prezente/'+today+'.csv', 'r+') as f:
        now = datetime.now().strftime("%d/%m/%Y,%H:%M")
        f.write(f'\n{name},{now}')
else:
    with open('opencv/prezente/'+today+'.csv', 'r+') as f:
        myDataList = f.readlines()
        row_count = sum(1 for row in myDataList)
        exista = []
        for line in myDataList:
            if name not in line:
                exista.append(name)
        if row_count == len(exista):
            now = datetime.now().strftime("%d/%m/%Y,%H:%M")
            f.write(f'\n{name},{now}')

so here is my markattendance function所以这是我的markattendance function

def markAttendance(name):
  with open('opencv/attendance.csv', 'r+') as f:
    myDataList = f.readlines()
    for line in myDataList:
        entry = line.split(',')
        today = datetime.now().strftime("%d/%m/%Y")
       
        if name in line and entry[1] == today:
            print(entry[1]+" ai mai fost azi " + entry[2])  
            
           
        else:
            now = datetime.now().strftime("%d/%m/%Y,%H:%M")
            # f.write(f'\n{name},{now}')
            print("ciubaca")

i have comented the line f.write because there is my problem, from my logic that part should not execute if the condition is true but instead this is what i get in console我已经评论了 f.write 行,因为这是我的问题,从我的逻辑来看,如果条件为真,那部分不应该执行,但这是我在控制台中得到的

在此处输入图像描述

What exactly is the problem you want to fix?您要解决的具体问题是什么? My hunch is that you need an if elif statement instead of if else because right now the else statement could be triggering either if the name is not in the line or if entry[1] is not today:我的预感是你需要一个 if elif 语句而不是 if else 因为现在 else 语句可能会在名称不在行中或 entry[1] 不在今天触发时触发:

def markAttendance(name):
    with open('opencv/attendance.csv', 'r+') as f:
        myDataList = f.readlines()
        for line in myDataList:
            entry = line.split(',')
            today = datetime.now().strftime("%d/%m/%Y")
   
            if name in line and entry[1] == today:
                print(entry[1]+" ai mai fost azi " + entry[2])  
        
            elif name not in line and entry[1] == today:
                now = datetime.now().strftime("%d/%m/%Y,%H:%M")
                # f.write(f'\n{name},{now}')
                print("ciubaca")

But I'd need more details on the problem to be sure.但我需要更多关于这个问题的细节来确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM