valetudo-map-parser 0.1.9b21__tar.gz → 0.1.9b23__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/PKG-INFO +1 -1
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/__init__.py +1 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/config/auto_crop.py +1 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/config/colors.py +1 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/config/rand25_parser.py +1 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/config/shared.py +11 -1
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/config/types.py +11 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/config/utils.py +34 -21
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/hypfer_draw.py +1 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/hypfer_handler.py +3 -10
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/rand25_handler.py +3 -10
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/reimg_draw.py +1 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/pyproject.toml +17 -29
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/LICENSE +0 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/NOTICE.txt +0 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/README.md +0 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/config/__init__.py +0 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/config/drawable.py +0 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/map_data.py +0 -0
- {valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/py.typed +0 -0
@@ -6,6 +6,7 @@ Version: v2024.12.0
|
|
6
6
|
|
7
7
|
import asyncio
|
8
8
|
import logging
|
9
|
+
from typing import Dict, List
|
9
10
|
|
10
11
|
from .types import (
|
11
12
|
ATTR_CALIBRATION_POINTS,
|
@@ -36,8 +37,10 @@ from .types import (
|
|
36
37
|
DEFAULT_VALUES,
|
37
38
|
CameraModes,
|
38
39
|
Colors,
|
40
|
+
TrimsData,
|
39
41
|
)
|
40
42
|
|
43
|
+
|
41
44
|
_LOGGER = logging.getLogger(__name__)
|
42
45
|
|
43
46
|
|
@@ -99,8 +102,15 @@ class CameraShared:
|
|
99
102
|
self.map_pred_points = None # Predefined points data
|
100
103
|
self.map_new_path = None # New path data
|
101
104
|
self.map_old_path = None # Old path data
|
102
|
-
self.trim_crop_data = None
|
103
105
|
self.user_language = None # User language
|
106
|
+
self.trim_crop_data = None
|
107
|
+
self.trims: Dict[TrimsData, int] = {
|
108
|
+
TrimsData.TRIM_LEFT: 0,
|
109
|
+
TrimsData.TRIM_UP: 0,
|
110
|
+
TrimsData.TRIM_RIGHT: 0,
|
111
|
+
TrimsData.TRIM_DOWN: 0,
|
112
|
+
}
|
113
|
+
self.skip_room_ids: List[str] = []
|
104
114
|
|
105
115
|
def update_user_colors(self, user_colors):
|
106
116
|
"""Update the user colors."""
|
@@ -7,11 +7,13 @@ import asyncio
|
|
7
7
|
import json
|
8
8
|
import logging
|
9
9
|
from dataclasses import dataclass
|
10
|
+
from enum import Enum
|
10
11
|
from typing import Any, Dict, Tuple, Union
|
11
12
|
|
12
13
|
import numpy as np
|
13
14
|
from PIL import Image
|
14
15
|
|
16
|
+
|
15
17
|
DEFAULT_ROOMS = 1
|
16
18
|
|
17
19
|
MY_LOGGER = logging.getLogger(__name__)
|
@@ -587,3 +589,12 @@ class CameraModes:
|
|
587
589
|
CAMERA_STANDBY = "camera_standby"
|
588
590
|
CAMERA_OFF = False
|
589
591
|
CAMERA_ON = True
|
592
|
+
|
593
|
+
|
594
|
+
class TrimsData(Enum):
|
595
|
+
"""Constants for the trims data."""
|
596
|
+
|
597
|
+
TRIM_LEFT = "trim_left"
|
598
|
+
TRIM_UP = "trim_up"
|
599
|
+
TRIM_RIGHT = "trim_right"
|
600
|
+
TRIM_DOWN = "trim_down"
|
@@ -1,13 +1,15 @@
|
|
1
1
|
"""Utility code for the valetudo map parser."""
|
2
2
|
|
3
|
-
from dataclasses import dataclass
|
4
3
|
import hashlib
|
5
4
|
import json
|
5
|
+
from dataclasses import dataclass
|
6
6
|
from logging import getLogger
|
7
|
+
from typing import Callable, List, Optional
|
8
|
+
|
9
|
+
from PIL import ImageOps
|
7
10
|
|
8
|
-
from
|
11
|
+
from .types import ChargerPosition, ImageSize, NumpyArray, PilPNG, RobotPosition
|
9
12
|
|
10
|
-
from .types import ChargerPosition, ImageSize, NumpyArray, RobotPosition
|
11
13
|
|
12
14
|
_LOGGER = getLogger(__name__)
|
13
15
|
|
@@ -16,13 +18,13 @@ _LOGGER = getLogger(__name__)
|
|
16
18
|
class ResizeParams:
|
17
19
|
"""Resize the image to the given dimensions and aspect ratio."""
|
18
20
|
|
19
|
-
pil_img:
|
21
|
+
pil_img: PilPNG
|
20
22
|
width: int
|
21
23
|
height: int
|
22
|
-
aspect_ratio: str
|
23
|
-
crop_size:
|
24
|
-
is_rand: bool = False
|
25
|
-
offset_func:
|
24
|
+
aspect_ratio: str
|
25
|
+
crop_size: List[int]
|
26
|
+
is_rand: Optional[bool] = False
|
27
|
+
offset_func: Optional[Callable] = None
|
26
28
|
|
27
29
|
|
28
30
|
@dataclass
|
@@ -33,7 +35,7 @@ class OffsetParams:
|
|
33
35
|
hsf: int
|
34
36
|
width: int
|
35
37
|
height: int
|
36
|
-
rand256: bool = False
|
38
|
+
rand256: Optional[bool] = False
|
37
39
|
|
38
40
|
|
39
41
|
class BaseHandler:
|
@@ -91,7 +93,7 @@ class BaseHandler:
|
|
91
93
|
)
|
92
94
|
|
93
95
|
def _set_image_offset_ratio_1_1(
|
94
|
-
self, width: int, height: int, rand256: bool = False
|
96
|
+
self, width: int, height: int, rand256: Optional[bool] = False
|
95
97
|
) -> None:
|
96
98
|
"""Set the image offset ratio to 1:1."""
|
97
99
|
|
@@ -118,7 +120,7 @@ class BaseHandler:
|
|
118
120
|
)
|
119
121
|
|
120
122
|
def _set_image_offset_ratio_2_1(
|
121
|
-
self, width: int, height: int, rand256: bool = False
|
123
|
+
self, width: int, height: int, rand256: Optional[bool] = False
|
122
124
|
) -> None:
|
123
125
|
"""Set the image offset ratio to 2:1."""
|
124
126
|
|
@@ -146,7 +148,7 @@ class BaseHandler:
|
|
146
148
|
)
|
147
149
|
|
148
150
|
def _set_image_offset_ratio_3_2(
|
149
|
-
self, width: int, height: int, rand256: bool = False
|
151
|
+
self, width: int, height: int, rand256: Optional[bool] = False
|
150
152
|
) -> None:
|
151
153
|
"""Set the image offset ratio to 3:2."""
|
152
154
|
|
@@ -177,7 +179,7 @@ class BaseHandler:
|
|
177
179
|
)
|
178
180
|
|
179
181
|
def _set_image_offset_ratio_5_4(
|
180
|
-
self, width: int, height: int, rand256: bool = False
|
182
|
+
self, width: int, height: int, rand256: Optional[bool] = False
|
181
183
|
) -> None:
|
182
184
|
"""Set the image offset ratio to 5:4."""
|
183
185
|
|
@@ -209,7 +211,7 @@ class BaseHandler:
|
|
209
211
|
)
|
210
212
|
|
211
213
|
def _set_image_offset_ratio_9_16(
|
212
|
-
self, width: int, height: int, rand256: bool = False
|
214
|
+
self, width: int, height: int, rand256: Optional[bool] = False
|
213
215
|
) -> None:
|
214
216
|
"""Set the image offset ratio to 9:16."""
|
215
217
|
|
@@ -237,7 +239,7 @@ class BaseHandler:
|
|
237
239
|
)
|
238
240
|
|
239
241
|
def _set_image_offset_ratio_16_9(
|
240
|
-
self, width: int, height: int, rand256: bool = False
|
242
|
+
self, width: int, height: int, rand256: Optional[bool] = False
|
241
243
|
) -> None:
|
242
244
|
"""Set the image offset ratio to 16:9."""
|
243
245
|
|
@@ -298,8 +300,8 @@ class BaseHandler:
|
|
298
300
|
|
299
301
|
@staticmethod
|
300
302
|
async def calculate_array_hash(
|
301
|
-
layers: dict, active:
|
302
|
-
) -> str
|
303
|
+
layers: dict, active: Optional[List[int]]
|
304
|
+
) -> str | None:
|
303
305
|
"""Calculate the hash of the image based on layers and active zones."""
|
304
306
|
if layers and active:
|
305
307
|
data_to_hash = {
|
@@ -499,12 +501,23 @@ async def async_resize_image(params: ResizeParams):
|
|
499
501
|
str(hsf),
|
500
502
|
)
|
501
503
|
|
502
|
-
if params.crop_size is not None:
|
504
|
+
if (params.crop_size is not None) and (params.offset_func is not None):
|
503
505
|
offset = OffsetParams(wsf, hsf, new_width, new_height, params.is_rand)
|
504
|
-
params.crop_size[0], params.crop_size[1] = await params.offset_func(
|
505
|
-
offset
|
506
|
-
)
|
506
|
+
params.crop_size[0], params.crop_size[1] = await params.offset_func(offset)
|
507
507
|
|
508
508
|
return ImageOps.pad(params.pil_img, (new_width, new_height))
|
509
509
|
|
510
510
|
return ImageOps.pad(params.pil_img, (params.width, params.height))
|
511
|
+
|
512
|
+
|
513
|
+
def prepare_resize_params(handler, pil_img, rand):
|
514
|
+
"""Prepare resize parameters for image resizing."""
|
515
|
+
return ResizeParams(
|
516
|
+
pil_img=pil_img,
|
517
|
+
width=handler.shared.image_ref_width,
|
518
|
+
height=handler.shared.image_ref_height,
|
519
|
+
aspect_ratio=handler.shared.image_aspect_ratio,
|
520
|
+
crop_size=handler.crop_img_size,
|
521
|
+
offset_func=handler.async_map_coordinates_offset,
|
522
|
+
is_rand=rand,
|
523
|
+
)
|
@@ -16,10 +16,11 @@ from .config.auto_crop import AutoCrop
|
|
16
16
|
from .config.drawable import Drawable
|
17
17
|
from .config.shared import CameraShared
|
18
18
|
from .config.types import COLORS, CalibrationPoints, Colors, RoomsProperties
|
19
|
-
from .config.utils import BaseHandler,
|
19
|
+
from .config.utils import BaseHandler, prepare_resize_params
|
20
20
|
from .hypfer_draw import ImageDraw as ImDraw
|
21
21
|
from .map_data import ImageData
|
22
22
|
|
23
|
+
|
23
24
|
_LOGGER = logging.getLogger(__name__)
|
24
25
|
|
25
26
|
|
@@ -247,15 +248,7 @@ class HypferMapImageHandler(BaseHandler):
|
|
247
248
|
del img_np_array
|
248
249
|
# reduce the image size if the zoomed image is bigger then the original.
|
249
250
|
if self.check_zoom_and_aspect_ratio():
|
250
|
-
resize_params =
|
251
|
-
pil_img=pil_img,
|
252
|
-
width=self.shared.image_ref_width,
|
253
|
-
height=self.shared.image_ref_height,
|
254
|
-
aspect_ratio=self.shared.image_aspect_ratio,
|
255
|
-
crop_size=self.crop_img_size,
|
256
|
-
offset_func=self.async_map_coordinates_offset,
|
257
|
-
is_rand=False,
|
258
|
-
)
|
251
|
+
resize_params = prepare_resize_params(self, pil_img, False)
|
259
252
|
resized_image = await self.async_resize_images(resize_params)
|
260
253
|
return resized_image
|
261
254
|
_LOGGER.debug("%s: Frame Completed.", self.file_name)
|
@@ -24,10 +24,11 @@ from .config.types import (
|
|
24
24
|
RobotPosition,
|
25
25
|
RoomsProperties,
|
26
26
|
)
|
27
|
-
from .config.utils import BaseHandler,
|
27
|
+
from .config.utils import BaseHandler, prepare_resize_params
|
28
28
|
from .map_data import RandImageData
|
29
29
|
from .reimg_draw import ImageDraw
|
30
30
|
|
31
|
+
|
31
32
|
_LOGGER = logging.getLogger(__name__)
|
32
33
|
|
33
34
|
|
@@ -257,15 +258,7 @@ class ReImageHandler(BaseHandler):
|
|
257
258
|
|
258
259
|
async def _finalize_image(self, pil_img):
|
259
260
|
if self.check_zoom_and_aspect_ratio():
|
260
|
-
resize_params =
|
261
|
-
pil_img=pil_img,
|
262
|
-
width=self.shared.image_ref_width,
|
263
|
-
height=self.shared.image_ref_height,
|
264
|
-
aspect_ratio=self.shared.image_aspect_ratio,
|
265
|
-
crop_size=self.crop_img_size,
|
266
|
-
offset_func=self.async_map_coordinates_offset,
|
267
|
-
is_rand=True,
|
268
|
-
)
|
261
|
+
resize_params = prepare_resize_params(self, pil_img, True)
|
269
262
|
pil_img = await self.async_resize_images(resize_params)
|
270
263
|
_LOGGER.debug("%s: Frame Completed.", self.file_name)
|
271
264
|
return pil_img
|
@@ -1,13 +1,12 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "valetudo-map-parser"
|
3
|
-
version = "0.1.9.
|
3
|
+
version = "0.1.9.b23"
|
4
4
|
description = "A Python library to parse Valetudo map data returning a PIL Image object."
|
5
5
|
authors = ["Sandro Cantarella <gsca075@gmail.com>"]
|
6
6
|
license = "Apache-2.0"
|
7
7
|
readme = "README.md"
|
8
8
|
packages = [{include = "valetudo_map_parser", from = "SCR"}]
|
9
9
|
|
10
|
-
|
11
10
|
[tool.poetry.urls]
|
12
11
|
"Homepage" = "https://github.com/sca075/Python-package-valetudo-map-parser"
|
13
12
|
"Repository" = "https://github.com/sca075/Python-package-valetudo-map-parser"
|
@@ -19,43 +18,32 @@ python = ">=3.12"
|
|
19
18
|
numpy = ">=1.26.4"
|
20
19
|
Pillow = ">=10.3.0"
|
21
20
|
|
22
|
-
[poetry.group.dev.dependencies]
|
23
|
-
black = "*"
|
24
|
-
mypy = "*"
|
21
|
+
[tool.poetry.group.dev.dependencies]
|
25
22
|
ruff = "*"
|
26
23
|
isort = "*"
|
27
24
|
pylint = "*"
|
28
25
|
types-Pillow = "*"
|
29
26
|
|
30
|
-
|
31
|
-
|
27
|
+
# Ruff settings
|
28
|
+
[tool.ruff.format]
|
32
29
|
|
30
|
+
# isort settings (compatible with Ruff)
|
33
31
|
[tool.isort]
|
34
32
|
profile = "black"
|
35
33
|
line_length = 120
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
disallow_untyped_defs = true
|
46
|
-
disallow_untyped_decorators = true
|
47
|
-
no_implicit_optional = true
|
48
|
-
no_implicit_reexport = true
|
49
|
-
strict_optional = true
|
50
|
-
warn_incomplete_stub = true
|
51
|
-
warn_no_return = true
|
52
|
-
warn_redundant_casts = true
|
53
|
-
warn_return_any = true
|
54
|
-
warn_unused_configs = true
|
55
|
-
warn_unused_ignores = true
|
56
|
-
|
34
|
+
known_first_party = ["valetudo_map_parser"]
|
35
|
+
multi_line_output = 3
|
36
|
+
include_trailing_comma = true
|
37
|
+
force_grid_wrap = 0
|
38
|
+
use_parentheses = true
|
39
|
+
ensure_newline_before_comments = true
|
40
|
+
lines_after_imports = 2
|
41
|
+
|
42
|
+
# Pylint settings
|
57
43
|
[tool.pylint]
|
58
|
-
disable = ["C0103", "C0116", "R0902", "R0903", "
|
44
|
+
disable = ["C0103", "C0116", "R0902", "R0903", "R0904","R0913",
|
45
|
+
"R0914", "R0917", "R0915", "W0640"]
|
46
|
+
|
59
47
|
max-line-length = 120
|
60
48
|
|
61
49
|
[build-system]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/map_data.py
RENAMED
File without changes
|
{valetudo_map_parser-0.1.9b21 → valetudo_map_parser-0.1.9b23}/SCR/valetudo_map_parser/py.typed
RENAMED
File without changes
|