def show_reports(date: str, location: str): location = None if location == "" else location hours = data.config['settings']['hours'] table = {"ID": [], "Name": [], "Classroom": []} for i in range(len(hours)): table["#" + str(i + 1)] = [] filters = {} if location is not None: filters["classroom"] = location for student in database.students_col.find(filters, {"face": False}): table["ID"].append(student['id']) table["Name"].append(student['name']) table["Classroom"].append(student["classroom"]) for i in range(len(hours)): hour = hours[i] start, finish = hour.split() time_start = datetime.datetime.strptime(f"{date} {start}", "%Y_%m_%d %H:%M") time_start = data.tz.normalize( data.tz.localize(time_start)).astimezone(pytz.utc) time_finish = datetime.datetime.strptime(f"{date} {finish}", "%Y_%m_%d %H:%M") time_finish = data.tz.normalize( data.tz.localize(time_finish)).astimezone(pytz.utc) query = { 'student-id': student['_id'], 'timestamp': { "$gte": time_start, "$lt": time_finish } } count = database.reports_col.count_documents(query) table["#" + str(i + 1)].append(count) print_table(table)
def do_hours(arg): """Show class hours. Usage: hours (Show class hours.)""" if arg == "set": print("Not implemented.") elif arg == "": hours = data.config["settings"]["hours"] table = {"Class": [], "Start": [], "Finish": []} for i in range(len(hours)): start, finish = hours[i].split() table["Class"].append("#" + str(i + 1)) table["Start"].append(start) table["Finish"].append(finish) print_table(table) else: print("Please supply arguments.")
def do_students(arg): """Show or add new students. Usage: students (Show all students.) Usage: students <classroom> (Show all students. Filter students by their classrooms.) Usage: students add <camera-id> (Add a new student to the database.)""" if len(arg.split()) == 2 and arg.split()[0] == 'add': commands.add_new_student(arg.split()[1]) else: table = {"ID": [], "Name": [], "Classroom": []} filters = {'classroom': arg} if arg == "": filters = {} for student in database.students_col.find(filter=filters, projection={"face": False}): table["ID"].append(student["id"]) table["Name"].append(student["name"]) table["Classroom"].append(student["classroom"]) print_table(table)
def show_cameras(): res = connection.get_cameras() if len(res["pi-id"]) == 0: print("No cameras detected.") else: print_table(res)
def do_cameras(arg): """Show a list of connected cameras. Usage: cameras (Show a list of connected cameras.)""" cameras = connection.get_cameras() table = {"ID": cameras['pi-id'], "Location": cameras["location"]} print_table(table)