Skip to content

Instantly share code, notes, and snippets.

@Aniruddha-Deb
Created June 30, 2022 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aniruddha-Deb/48b9ba95643b35eec3e53be7cf7f4411 to your computer and use it in GitHub Desktop.
Save Aniruddha-Deb/48b9ba95643b35eec3e53be7cf7f4411 to your computer and use it in GitHub Desktop.
Logger for queue (entry/exit time)
# Person, queue_in_time, queue_out_time, timedelta
# <int>, <time> , <time> , <timedelta>
import datetime
import curses
import pandas as pd
import os
def main(win):
win.nodelay(False)
curses.curs_set(0)
key = ""
win.clear()
userqueue = []
raw_data = []
fmt = "%Y-%m-%d %H:%M:%S"
change = False
while True:
try:
key = win.getkey()
win.clear()
change = False
if (key == 'i'):
userqueue.insert(0,datetime.datetime.now())
print("User added")
win.addstr(13,40,"User Added")
change = True
elif (key == 'o') and len(userqueue) > 0:
tout = datetime.datetime.now()
tin = userqueue.pop()
raw_data.append({
'in': tin.strftime(fmt),
'out': tout.strftime(fmt),
'delta': (tout-tin).seconds
})
win.addstr(13,40,"User Removed")
print("User removed")
change = True
elif (key == 'q'):
break
if (change):
win.addstr(15,40,"O "+"▊"*len(userqueue))
except Exception as e:
print(e)
df = pd.DataFrame(raw_data)
df.to_csv('timings.csv')
if __name__ == '__main__':
curses.wrapper(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment