-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor drawing methods for improved clarity and type safety #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
correct webp conversion
Angle for Rand256
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* testing new data and async_utils.py Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * Corrections Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * Corrections 2 Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * Corrections 3 async methods in auto crop optimize the image output. Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * update toml Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * update battery attributes. Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * update _state_charging Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * update _state_charging convert value to int Signed-off-by: Sandro Cantarella <sandro@d0c01da6-48fd-4689-9a5c-f5f21d0fdd39.fritz.box> * correct async_utils.py Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * correct async_utils.py Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * remove old rand25_parser.py Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * rand256 async implemented and introducing pool array. Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * removing memory expensing implemented before, changes in shared.py and added async_get_pil_image to the handlers base class Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * consolidating and renaming async_get_image adding bytes conversion on the go. solving issues on hyper_handler. Signed-off-by: Sandro Cantarella <sandro@d3548ddd-0920-4ec4-b22e-8d29b286c8c1.fritz.box> * removed parallel zone clean memory saving Signed-off-by: Sandro Cantarella <sandro@d3548ddd-0920-4ec4-b22e-8d29b286c8c1.fritz.box> * memory treat Signed-off-by: Sandro Cantarella <sandro@d3548ddd-0920-4ec4-b22e-8d29b286c8c1.fritz.box> * updated tests, and removed panda. Improved drawable.py, reimg_draw.py fix no walls draw Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * ruff format Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * updated init Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * updated init agan Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * project Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * project final Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> * project final Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> --------- Signed-off-by: Sandro Cantarella <sandro@Sandros-Mac-mini.fritz.box> Signed-off-by: Sandro Cantarella <sandro@d0c01da6-48fd-4689-9a5c-f5f21d0fdd39.fritz.box> Signed-off-by: Sandro Cantarella <sandro@d3548ddd-0920-4ec4-b22e-8d29b286c8c1.fritz.box>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors drawing methods to improve type safety, performance, and code clarity while maintaining compatibility. The changes focus on optimizing performance bottlenecks, adding async utilities, and removing outdated code.
Key changes:
- Enhanced async utilities for NumPy and PIL operations to improve performance
- Comprehensive performance profiling system for testing and optimization
- Refactored drawing algorithms with vectorized operations and better memory management
- Updated type hints and removed deprecated code
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_rand.py | Added comprehensive performance profiling with CPU and memory tracking |
| tests/test.py | Enhanced test suite with configurable profiling and performance metrics |
| pyproject.toml | Version bump from beta to stable release |
| SCR/valetudo_map_parser/reimg_draw.py | Added wall drawing conditional check for drawable elements |
| SCR/valetudo_map_parser/rand256_handler.py | Integrated async utilities and improved image processing |
| SCR/valetudo_map_parser/hypfer_handler.py | Major refactoring with parallel data extraction and memory optimization |
| SCR/valetudo_map_parser/hypfer_draw.py | Optimized drawing algorithms with vectorized operations |
| SCR/valetudo_map_parser/config/utils.py | Added unified async image handling method |
| SCR/valetudo_map_parser/config/types.py | Updated attribute constants for battery and charging |
| SCR/valetudo_map_parser/config/shared.py | Enhanced shared data management with PIL image handling |
| SCR/valetudo_map_parser/config/rand25_parser.py | Removed deprecated parser implementation |
| SCR/valetudo_map_parser/config/drawable.py | Refactored line drawing and zone rendering with optimized algorithms |
| SCR/valetudo_map_parser/config/auto_crop.py | Integrated async utilities for rotation operations |
| SCR/valetudo_map_parser/config/async_utils.py | New async utility module for NumPy and PIL operations |
| SCR/valetudo_map_parser/init.py | Updated exports to reflect new type system |
| .github/workflows/release.yaml | Updated checkout action to v5 |
| .github/workflows/code_quality.yaml | Updated checkout action to v5 |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| # Load the test.json file | ||
| test_file_path = os.path.join(os.path.dirname(__file__), "test.json") | ||
| test_file_path = os.path.join(os.path.dirname(__file__), "test.json") #glossyhardtofindnarwhal |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Remove the cryptic comment '#glossyhardtofindnarwhal' as it serves no documentation purpose and appears to be debug remnant.
| test_file_path = os.path.join(os.path.dirname(__file__), "test.json") #glossyhardtofindnarwhal | |
| test_file_path = os.path.join(os.path.dirname(__file__), "test.json") |
|
|
||
| return np_array | ||
|
|
||
| def _prepare_xyz_sequences(points: list[int]) -> list[tuple[int, int, int]]: |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This static method incorrectly references self.img_h.data.sublist but is defined as a static method. Either remove the @staticmethod decorator or pass the required data as a parameter.
| def _prepare_xyz_sequences(points: list[int]) -> list[tuple[int, int, int]]: | |
| def _prepare_xyz_sequences(self, points: list[int]) -> list[tuple[int, int, int]]: |
|
|
||
| predicted_path = (paths_data.get("predicted_path") or []) | ||
| if predicted_path and "points" in predicted_path[0]: | ||
| coords = _prepare_xy_sequences(predicted_path[0]["points"]) |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _prepare_xy_sequences is called but is not defined. This should likely be _prepare_xyz_sequences or a similar helper function that handles 2D coordinates.
|
|
||
| path_pixels = paths_data.get("path") or [] | ||
| for path in path_pixels: | ||
| coords = _prepare_xy_sequences(path.get("points", [])) |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _prepare_xy_sequences is called but is not defined. This should likely be _prepare_xyz_sequences or a similar helper function that handles 2D coordinates.
| attrs = { | ||
| ATTR_CAMERA_MODE: self.camera_mode, | ||
| ATTR_VACUUM_BATTERY: f"{self.vacuum_battery}%", | ||
| ATTR_VACUUM_CHARGING: self.vacuum_bat_charged, |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should call the method self.vacuum_bat_charged() with parentheses, not reference the method object itself.
| ATTR_VACUUM_CHARGING: self.vacuum_bat_charged, | |
| ATTR_VACUUM_CHARGING: self.vacuum_bat_charged(), |
| while True: | ||
| # Draw a filled circle for thickness | ||
| yy, xx = np.ogrid[-half_w : half_w + 1, -half_w : half_w + 1] | ||
| mask = xx**2 + yy**2 <= half_w**2 |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a circular mask for every pixel in line drawing is inefficient. Consider pre-computing the mask once and reusing it, or use a simpler approach for thick lines.
| while True: | |
| # Draw a filled circle for thickness | |
| yy, xx = np.ogrid[-half_w : half_w + 1, -half_w : half_w + 1] | |
| mask = xx**2 + yy**2 <= half_w**2 | |
| # Precompute the circular mask for line thickness | |
| yy, xx = np.ogrid[-half_w : half_w + 1, -half_w : half_w + 1] | |
| mask = xx**2 + yy**2 <= half_w**2 | |
| while True: |
Check types and pep8 corrections