Skip to content

Conversation

paynterf
Copy link

@paynterf paynterf commented Dec 21, 2024

XCSoar (.CUP) and Winpilot (.DAT) file processing now works properly. Unfortunately I couldn't figure out how to get the left/right/top/bottom bounds values to show up in the corresponding web page windows, so the map still isn't generated automatically.

As a workaround the calculated bounds are displayed in the 'error' window, and the user can manually transcribe the values to the bounds entry fields and then select the 'select map bounds by hand' option.

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation of waypoint file formats, ensuring only files with .dat or .cup extensions are accepted.
    • Enhanced handling of altitude values in waypoint parsing to support decimal values.
    • Improved detection and skipping of header lines and comments in SeeYou waypoint files.
    • Added error reporting for decoding issues in waypoint files.
  • Refactor

    • Streamlined and clarified internal parsing logic for waypoint files, including better variable naming and consistent input handling.
    • Improved code readability by adjusting whitespace and restructuring some conditions.

@lordfolken lordfolken linked an issue Dec 23, 2024 that may be closed by this pull request
Copy link
Member

@lordfolken lordfolken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on figuring out the basic problem. :)

Can you please make a change that is as minimal as possible to fix the cup parsing issue and make a commit for it? No Test files or commented out debug code please, also no excessive logging which isn´t needed for operation.

@paynterf
Copy link
Author

paynterf commented Jan 2, 2025

Let me get my Linux laptop back out and I'll do the changes you requested ;)

@paynterf
Copy link
Author

paynterf commented Jan 2, 2025

Regarding the .CUP file encoding issue, I checked both the Slovenia3.cup and the Slovenia3.cup, and it appears the Slovenia3.cup file is corrupted - at least in my Landscapes/Slovenia3 folder. I did see that Slovenia3.cup is encoded in UTF-8 as you stated, but for some reason the Slovenia2.cup file is encoded as 'ANSI'. In any case I'll change back to UTF-8, but what to do about the corrupted lines in Slovenia3.cup? Can you check Slovenia3.cup on your end? Here is my line for 'Amzs Koa' (which isn't in the Slovenia2.cup file)

"Amzs Ko├Ã",Amzs Koì,4539.139N,01450.914E,470.0m,1,,,,

@paynterf
Copy link
Author

paynterf commented Jan 2, 2025

commit 2abe1a4 (HEAD -> master)
Author: Frank Paynter [email protected]
Date: Wed Jan 1 21:47:37 2025 -0500

Changed decoding to UTF-8, removed logging code, removed test files

@lordfolken
Copy link
Member

Regarding the .CUP file encoding issue, I checked both the Slovenia3.cup and the Slovenia3.cup, and it appears the Slovenia3.cup file is corrupted - at least in my Landscapes/Slovenia3 folder. I did see that Slovenia3.cup is encoded in UTF-8 as you stated, but for some reason the Slovenia2.cup file is encoded as 'ANSI'. In any case I'll change back to UTF-8, but what to do about the corrupted lines in Slovenia3.cup? Can you check Slovenia3.cup on your end? Here is my line for 'Amzs Koa' (which isn't in the Slovenia2.cup file)

"Amzs Ko├Ã",Amzs Koì,4539.139N,01450.914E,470.0m,1,,,,

I also have condor3 and i see the same issue in the Slovenia3.cup file. So its really corrupted.

@paynterf
Copy link
Author

paynterf commented Jan 4, 2025

Removed another couple of logging code lines, and added Slovenia3.cup/dat to .gtignore

Copy link
Member

@lordfolken lordfolken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are getting there. 👍

Please remove any unessential changes.
No unnecessary newlines, indention changes,
Please delete Slovenia* from the code tree
also still some cherrypy.log entries which are just debug outputs

Regards,

  • Folken

@paynterf
Copy link
Author

One comment line removed from server.py, Slovenia* removed.

@paynterf
Copy link
Author

Haven't seen anything here recently. Do you have any other requested changes?

@paynterf
Copy link
Author

Just checking in here. I see you have requested a change, but I can't see what the requested change is. Am I missing something?

@lordfolken
Copy link
Member

@coderabbitai full review

Copy link

coderabbitai bot commented Jul 16, 2025

✅ Actions performed

Full review triggered.

Copy link

coderabbitai bot commented Jul 16, 2025

Warning

Rate limit exceeded

@lordfolken has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 0 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e0bb35b and 3f9dd9d.

📒 Files selected for processing (6)
  • lib/xcsoar/mapgen/server/server.py (2 hunks)
  • lib/xcsoar/mapgen/server/view.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/list.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/parser.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/seeyou_reader.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/winpilot_reader.py (2 hunks)

Walkthrough

The changes focus on improving the readability, correctness, and robustness of waypoint file parsing and validation. They clarify file extension checks, consistently handle byte input lines by decoding them, refine header and comment skipping, and enhance type handling for coordinates and altitudes. No public interfaces or function signatures were altered.

Changes

File(s) Change Summary
lib/xcsoar/mapgen/server/server.py Improved waypoint file extension validation logic, added whitespace for readability, adjusted control flow to return view after parsing.
lib/xcsoar/mapgen/server/view.py Added a blank line before context creation in the render function.
lib/xcsoar/mapgen/waypoints/list.py Removed an unnecessary blank line after rc.expand(offset_distance) in WaypointList.get_bounds.
lib/xcsoar/mapgen/waypoints/parser.py Standardized file reading to always use a list of lines, removed internal file opening logic.
lib/xcsoar/mapgen/waypoints/seeyou_reader.py Decoded input lines from bytes, improved header detection by matching exact CSV header line, enhanced error handling on decoding, clarified variable usage and line skipping.
lib/xcsoar/mapgen/waypoints/winpilot_reader.py Improved altitude parsing by converting to float before int, clarified variable naming, decoded input lines from bytes, added line counting.

Poem

In fields of code where waypoints lie,
Rabbits hop and parse on by.
Bytes decoded, headers clear,
Extensions checked—no bugs to fear!
With whitespace neat and logic tight,
The mapgen burrow shines so bright.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
lib/xcsoar/mapgen/waypoints/seeyou_reader.py (1)

81-83: Remove unused line counter variable.

The wpnum variable is incremented but never used elsewhere in the function. This appears to be leftover debugging code that should be removed.

-    wpnum = 0
     for byteline in lines:
-        wpnum = wpnum + 1
         line = byteline.decode("UTF-8")
lib/xcsoar/mapgen/waypoints/parser.py (1)

12-12: Clarify the bugfix comment.

The comment "# 241207 gfp bugfix:" is unclear. Please provide more context about what specific bug was fixed.

lib/xcsoar/mapgen/waypoints/winpilot_reader.py (1)

52-54: Consider utilizing the waypoint counter.

A waypoint counter wpnum is introduced but not used in the current implementation. If this is intended for future use (like line number reporting in error messages), consider adding a comment explaining its purpose.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 87dada4 and e332be4.

📒 Files selected for processing (7)
  • .gitignore (1 hunks)
  • lib/xcsoar/mapgen/server/server.py (5 hunks)
  • lib/xcsoar/mapgen/server/view.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/list.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/parser.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/seeyou_reader.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/winpilot_reader.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
lib/xcsoar/mapgen/waypoints/parser.py (2)
lib/xcsoar/mapgen/waypoints/winpilot_reader.py (1)
  • parse_winpilot_waypoints (49-73)
lib/xcsoar/mapgen/waypoints/seeyou_reader.py (1)
  • parse_seeyou_waypoints (76-137)
lib/xcsoar/mapgen/server/server.py (4)
lib/xcsoar/mapgen/waypoints/parser.py (1)
  • parse_waypoint_file (6-16)
lib/xcsoar/mapgen/waypoints/list.py (1)
  • get_bounds (33-43)
lib/xcsoar/mapgen/server/view.py (1)
  • render (35-47)
lib/xcsoar/mapgen/server/job.py (1)
  • error (65-70)
lib/xcsoar/mapgen/waypoints/winpilot_reader.py (1)
lib/xcsoar/mapgen/waypoints/list.py (1)
  • WaypointList (6-43)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (13)
.gitignore (1)

18-19: LGTM! Proper cleanup of corrupted test files.

Adding the corrupted Slovenia3.cup and Slovenia3.dat files to .gitignore is the correct approach based on the PR discussion about file corruption issues.

lib/xcsoar/mapgen/server/view.py (1)

44-44: LGTM! Good formatting improvement.

The blank line improves code readability by providing visual separation before the Context creation.

lib/xcsoar/mapgen/waypoints/list.py (1)

42-42: LGTM! Addressed previous review feedback.

The removal of the extraneous blank line addresses the previous review comment requesting this cleanup.

lib/xcsoar/mapgen/waypoints/seeyou_reader.py (2)

90-91: Good improvement for header detection.

The explicit header checking with if header in line: is a robust improvement that handles the updated CUP format standards mentioned in the past review comments.


97-100: Good variable naming improvement.

Using CSVline instead of reusing line improves code clarity and prevents confusion between the raw line and the CSV parsing object.

lib/xcsoar/mapgen/waypoints/parser.py (1)

10-12: Good alignment with parsing function expectations.

Passing the lines list to the parsing functions is correct since both parse_winpilot_waypoints and parse_seeyou_waypoints expect a list of byte lines to decode, as shown in the relevant code snippets.

lib/xcsoar/mapgen/server/server.py (3)

65-65: Minor formatting improvements.

The added whitespace improves code readability and consistency.

Also applies to: 79-79, 88-88, 111-111, 153-153


89-103: Excellent fix to the file extension validation logic.

The previous logic had a confusing condition that would incorrectly reject valid files. The new implementation clearly validates that the file must have either a .dat or .cup extension, which aligns with the supported formats mentioned in the PR objectives.


112-114: Temporary bounds display solution works as intended.

This implementation addresses the PR objective where automatic display of bounds in the web interface wasn't fully implemented. Showing the calculated bounds in the error message allows users to manually copy these values as mentioned in the PR summary.

lib/xcsoar/mapgen/waypoints/winpilot_reader.py (4)

13-16: Improved altitude parsing to handle decimal values.

The change from direct int(str) to int(float(str)) properly handles altitude strings that may contain decimal values, preventing ValueError exceptions.


18-24: Helpful documentation for coordinate formats.

The added comments clearly document the expected coordinate formats for Winpilot .DAT files, improving code maintainability.


31-31: Good practice: avoid variable name shadowing.

Renaming the variable from str to strsplit prevents shadowing of the built-in str type and makes the code more readable. All references have been correctly updated.

Also applies to: 32-32, 35-35, 37-37, 39-39


53-56: UTF-8 decoding implementation aligns with parser refactoring.

The change to iterate over byte lines and decode UTF-8 is consistent with the parser.py refactoring mentioned in the relevant snippets. This addresses the encoding issues discussed in the PR comments.

@lordfolken
Copy link
Member

@coderabbitai please create a commit that removes the addtions to .gitignore

Copy link

coderabbitai bot commented Jul 16, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@lordfolken, I'll help you remove the additions to .gitignore. Let me first examine the current state of the file to see exactly what needs to be removed.


🏁 Script executed:

#!/bin/bash
# Check the current content of .gitignore file
cat .gitignore

Length of output: 158


I can see the current .gitignore file and the two additions that need to be removed. Let me plan the code changes to remove Slovenia3.cup and Slovenia3.dat from the .gitignore file.

Task: Remove Slovenia3.cup and Slovenia3.dat from .gitignore

  • Remove the last two lines from .gitignore file
  • Create a commit with appropriate message

The plan is ready! Another agent will now execute these changes and create a commit that removes the Slovenia3.cup and Slovenia3.dat entries from the .gitignore file.


⏳ Preparing changes...

Copy link

coderabbitai bot commented Jul 16, 2025

A summary of the changes CodeRabbit can apply:

  • Update the .gitignore file by deleting the lines that exclude Slovenia3.cup and Slovenia3.dat to ensure these files are no longer ignored by version control.
  • Created local commit - (🔄 Check again to try again)

Copy link

coderabbitai bot commented Jul 16, 2025

Caution

CodeRabbit has failed to create a local commit with your edits.

1 similar comment
Copy link

coderabbitai bot commented Jul 16, 2025

Caution

CodeRabbit has failed to create a local commit with your edits.

@lordfolken lordfolken force-pushed the master branch 3 times, most recently from 859e1a4 to e0bb35b Compare July 16, 2025 11:32
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/xcsoar/mapgen/waypoints/seeyou_reader.py (1)

84-90: Improve exception chaining for better error context.

The UTF-8 decoding error handling correctly prevents data loss as required for aviation safety, but the exception chaining could be improved.

Apply this diff to follow Python best practices for exception chaining:

        except UnicodeDecodeError as e:
            raise RuntimeError(
                f"Failed to decode line {wpnum} as UTF-8: {e}. "
                f"Please check the waypoint file encoding and fix any corrupted data."
-            )
+            ) from e

This preserves the original exception context while providing the enhanced error message.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 859e1a4 and e0bb35b.

📒 Files selected for processing (6)
  • lib/xcsoar/mapgen/server/server.py (2 hunks)
  • lib/xcsoar/mapgen/server/view.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/list.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/parser.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/seeyou_reader.py (1 hunks)
  • lib/xcsoar/mapgen/waypoints/winpilot_reader.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • lib/xcsoar/mapgen/server/view.py
  • lib/xcsoar/mapgen/waypoints/list.py
  • lib/xcsoar/mapgen/server/server.py
  • lib/xcsoar/mapgen/waypoints/parser.py
  • lib/xcsoar/mapgen/waypoints/winpilot_reader.py
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: lordfolken
PR: XCSoar/mapgen#90
File: lib/xcsoar/mapgen/waypoints/seeyou_reader.py:84-84
Timestamp: 2025-07-16T10:29:46.065Z
Learning: In aviation contexts, waypoint data integrity is critical for navigation safety. Error handling should never silently skip or lose waypoint data as this could result in missing navigation points that pilots need. Always fail explicitly with clear error messages rather than silently losing data.
lib/xcsoar/mapgen/waypoints/seeyou_reader.py (1)
Learnt from: lordfolken
PR: XCSoar/mapgen#90
File: lib/xcsoar/mapgen/waypoints/seeyou_reader.py:84-84
Timestamp: 2025-07-16T10:29:46.065Z
Learning: In aviation contexts, waypoint data integrity is critical for navigation safety. Error handling should never silently skip or lose waypoint data as this could result in missing navigation points that pilots need. Always fail explicitly with clear error messages rather than silently losing data.
🪛 Ruff (0.12.2)
lib/xcsoar/mapgen/waypoints/seeyou_reader.py

87-90: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (4)
lib/xcsoar/mapgen/waypoints/seeyou_reader.py (4)

79-80: LGTM: Header definition improves robustness.

The explicit header definition makes the code more maintainable and self-documenting compared to relying on positional assumptions.


81-83: LGTM: Line counter enhances error reporting.

The line counter provides valuable context for error messages, which is crucial for aviation applications where data integrity issues must be precisely identified.


96-97: LGTM: Header detection replaces fragile line skipping.

The header detection is more robust than unconditionally skipping the first line, as it correctly handles files with different structures or missing headers.


103-106: LGTM: Variable naming improves code clarity.

Using CSVline instead of reusing line makes the code more readable and reduces potential confusion between the raw line and the CSV parser object.

@lordfolken
Copy link
Member

@coderabbitai hey bunny, can you analyze server.py and see why the bounds would not get parsed when uploading a foobar.cup file?

Copy link

coderabbitai bot commented Jul 16, 2025

Tip

For best results, initiate chat on the files or code changes.

A summary of the changes CodeRabbit can apply:

  • Analyze and correct the waypoint file processing in server.py by removing an early erroneous return that mishandles bounds parsing, clarifying and fixing the filename validation logic to properly support .cup files, and ensuring the flow continues correctly after waypoint validation.

  • Modify server.py to correct the waypoint file validation logic to accept both ".dat" and ".cup" files, and remove the debugging error message that halts map generation by deleting the return statement displaying bounds, enabling normal map generation flow.

  • Correct the bounds handling in server.py by replacing the error message on line 110 with code that populates the calculated bounds into the form fields and returns the updated view with these values.

  • Created local commit - (🔄 Check again to try again)

Copy link

coderabbitai bot commented Jul 16, 2025

Caution

CodeRabbit has failed to create a local commit with your edits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XCSoar Map Generator Error - cup file upload

2 participants