def remove_process_for_beer(gyle_no: int, beer_name: str, quantity: int):
    """
    This function allow the process to remove the process to the next
     state.
    :param gyle_no: an integer of the batch number.
    :param beer_name: a string containing the name of the beer.
    :param quantity: an integer representing the quantity of the beer.
    """
    errorLogger.info("Removing a given beer in the brewing process.")
    beer_obj = find_process_for_beer(gyle_no, beer_name, quantity)
    if beer_obj:
        beers_producer_queue.remove(beer_obj)
        eventLogger.critical("@state : @%s", store_beer_process_data())
示例#2
0
def update_recommended_sales(recommended_sales: dict, beer_name: str,
                             quantity: int):
    """
    Updating recommended sales dictionary.
    :param recommended_sales: a dictionary of the recommended sales.
    :param beer_name: a string representing the name of the beer.
    :param quantity: an integer of the beer quantity.
    """
    errorLogger.info("Updating recommended sales dictionary.")
    recommended_sales.update(
        {beer_name: (recommended_sales[beer_name] - quantity)})
    if recommended_sales[beer_name] <= 0:
        recommended_sales.update({beer_name: 0})
    eventLogger.critical("@recommended : @%s", recommended_sales)
def move_process_to_next_state(gyle_no: int, beer_name: str, quantity: int):
    """
    This function allow the process to move the process to the next
     state.
    :param gyle_no: an integer of the batch number.
    :param beer_name: a string containing the name of the beer.
    :param quantity: an integer representing the quantity of the beer.
    """
    errorLogger.info("Moving a given beer in the brewing process to "
                     "the next stage.")
    beer_obj = find_process_for_beer(gyle_no, beer_name, quantity)
    if beer_obj:
        beer_obj.set_move_next()
        time.sleep(0.2)
        eventLogger.critical("@state : @%s", store_beer_process_data())
def update_tank_used_capacity(tank_name: str, volume: int):
    """
    This method updates the used_capacity in the TANKS dictionary.
    :param tank_name: a string containing the name of the tank.
    :param volume: an integer of the tank's volume.
    """
    errorLogger.info("Updating the used capacity in the TANKS " "dictionary.")
    TANKS.update({
        tank_name: {
            "volume": TANKS[tank_name]["volume"],
            "capability": TANKS[tank_name]["capability"],
            "used_capacity": volume
        }
    })
    eventLogger.critical("@tanks : @%s", TANKS)
def release_tank(tank: str):
    """
    This allow to release tank.
    :param tank: a string representing the tank's name.
    :return: boolean
    """
    errorLogger.info("Releasing a tank.")
    TANKS.update({
        tank: {
            "volume": TANKS[tank]["volume"],
            "capability": TANKS[tank]["capability"],
            "used_capacity": 0
        }
    })
    eventLogger.critical("@tanks : @%s", TANKS)
    return True
def update_beer_stock(beer_name: str, quantity: int):
    """
    This method updates the current beer stock.
    :param beer_name: a string of the beer name.
    :param quantity: an integer representing the quantity of beer.
    :return:
    """
    errorLogger.info("Updating the beer stock.")
    temp = 0
    try:
        if beer_stock[beer_name]:
            temp = beer_stock[beer_name] + quantity
    except:
        temp = quantity
    beer_stock.update({beer_name: temp})
    eventLogger.critical("@stock : @%s", beer_stock)
def create_process_for_beer(gyle_no: int, beer_name: str, quantity: int):
    """
    This create brew process for a beer.
    :param gyle_no: an integer showing the batch number.
    :param beer_name: a string representing the name of the beer.
    :param quantity: an integer of the beer quantity.
    """
    errorLogger.info("Creating a brewing process for a given batch of "
                     "beer.")
    if not find_process_for_beer(gyle_no, beer_name, quantity):
        with lock:
            beers_producer_queue.append(
                BrewingProcess(gyle_no, beer_name, quantity, {}, False,
                               "start", "start"))
            eventLogger.critical("@state : @%s", store_beer_process_data())
    else:
        errorLogger.warning("Beer process already exists")