From 23a8321e2d5f9a900912f635efde0320b2c30a43 Mon Sep 17 00:00:00 2001 From: andrzej Date: Sat, 9 May 2020 14:01:48 +0200 Subject: [PATCH] =?UTF-8?q?Dodanie=20rodzaju=20towaru=20w=20paczce,=20oraz?= =?UTF-8?q?=20temperatury=20i=20wilgotno=C5=9Bci=20na=20polu=20w=20magazyn?= =?UTF-8?q?ie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent.py | 1 + attributes.py | 2 +- products_types.py | 33 +++++++++++++++++++++++++++++++ warehouse.py | 50 ++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 products_types.py diff --git a/agent.py b/agent.py index cb08386..2617ebb 100644 --- a/agent.py +++ b/agent.py @@ -236,3 +236,4 @@ class Agent: pack.lays_on_field.capacity -= pack.size pack.status = PackStatus.STORED self.warehouse.packages.append(pack) + print(tile.air_temperature, tile.humidity) diff --git a/attributes.py b/attributes.py index 3f959e6..30080af 100644 --- a/attributes.py +++ b/attributes.py @@ -44,4 +44,4 @@ DIRECTION_ANGLES = { "up": -90, "right": 180, "down": 90 -} +} \ No newline at end of file diff --git a/products_types.py b/products_types.py new file mode 100644 index 0000000..9fe1a2a --- /dev/null +++ b/products_types.py @@ -0,0 +1,33 @@ +PRODUCT_TYPES = { + "freezed": [ + "frozen food", + "seeds", + "frozen liquids" + ], + "fragile": [ + "glass", + "porcelain", + "vials", + "phials", + "plate", + ], + "keep_dry": [ + "electronic", + "drugs", + "books", + "clothes", + "cardboard" + ], + "normal": [ + "cosmetics", + "wood", + "metal", + "plastic" + ], + "flammable": [ + "gasoline", + "lacquer", + "ammo" + ] + +} \ No newline at end of file diff --git a/warehouse.py b/warehouse.py index e3de507..d39cea1 100644 --- a/warehouse.py +++ b/warehouse.py @@ -1,4 +1,5 @@ from attributes import PackStatus +from products_types import PRODUCT_TYPES import random import queue from collections import namedtuple @@ -20,6 +21,8 @@ class Pack: def __init__(self, size=5, categ='general', lays_on_field=None): self.size = size self.category = categ + self.products_inside = self.set_products_inside() + assert isinstance(lays_on_field, Tile), AssertionError("Attribute lays_on_field must be a Tile object! You know, package cannot lay in void :)") self.lays_on_field = lays_on_field self.status = self.set_status() @@ -35,6 +38,26 @@ class Pack: status = PackStatus.STORED return status + def set_products_inside(self): + seed = random.random() + products_category = None + if seed < 0.6: + products_category = "normal" + elif 0.6 <= seed < 0.75: + products_category = "keep_dry" + elif 0.75 <= seed < 0.9: + products_category = "fragile" + elif 0.9 <= seed < 0.98: + products_category = "freezed" + elif 0.96 <= seed <= 1.0: + products_category = "flammable" + + products_in_category = PRODUCT_TYPES.get(products_category, ["food"]) + product_inside = random.choice(products_in_category) + print(product_inside) + return product_inside + + CATEGORY = { 'floor': CategoryData('Floor', True, False), #lava 'rack': CategoryData('Rack', False, True), @@ -53,7 +76,10 @@ class Warehouse: self.no_of_packages = no_of_packages self.generate_racks() self.open_isolated_areas() + self.set_temperature(20, 30) + self.set_humidity() self.create_fridge(10) + print([row[0].air_temperature for row in self.tiles]) self.packages = self.place_packages(no_of_packages) self.tiles[1][1] = Tile('floor', 1, 1) def __str__(self): @@ -97,6 +123,21 @@ class Warehouse: node_y = next_node.y_position self.tiles[node_x][node_y] = Tile('rack', node_x, node_y) + def set_temperature(self, min_temperature=20, max_temperature=30): + for num, row in enumerate(self.tiles): + row_temperature = min_temperature + round(num/2) + for cell in row: + cell.air_temperature = row_temperature + + def set_humidity(self, min_humidity=0.2, max_humidity=0.7): + current_humidity = min_humidity + for y in range(self.height): + current_humidity += (0.1/4) + for x in range(self.width): + self.tiles[x][y].humidity = round(current_humidity, 1) + # print(round(current_humidity, 1)) + + def create_fridge(self, size): x_corner = random.choice(['left', 'right']) y_corner = random.choice(['top', 'bottom']) @@ -124,9 +165,9 @@ class Warehouse: for num, row in enumerate(rows, start_x): for index, tile in enumerate(row[start_y:end_y], start_y): if self.tiles[num][index].category.name == "Floor": - self.tiles[num][index] = Tile('fridge_floor', num, index) + self.tiles[num][index] = Tile('fridge_floor', num, index, temperature=-5) else: - self.tiles[num][index] = Tile('fridge', num, index, capacity=random.randrange(10, 12)) + self.tiles[num][index] = Tile('fridge', num, index, capacity=random.randrange(10, 12), temperature=-15) def get_not_rack_nodes(self, node_x, node_y): adjacent_tiles = self.get_adjacent_tiles(node_x, node_y) @@ -181,6 +222,7 @@ class Warehouse: self.tiles[bottom_left.x][bottom_left.y] ] return diagonals + def get_all_racks(self): """:return list of Tile objects""" racks = [] @@ -247,10 +289,12 @@ class Warehouse: return wall class Tile: - def __init__(self, category, x_position, y_position, capacity=10): + def __init__(self, category, x_position, y_position, capacity=10, temperature: int=24, humidity: float=0.3): self.category = CATEGORY.get(category, CATEGORY['floor']) self.x_position = x_position self.y_position = y_position + self.air_temperature = temperature + self.humidity = humidity self.capacity = capacity