Makeroom wizard #27

Merged
stranck merged 15 commits from drew-dev into stranck-dev 2024-05-20 10:32:09 +00:00
2 changed files with 30 additions and 3 deletions
Showing only changes of commit f3a76b6e93 - Show all commits

View File

@ -128,19 +128,34 @@ async def room_wizard(request, order:Order):
'room_type': 5,
'room_name': 'generated 1',
'to_add': ['B', 'a', 'c']
}
},
'rooms_to_delete': []
}
result_map = {}
# Get room quotas
room_quota_map = {}
room_quota_overflow = {}
for key, value in ITEM_VARIATIONS_MAP['bed_in_room'].items():
capacity = ROOM_CAPACITY_MAP[key] if key in ROOM_CAPACITY_MAP else 1
room_quota_map[value] = math.ceil((len(list(filter(lambda y: y.bed_in_room == value, orders.values())))) / capacity)
current_quota = len(list(filter(lambda y: y.bed_in_room == value and y.room_owner == True, orders.values())))
room_quota_overflow[value] = current_quota - (room_quota_map[value] if value in room_quota_map else 0)
print('RMQ = ')
print(room_quota_map)
# Init rooms to remove
result_map["void"] = []
# Dismember rooms that are over quota
for room_type, overflow_qty in {key:value for key,value in room_quota_overflow.items() if value > 0}.items():
sorted_rooms = sorted(incomplete_orders.values(), key=lambda r: len(r.room_members))
for room_to_remove in sorted_rooms[:overflow_qty]:
# Room codes to remove
result_map["void"].append(room_to_remove.code)
# Move room members to the roomless list
for member_code in room_to_remove.room_members:
roomless_orders[member_code] = all_orders[member_code]
del incomplete_orders[room_to_remove.code]
# Fill already existing rooms
for room_order in incomplete_orders.items():

12
ext.py
View File

@ -248,6 +248,18 @@ class Order:
def get_language(self):
return self.country.lower() if self.country.lower() in AVAILABLE_LOCALES else 'en'
def __str__(self):
to_return = f"{'Room' if self.room_owner else 'Order'} {self.code}"
if self.room_owner == True:
to_return = f"{to_return} [ members = {self.room_members} ]"
return to_return
def __repr__(self):
to_return = f"{'Room' if self.room_owner == True else 'Order'} {self.code}"
if self.room_owner == True:
to_return = f"{to_return} [ members = {self.room_members} ]"
return to_return
@dataclass
class Quotas:
def __init__(self, data):