From e1f08f4c2322a5458cd88e2e259fc80fb03be127 Mon Sep 17 00:00:00 2001 From: David Rodenkirchen Date: Wed, 4 Sep 2024 23:54:28 +0200 Subject: [PATCH] remove xml/svg based seating --- config/config.example.toml | 5 +- config/seating_plan.example.drawio | 256 ----- config/seating_plan_base.example.svg | 973 ------------------ .../services/ConfigurationService.py | 7 +- src/ez_lan_manager/services/SeatingService.py | 97 +- .../types/ConfigurationTypes.py | 2 +- 6 files changed, 7 insertions(+), 1333 deletions(-) delete mode 100644 config/seating_plan.example.drawio delete mode 100644 config/seating_plan_base.example.svg diff --git a/config/config.example.toml b/config/config.example.toml index 656526c..199279c 100644 --- a/config/config.example.toml +++ b/config/config.example.toml @@ -20,7 +20,10 @@ password="" [seating] - base_svg_path="" + # SeatID -> Category + A01 = "NORMAL" + A02 = "NORMAL" + C01 = "LUXUS" [tickets] [tickets."NORMAL"] diff --git a/config/seating_plan.example.drawio b/config/seating_plan.example.drawio deleted file mode 100644 index 00d993c..0000000 --- a/config/seating_plan.example.drawio +++ /dev/null @@ -1,256 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/seating_plan_base.example.svg b/config/seating_plan_base.example.svg deleted file mode 100644 index 2a5410f..0000000 --- a/config/seating_plan_base.example.svg +++ /dev/null @@ -1,973 +0,0 @@ - - - - - - - - -
-
-
- - Bürgerhaus Bottenhorn - -
-
-
-
- - Bürgerhaus Bottenhorn - -
-
- - - - - - - - - - - - - -
-
-
- - Schlarfsaal - -
-
-
-
- - Schlarfsaal - -
-
- - - - - - - -
-
-
- - Einlass
und
Orga -
-
-
-
-
-
-
- - Einlass... - -
-
- - - - -
-
-
- - Toiletten - -
-
-
-
- - Toiletten - -
-
- - - - - - - - - - -
-
-
- - Bühne - -
-
-
-
- - Bühne - -
-
- - - - -
-
-
- B01 -
-
-
-
- - B01 - -
-
- - - - -
-
-
- B11 -
-
-
-
- - B11 - -
-
- - - - -
-
-
- B03 -
-
-
-
- - B03 - -
-
- - - - -
-
-
- B10 -
-
-
-
- - B10 - -
-
- - - - -
-
-
- B12 -
-
-
-
- - B12 - -
-
- - - - -
-
-
- B02 -
-
-
-
- - B02 - -
-
- - - - -
-
-
- C01 -
-
-
-
- - C01 - -
-
- - - - -
-
-
- C11 -
-
-
-
- - C11 - -
-
- - - - -
-
-
- C03 -
-
-
-
- - C03 - -
-
- - - - -
-
-
- C10 -
-
-
-
- - C10 - -
-
- - - - -
-
-
- C12 -
-
-
-
- - C12 - -
-
- - - - -
-
-
- C02 -
-
-
-
- - C02 - -
-
- - - - -
-
-
- E13 -
-
-
-
- - E13 - -
-
- - - - -
-
-
- E10 -
-
-
-
- - E10 - -
-
- - - - -
-
-
- E12 -
-
-
-
- - E12 - -
-
- - - - -
-
-
- E11 -
-
-
-
- - E11 - -
-
- - - - -
-
-
- E01 -
-
-
-
- - E01 - -
-
- - - - -
-
-
- E02 -
-
-
-
- - E02 - -
-
- - - - -
-
-
- E03 -
-
-
-
- - E03 - -
-
- - - - -
-
-
- E04 -
-
-
-
- - E04 - -
-
- - - - -
-
-
- D13 -
-
-
-
- - D13 - -
-
- - - - -
-
-
- D10 -
-
-
-
- - D10 - -
-
- - - - -
-
-
- D12 -
-
-
-
- - D12 - -
-
- - - - -
-
-
- D11 -
-
-
-
- - D11 - -
-
- - - - -
-
-
- D01 -
-
-
-
- - D01 - -
-
- - - - -
-
-
- D02 -
-
-
-
- - D02 - -
-
- - - - -
-
-
- D03 -
-
-
-
- - D03 - -
-
- - - - -
-
-
- D04 -
-
-
-
- - D04 - -
-
- - - - -
-
-
- A01 -
-
-
-
- - A01 - -
-
- - - - -
-
-
- A11 -
-
-
-
- - A11 - -
-
- - - - -
-
-
- A03 -
-
-
-
- - A03 - -
-
- - - - -
-
-
- A10 -
-
-
-
- - A10 - -
-
- - - - -
-
-
- A12 -
-
-
-
- - A12 - -
-
- - - - -
-
-
- A02 -
-
-
-
- - A02 - -
-
- - - - -
-
-
- - Getränke - -
-
-
-
- - Getränke - -
-
- - - - -
-
-
- Neben-Ausgang -
-
-
-
- - Neben-Ausgang - -
-
- - - - -
-
-
- Eingang -
-
-
-
- - Eingang - -
-
-
- - - - Text is not SVG - cannot display - - -
\ No newline at end of file diff --git a/src/ez_lan_manager/services/ConfigurationService.py b/src/ez_lan_manager/services/ConfigurationService.py index c648d5b..b5719c7 100644 --- a/src/ez_lan_manager/services/ConfigurationService.py +++ b/src/ez_lan_manager/services/ConfigurationService.py @@ -71,13 +71,8 @@ class ConfigurationService: def get_seating_configuration(self) -> SeatingConfiguration: try: - seating_config = self._config["seating"] - base_svg_file_path = from_root(seating_config["base_svg_path"]) - if not base_svg_file_path.exists(): - logger.fatal(f"Specified seating plan SVG file was not found at {base_svg_file_path}! Exiting...") - sys.exit(1) return SeatingConfiguration( - base_svg_path=base_svg_file_path + seats=self._config["seating"] ) except KeyError: logger.fatal("Error loading seating configuration, exiting...") diff --git a/src/ez_lan_manager/services/SeatingService.py b/src/ez_lan_manager/services/SeatingService.py index ee80b3e..d323c36 100644 --- a/src/ez_lan_manager/services/SeatingService.py +++ b/src/ez_lan_manager/services/SeatingService.py @@ -1,11 +1,6 @@ import logging -import re -from io import StringIO -from pathlib import Path from typing import Optional -from xml.etree import ElementTree -from from_root import from_root from src.ez_lan_manager.services.DatabaseService import DatabaseService from src.ez_lan_manager.services.TicketingService import TicketingService @@ -32,9 +27,6 @@ class SeatingService: self._lan_info = lan_info self._db_service = db_service self._ticketing_service = ticketing_service - self._seating_plan = StringIO() - ElementTree.parse(self._seating_configuration.base_svg_path).write(self._seating_plan, encoding="unicode") - async def get_seating(self) -> list[Seat]: return await self._db_service.get_seating_info() @@ -67,92 +59,5 @@ class SeatingService: raise SeatAlreadyTakenError await self._db_service.seat_user(seat_id, user_id) - await self.update_svg_with_seating_status() - async def generate_new_seating_table(self, seating_plan_fp: Path, no_confirm: bool = False) -> None: - if not no_confirm: - confirm = input("WARNING: THIS ACTION WILL DELETE ALL SEATING DATA! TYPE 'AGREE' TO CONTINUE: ") - if confirm != "AGREE": - logging.info("Seating table generation aborted...") - return - - et = ElementTree.parse(seating_plan_fp) - seat_ids = [] - for child in et.getroot().findall(".//mxCell"): - possible_seat_identifier = child.get("value") - try: - if re.match(r"^\w\d{1,3}$", possible_seat_identifier): - seat_ids.append((possible_seat_identifier, self._lan_info.ticket_info.default_category)) - except TypeError: - continue - - for child in et.getroot().findall(".//object"): - possible_seat_identifier = child.get("label") - try: - if re.match(r"^\w\d{1,3}$", possible_seat_identifier): - category = child.get("category") - seat_ids.append((possible_seat_identifier, category)) - except TypeError: - continue - - await self._db_service.generate_fresh_seats_table(sorted(seat_ids, key=lambda sd: sd[0])) - await self.update_svg_with_seating_status() - - async def update_svg_with_seating_status(self) -> None: - et = ElementTree.parse(self._seating_configuration.base_svg_path) - root = et.getroot() - namespace = {'svg': root.tag.split('}')[0].strip('{')} if '}' in root.tag else {} - rect_g_pairs = [] - last_rect = None - - for elem in root.iter(): - if elem.tag == f"{{{namespace.get('svg')}}}rect": - last_rect = elem - elif elem.tag == f"{{{namespace.get('svg')}}}g": - if last_rect is not None: - rect_g_pairs.append((last_rect, elem)) - last_rect = None - - all_seats = await self.get_seating() - - for rect, g in rect_g_pairs: - seat_id = self.get_seat_id_from_element(g, namespace) - if not seat_id: - continue - seat = await self.get_seat(seat_id, cached_data=all_seats) - if not seat.is_blocked and seat.user is None: - rect.set("fill", "rgb(102, 255, 51)") - elif not seat.is_blocked and seat.user is not None: - rect.set("fill", "rgb(204, 0, 0)") - else: - rect.set("fill", "rgb(190,190,190)") - # @ToDo: Set URL's properly - rect.set('onclick', f"window.open('https://httpbin.org/get?seat_id={seat_id}', '_blank')") - g.set('onclick', f"window.open('https://httpbin.org/get?seat_id={seat_id}', '_blank')") - - # Debug output - et.write(from_root("debug_seating_plan.svg")) - - self._seating_plan = StringIO() - et.write(self._seating_plan, encoding='unicode') - - - @staticmethod - def get_seat_id_from_element(element: ElementTree.Element, namespace: dict) -> Optional[str]: - seat_id = None - for child in element.iter(): - if child.tag == f"{{{namespace.get('svg')}}}text": - # Extract identifier from element - seat_id = child.text.strip() if child.text else None - elif child.tag.endswith('div') and child.text: - # Extract identifier from /
- seat_id = child.text.strip() - - if seat_id: # Break if we've already found the identifier - break - try: - if re.match(r"^\w\d{1,3}$", seat_id): - return seat_id - except TypeError: - pass - return + # ToDo: Make function that creates database table `seats` from config diff --git a/src/ez_lan_manager/types/ConfigurationTypes.py b/src/ez_lan_manager/types/ConfigurationTypes.py index d54e07d..c888180 100644 --- a/src/ez_lan_manager/types/ConfigurationTypes.py +++ b/src/ez_lan_manager/types/ConfigurationTypes.py @@ -41,4 +41,4 @@ class LanInfo: @dataclass(frozen=True) class SeatingConfiguration: - base_svg_path: Path + seats: dict[str, str]