Skip to content
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

prof_to_cross utility #488

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

prof_to_cross utility #488

wants to merge 11 commits into from

Conversation

arthurvd
Copy link
Member

Fixes #487

@sonarcloud
Copy link

sonarcloud bot commented Apr 4, 2023

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
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
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
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
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).

hydrolib/core/utils.py Show resolved Hide resolved
@@ -0,0 +1,46 @@
import os
Copy link
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
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
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
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
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
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
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
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
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
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
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?

Copy link
Member Author

@arthurvd arthurvd Apr 11, 2023

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.

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
3 participants