SI_InteligentnyWozekWidlowy/visualization/DisplayOrderList.py

56 lines
1.5 KiB
Python
Raw Normal View History

2022-05-25 23:51:29 +02:00
from collections import Counter
from typing import List
from mesa.visualization.modules import TextElement
from data.Order import Order
class DisplayOrderList(TextElement):
def __init__(self, attr_name):
'''
Create a new text attribute element.
Args:
attr_name: The name of the attribute to extract from the model.
Example return: "happy: 10"
'''
self.attr_name = attr_name
def render(self, model):
val = getattr(model, self.attr_name)
2022-06-10 01:16:43 +02:00
res = ""
if val is not None:
orderList: List[Order] = val
2022-05-25 23:51:29 +02:00
2022-06-10 01:16:43 +02:00
res = self.attr_name + ": <ol>"
2022-05-25 23:51:29 +02:00
2022-06-10 01:16:43 +02:00
for o in orderList:
if o is None:
continue
2022-05-25 23:51:29 +02:00
2022-06-10 01:16:43 +02:00
itemList = map(lambda x: x.real_type, o.items)
itemCounter = Counter(itemList)
2022-05-25 23:51:29 +02:00
2022-06-10 01:16:43 +02:00
item_str = "<ul>"
for e in itemCounter:
key = e
val = itemCounter[key]
2022-05-25 23:51:29 +02:00
2022-06-10 01:16:43 +02:00
# key_str = ""
# if key == ItemType.DOOR:
# key_str = "Door"
# elif key == ItemType.SHELF:
# key_str = "Shelf"
2022-05-25 23:51:29 +02:00
2022-06-10 01:16:43 +02:00
item_str += f"<li>{str(key)}:{str(val)}</li>"
2022-05-25 23:51:29 +02:00
2022-06-10 01:16:43 +02:00
item_str += "</ul>"
2022-05-25 23:51:29 +02:00
2022-06-10 01:16:43 +02:00
res += f"<li> items: {item_str} priority: {o.priority} <br> Client: {vars(o.client_params)} </li>"
2022-05-25 23:51:29 +02:00
2022-06-10 01:16:43 +02:00
res += "</ol>"
2022-05-25 23:51:29 +02:00
return res