DOCUMENTACIÓN¶
LOADING INVENTORY FROM CSV¶
-
inventory_from_txt.load_inventory(file: str, sep=',') → dict¶ Read a file separated by , into a dictionary
- Parameters
file (str) – string path
sep (str) – delimiter to use.
- Returns
- Return type
dictionary which contains an inventory
Examples
>>> almacen = load_inventory('inventarioAlmacen.txt') >>> print(almacen) {'001': [100, 25, 70, '001_AA', 'Yogures de fresa'], '002': .......
UPDATING SALES¶
-
A.sells(inventory: dict, file: str)¶ Procedure which reads a file containing a supermarket selling log, then updates a dictionary which contains supermarket stock
- Parameters
inventory – dict which contains information about each product
file – string path
Example
>>> almacen = load_inventory('inventarioAlmacen.txt') >>> sells(almacen, 'ventasCajas.txt') Venta : 20-oct-2006 12:25 001 34 Antes de : 100 25 70 001_AA Yogures de fresa Después de : 100 25 36 001_AA Yogures de fresa ======>Necesidad de reponer<========
SALES AND RESTOCKS¶
-
AB.sells_and_restocks(inventory, file)¶ Procedure which read every line of a given file, in the follawing format: [VENTA | REPO] [DAY-MONTH(e.g. ‘OCT’, ‘ENE’)] [TIME(24H)] [PRODUCT CODE] [PRODUCT UNITS] Then, updates current stock in the given inventory
- Parameters
inventory – dictionary which contains products which we want to update
file – string path
WAREHOUSE CLASS¶
-
class
class_warehouse.Warehouse¶ Manages a supermarket inventory, allowing to operate with supermarket stock either adding up or subtracting, you are able to load your dictionary from a external file. Attributes are show below(products and _copy_products)
- products :
A dictionary whose keys are the product code and its elements are the maximum and minimum number of units in our shelves, our actual stock for each product, their locations in our supermarket and a brief description.
- _copy_products :
In order to implement a Context Manager we have deepcopied our dictionary products, this backup will be helpful if we want to undo an operation.
-
__enter__()¶ Backing up our main dictionary
-
__exit__(exc_type, exc_val, exc_tb)¶ When exc_type is not None undo the operation deepcopying _copy_products
- Parameters
exc_type – exception type
exc_val – exception value
exc_tb – traceback
-
__getitem__(code: str) → list¶ This magic method allows us to index our dict without write Warehouse.products[] using instead Warehouse[]
- Parameters
code – product code which is a dict key
Example
>>> amazon = Warehouse() >>> amazon.add_products('001', 4, 1, 2, 'SOUTH', 'Rice') >>> amazon['001'] [4, 1, 2, 'SOUTH', 'Rice'] >>> amazon.products['001'] [4, 1, 2, 'SOUTH', 'Rice']
-
__init__()¶ Constructor. Initialize our products dictionary
-
__weakref__¶ list of weak references to the object (if defined)
-
add_products(code, maximum, minimum, stock, location, description)¶ This method add a product to our dictionary.
- Parameters
code – product code
maximum – maximum allowed in supermarket shelves
minimum – minimum allowed in supermarket shelves
stock – actual stock in shelves
location – location in supermarket
description – briefly descriptor
-
load_from_txt(file: str)¶ This method loads products from a external file into a dictionary
- Parameters
file – file path where our inventory is located
-
update_inventory_from_txt(file)¶ Given a file this method read every line, differencing between sells and restocks, updating the stock in a given inventory.
- Parameters
file – path to a file containing a supermarket transaction log
-
update_stock(code: str, amount: int, sw: bool) → ValueError¶ This method updates the units of a given product either adding up or subtracting
- Parameters
code – Id of product
amount – units of product, when is >0 is a restock else is a sell
sw – 1 when restocking, 0 when selling
Return –
------- – A str containing the error description
SIMULATION¶
-
simulacion.supermarket_log(starting_time, finish_time, warehouse, file)¶ Simulating one day of restock and sells in a supermarket, the events in the supermarket follow an exponential distribution with an average time between events of 5 minutes. Each time that an event occur, the next event (restock or sell) is chosen with a binomial distribution where a sell has probability 0.65 and a restock 0.35. When a client buy a product, that product is selected randomly uniformly, whereas the quantity is chosen from a binomial with n=(max quantity of the product chosen) and p=0.15 We are making one restock at once, each time that a restock is made the product selected is randomly uniformly chosen, meanwhile the quantity of the product to restock is chosen from a binomial where n=(max quantity allowed in shelves), p=0.65
- Parameters
starting_time – supermarket opening time
finish_time – supermarket closing time
warehouse – class Warehouse where our products catalog is saved, we need this information to know products and their codes in our supermarket
file – file path in which save our daily log