def clear_cache(config): """ Clear Intervals which have expired. Usage:\n hotel clear-cache\n Arguments:\n None\n Description:\n This commmand removes intervals where intv_end < current_date.\n Run if reserve_dates() is slow. """ helpers.handle_session() df = config.intervals.stack().swaplevel(0, 1).reset_index() df.columns = ["room", "start", "end"] curr_date = datetime.date(datetime.now()) def clear(x): if x["end"].date() < curr_date: return pd.Series(data=[None, None, None], index=x.index) else: return x config.intervals = df.apply(clear, axis=1).dropna()
def get_client_id(config, name, email): """ Print client ID. Usage:\n hotel get-client-id name email\n Arguments:\n name is type STRING\n email is type STRING\n Description:\n This commmand prints the client ID from client_supp.csv """ helpers.handle_session() id_list = helpers.unique_client(config.client_supp, name, email) if id_list.empty: click.echo( f"The name: {name} and email: {email} does not match any known client ID" ) else: client_id = int(id_list.squeeze()) click.echo(f"The client ID for {name} is {client_id}")
def delete_reservation(config, client_id): """ Undo reserve-dates command. Usage:\n hotel delete-reservation client_id\n Arguments:\n client_id is type INT\n Description:\n This commmand removes reservation in rooms/reservations/{best_room}.csv for client_id, state = 3\n Removes and rejoins old interverl in rooms/interval/{best_rom}.csv\n Updates client_list.csv with new informtion """ helpers.handle_session() if client_id in config.client_list.index: if config.client_list.loc[client_id, "state"] == 2: hotel_path = helpers.get_hotel_path() full_path = os.path.join(config.cwd_path, hotel_path) res_start = config.client_list.loc[client_id, "start"] res_end = config.client_list.loc[client_id, "end"] room_number = config.client_list.loc[client_id, "reserved_room"] helpers.remove_reservation_client_list(config.client_list, client_id) helpers.overwrite_client_list(config.client_list, full_path) helpers.remove_reservations(config.reservations, res_start) helpers.overwrite_reservations(config.reservations, config.cwd_path, hotel_path, room_number) helpers.remove_intervals(config.intervals, res_start, res_end, room_number) helpers.overwrite_intervals(config.intervals, config.cwd_path, hotel_path, room_number) click.echo("The reservation has been deleted.") else: click.echo( f"The client ID {client_id} does not have a reservation.") else: click.echo( f"The client ID {client_id} does not exist. Please use a valid client ID" )
def check_in(config, client_id): """ Update client list after check-in. Usage:\n hotel check-in client_id\n Arguments:\n client_id is type INT\n Description:\n This commmand pops reservation from reservation in rooms/reservations/{best_room}.csv\n Popped reservation is updated in client_list.csv\n State = 1 """ helpers.handle_session() if client_id in config.client_list.index: if config.client_list.loc[client_id, "state"] == 2: hotel_path = helpers.get_hotel_path() full_path = os.path.join(config.cwd_path, hotel_path) res_start = config.client_list.loc[client_id, "start"] room_number = config.client_list.loc[client_id, "reserved_room"] helpers.checkin_client_list(config.client_list, client_id) helpers.overwrite_client_list(config.client_list, full_path) helpers.pop_reservation(config.reservations, res_start, room_number) helpers.overwrite_reservations(config.reservations, config.cwd_path, hotel_path, room_number) click.echo("You are now checked in!") else: click.echo( f"The client ID {client_id} does not have a reservation. Please first make a reservation" ) else: click.echo( f"The client ID {client_id} does not exist. Please use a valid client ID" )
def get_all_clients(config): """ Print all clients in client_list. Usage:\n hotel get-all-clients\n Arguments:\n None\n Description:\n This commmand prints the info of all clients from client_list.csv\n """ helpers.handle_session() with pd.option_context("display.max_rows", None, "display.max_columns", None): click.echo(config.client_list)
def quit(): """ Quit current session. Usage:\n hotel quit\n Arguments:\n None\n Description:\n This commmand ends the current session.\n Moves the session.csv file to data/hotel_*/session.csv for storage """ helpers.handle_session() hotel_path = helpers.get_hotel_path() hotel = hotel_path.split("/")[1] shutil.move("session.csv", hotel_path) click.echo(f"The session for {hotel} is now closed.")
def get_some_clients(config, state): """ Print clients with state = state. Usage:\n hotel get-some-clients state\n Arguments:\n state is type INT\n Description:\n This commmand prints the info of clients (based on state values) from client_list.csv\n States:\n registered client = 1\n client with reservation = 2\n client while checked-in = 3 """ helpers.handle_session() curr_clients = config.client_list.loc[config.client_list["state"] == state] click.echo(curr_clients)
def register(config, name, email): """ Add new client information to the DB. Usage:\n hotel register name email\n Arguments:\n name is type STRING\n email is type STRING\n Description:\n This commmand adds new clients to the DB, starting state = 3\n Client_supp.csv saves new client info, assigns a client ID\n Client_list.csv uses client ID to track relevent informtion """ helpers.handle_session() id_list = helpers.unique_client(config.client_supp, name, email) if id_list.empty: hotel_path = helpers.get_hotel_path() full_path = os.path.join(config.cwd_path, hotel_path) config.client_supp = helpers.add_client_supp(config.client_supp, name, email) helpers.overwrite_client_supp(config.client_supp, full_path) config.client_list = helpers.add_client_list(config.client_list, 3, None, None, -1, None, False, -1) helpers.overwrite_client_list(config.client_list, full_path) click.echo("Registration successful!") else: click.echo( f"The a client already exists with name: {name} and email: {email}" )
def get_one_client(config, client_id): """ Print client info from a single client. Usage:\n hotel get_one_client client_id\n Arguments:\n client_id is type INT\n Description:\n This commmand prints the info of client_id from client_list.csv """ helpers.handle_session() if client_id in config.client_list.index: client_info = config.client_list.iloc[client_id] click.echo(client_info) else: click.echo( f"The client ID {client_id} does not exist. Please use a valid client ID" )
def check_out(config, client_id, paid): """ Update client list after check-out. Usage:\n hotel check-out client_id paid\n Arguments:\n client_id is type INT\n paid is stype BOOL\n Description:\n This commmand updates client_list.csv with new informtion, state = 3 """ helpers.handle_session() if client_id in config.client_list.index: if config.client_list.loc[client_id, "state"] == 1: hotel_path = helpers.get_hotel_path() full_path = os.path.join(config.cwd_path, hotel_path) helpers.checkout_client_list(config.client_list, client_id, paid) helpers.overwrite_client_list(config.client_list, full_path) click.echo("You are now checked out!") else: click.echo( f"The client ID {client_id} is not currently checked-in. Please first ensure client is checked-in" ) else: click.echo( f"The client ID {client_id} does not exist. Please use a valid client ID" )
def reserve_dates(config, client_id, room_type, start, end): """ Find ideal rooms based on criteria given. Usage:\n hotel reserve-dates client_id room_type start_date end_date\n Arguments:\n client_id is type INT\n room_type is type INT\n start_date is format %Y-%m-%d\n end_date is format %Y-%m-%d\n Description:\n This commmand returns a list of rooms that match the criteria given\n Rooms are ordered by the minimal disruption of free intervals\n Creates new reservation in rooms/reservations/{best_room}.csv\n Splits and adds new interverl in rooms/interval/{best_rom}.csv\n Updates client_list.csv with new informtion, reserved state = 2 """ helpers.handle_session() if client_id in config.client_list.index: if config.client_list.loc[client_id, "state"] == 3: hotel_path = helpers.get_hotel_path() full_path = os.path.join(config.cwd_path, hotel_path) room_matching_type = helpers.get_room_of_type( config.hotel, room_type) df_intervals = config.intervals[room_matching_type].dropna( axis=0, how="all") available_rooms = helpers.get_room_number_optimized( df_intervals, start, end) delta = end - start if available_rooms.empty: click.echo("Sorry! There are no rooms available!") else: best_room = available_rooms["room"][0] payment = helpers.get_payment(config.hotel, best_room) payment_due = delta.days * payment paid = False helpers.add_reservation_client_list( config.client_list, client_id, 2, start, end, best_room, payment_due, paid, ) helpers.overwrite_client_list(config.client_list, full_path) helpers.add_reservations(config.reservations, best_room, client_id, start) helpers.overwrite_reservations(config.reservations, config.cwd_path, hotel_path, best_room) helpers.add_intervals(config.intervals, best_room, start, end, hotel_path) helpers.overwrite_intervals(config.intervals, config.cwd_path, hotel_path, best_room) click.echo("Reservation successful!") else: click.echo( f"The client ID {client_id} is currently unable to accept a new reservation. Please verify the current client state" ) else: click.echo( f"The client ID {client_id} does not exist. Please use a valid client ID" )