Simulator¶
The
simulatormodule provides a simple simulator simulating the behavior of the mechanics behind the cocktail making machine.It offers the simulation of the following components: - The pumping of non alcoholic and alcoholic liquids - The processing of non liquid ingredients - The mixing of the ingredients
The figure below shows the high-level architecture of the
simulatormodule: The simulator just simulates the consume of different ingredients and the mixing of them. It does not have any physical components.![]()
The
simulatorsupports a RESTful API implemented using Flask. See below for detailed documentation of its API endpoints and functionality.API Endpoints:
Pump Liquids:
URL:
/pump_liquidMethod:
POSTDescription: Simulates pumping alcoholic and non alcoholic liquids based on the given amount and type defined by each recipe.
Request Fields:
When sending form-encoded data:
liquor: A JSON-encoded array containing liquor items with their names and amounts in grams.
non_alcohol: A JSON-encoded array containing non-alcohol items with their names and amounts in grams.When sending JSON data:
liquor: An array containing liquor items with their names and amounts in grams.
non_alcohol: An array containing non-alcohol items with their names and amounts in grams.Example request with JSON data:
POST /pump_liquid HTTP/1.1 Host: example.com Content-Type: application/json { "liquor": [ { "name": "Vodka", "amount_grams": 50 } ], "non_alcohol": [ { "name": "Orange Juice", "amount_grams": 100 } ] }
Success Response:
HTTP/1.1 200 OK Content-Type: application/json { "message": "Ingredients processed successfully" }
Error Response:
If the request is invalid or missing required fields:
HTTP/1.1 400 Bad Request Content-Type: application/json { "error": "Invalid request, missing 'liquor' or 'non_alcohol'" }Processing Other Ingredients:
URL:
/process_ingredientMethod:
POSTDescription: Simulates the processing of non liquid ingredients. (e.g. ice, sugar, salt, etc.)
Request Fields:
When sending form-encoded data:
other: A JSON-encoded array containing other ingredient items with their names and amounts in grams.When sending JSON data:
other: An array containing other ingredient items with their names and amounts in grams.Example request with JSON data:
POST /process_ingredient HTTP/1.1 Host: example.com Content-Type: application/json { "other": [ { "name": "Garnish", "amount_grams": 5 } ] }
Success Response:
HTTP/1.1 200 OK Content-Type: application/json { "message": "Other ingredients processed successfully" }
Error Response:
If the request is invalid or missing the ‘other’ field:
HTTP/1.1 400 Bad Request Content-Type: application/json { "error": "Invalid request, missing 'Other'" }Mix:
URL:
/mixMethod:
POSTDescription: Simulates mixing the cocktail based on the given mix technique, strength and duration defined by each cocktail recipe.
Request Fields:
When sending form-encoded data:
mix_technique: A JSON-encoded object containing the mixing technique, strength, and duration.When sending JSON data:
technique: The technique used for mixing the cocktail.
strength: The intensity of mixing.
duration: The time duration for which ingredients are to be mixed.Example request with JSON data:
POST /mix HTTP/1.1 Host: example.com Content-Type: application/json { "technique": "Shake", "strength": "Medium", "duration": "5" }
Success Response:
HTTP/1.1 200 OK Content-Type: application/json { "message": "Mixed cocktail successfully" }
Error Response:
If the request is invalid or missing required fields:
HTTP/1.1 400 Bad Request Content-Type: application/json { "error": "Invalid request, missing required mixing parameters" }Module Implementation:
- simulator.complete_order()¶
Complete the order :return: A JSON response with a message indicating the order was completed successfully
- simulator.consume(item, amount)¶
Simulate consuming an ingredient :param item: The ingredient to consume :param amount: The amount of the ingredient to consume :return: None
- simulator.mix(technique, strength, duration)¶
Simulate mixing a drink :param technique: The technique to mix the drink :param strength: The strength of the mix :param duration: The duration of the mix :return: None
- simulator.mix_ingredients()¶
Mix the ingredients for a cocktail :return: A JSON response with a message indicating the cocktail was mixed successfully
- simulator.process_ingredient()¶
Process the other ingredients for a cocktail, consuming the other ingredients :return: A JSON response with a message indicating the other ingredients were processed successfully
- simulator.pump_liquid()¶
Process the ingredients for a cocktail, consuming the liquor and non-alcohol ingredients :return: A JSON response with a message indicating the ingredients were processed successfully
- simulator.serve(drink)¶
Simulate serving a drink :param drink: The drink to serve :return: None
- simulator.serve_cocktail()¶
Serve the cocktail :return: A JSON response with a message indicating the cocktail was served successfully