saimj7 / People-Counting-in-Real-Time

People Counting in Real-Time with an IP camera.
MIT License
528 stars 263 forks source link

Save Log per hour #59

Closed anandabayu closed 1 year ago

anandabayu commented 1 year ago

Hi, @saimj7 how can I save the log to be in 1-hourly and daily format? so the 1 log file will contain 24 row

saimj7 commented 1 year ago

Hi, I guess you could pause the program every hour with time.sleep(3600) to save the data at regular intervals

and if you need to save the rows hourly, append the data with with open('Log.csv', 'a', newline='') as myfile: instead of overwriting it (as it is now)

make sure to check if the file consists of header rows if myfile.tell() == 0:, as it is redundant to write them every hour

datetimee = [datetime.datetime.now()]
d = [datetimee, move_in, move_out, total]
export_data = zip_longest(*d, fillvalue='')
with open('Log.csv', 'a', newline='') as myfile:
    wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
    if myfile.tell() == 0:
        wr.writerow(("End Time", "In", "Out", "Total Inside"))
    wr.writerows(export_data)
time.sleep(3600)