Skip to content

prof_to_cross utility#488

Open
arthurvd wants to merge 11 commits into
mainfrom
feat/487_prof_to_cross
Open

prof_to_cross utility#488
arthurvd wants to merge 11 commits into
mainfrom
feat/487_prof_to_cross

Conversation

@arthurvd

Copy link
Copy Markdown
Member

Fixes #487

@sonarqubecloud

sonarqubecloud Bot commented Apr 4, 2023

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@priscavdsluis priscavdsluis marked this pull request as ready for review April 5, 2023 14:48
@@ -0,0 +1 @@

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should something be added to this file?

@@ -0,0 +1,545 @@
import argparse

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to put these file in the tools folder or in a sub folder in the tools folder? e.g. tools/converters

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

would it be an idea to splitup this file into smaller files?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The conclusion of last week's discussion was: begin with all tools directly inside the tools directory.
But now that this stis here, let's double check tomorrow (also taking your question below into account).

Comment thread hydrolib/core/utils.py
@@ -0,0 +1,46 @@
import os

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should the cmd line input (main) also be tested?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these tests only cover the prof_to_cross & prof_to_cross_from_mdu "public" methods, do we also need to test the other "public" methods?

if _proftype >= 2:
_proftype = math.floor(_proftype / 2.0) * 2

if _proftype == 1: # Pipe

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe you can use a dictionary to do this?

_crstype_map = {
    1: "circle",
    2: "rectangle",
    4: "yz",
    6: "yz",
    100: "yz",
    200: "xyz",
}

if _proftype in _crstype_map:
    crstype = _crstype_map[_proftype]
else:
    raise ValueError(f"Invalid legacy profile type given: TYPE={proftype}")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought about this! But then I thought: YAGNI.
I'll think about it

str: Equivalent frictionType string value for use in a crsdef.ini.
"""

if frctp == 0:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe the same refactor as described by _proftype_to_crsdeftype?


(proftype, crstype) = _proftype_to_crsdeftype(profdef.get("TYPE"))

crsdata = {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe the same refactor as described by _proftype_to_crsdeftype?
You could also move this to a seperate method.


crsdata["id"] = f"PROFNR{profdef['PROFNR']}"
crsdata["type"] = crstype
if crstype == "circle":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe the same refactor as described by _proftype_to_crsdeftype?
You could also move this to a seperate method.

crslocfile: PathOrStr = None,
crsdeffile: PathOrStr = None,
):
"""The actual converter function for converting legacy profile files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does "actual" add value to this description?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how do we want to make a distinction between the wrapper and this method towards the users in the method description?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is the addition in the wrapper function [..], for files listed in an MDU file. not sufficiently clear?

crslocfile: PathOrStr = None,
crsdeffile: PathOrStr = None,
):
"""Wrapper converter function for converting legacy profile files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to state that it is a wrapper, is that information usefull for the user?

@arthurvd arthurvd Apr 11, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

"Wrapper" can go for me, but it's to stress that this has MDU as input, but for the rest is the same as the actual converter function. Note that "user" is a "developer" here.

@arthurvd arthurvd requested a review from Copilot April 30, 2025 06:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 introduces the prof_to_cross utility for converting legacy D-Flow FM profile files to cross section files. It adds new tests, documentation, and a supporting context manager in the core utilities to facilitate the tool's operation.

  • Added unit tests for processing both profile files and MDU files.
  • Updated documentation and navigation to incorporate prof_to_cross.
  • Introduced a new working_directory context manager in the core utils.

Reviewed Changes

Copilot reviewed 7 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/tools/test_prof_to_cross.py New tests for validating prof_to_cross functionality
mkdocs.yml Updated navigation to include prof_to_cross documentation
hydrolib/tools/init .py Added an (empty) module initialization file for tools
hydrolib/core/utils.py Added working_directory context manager to manage CWD changes
docs/tools/tools.md Added an overview of built-in tools including prof_to_cross
docs/tools/prof_to_cross.md Added detailed documentation for prof_to_cross
Files not reviewed (10)
  • tests/data/input/prof_to_cross/profdef.txt: Language not supported
  • tests/data/input/prof_to_cross/profdef_withxyz.txt: Language not supported
  • tests/data/input/prof_to_cross/profdefxyz.pliz: Language not supported
  • tests/data/input/prof_to_cross/profloc.xyz: Language not supported
  • tests/data/input/prof_to_cross/profloc_withxyz.xyz: Language not supported
  • tests/data/input/prof_to_cross/tree1d2d.mdu: Language not supported
  • tests/data/reference/prof_to_cross/crsdef.ini: Language not supported
  • tests/data/reference/prof_to_cross/crsdef_withxyz.ini: Language not supported
  • tests/data/reference/prof_to_cross/crsloc.ini: Language not supported
  • tests/data/reference/prof_to_cross/crsloc_withxyz.ini: Language not supported
Comments suppressed due to low confidence (2)

hydrolib/core/utils.py:186

  • The 'Path' identifier is used without being imported. Consider adding 'from pathlib import Path' at the top of the file.
prev_cwd = Path.cwd()

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.

Converter for legacy profile files to cross section files

4 participants