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

Maritime schema integration #24

Conversation

minhemdnv
Copy link

These changes should allow the Types from maritime-schema to be used. The main changes are in types.py (now much shorter), as shared types live in maritime schema. Also some changes here and wherever an error was thrown. As far as I can see, the output generated is the same.

Copy link
Contributor

@ClaasRostock ClaasRostock left a comment

Choose a reason for hiding this comment

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

Great work. Approved with some comments.
Most comments are minor. The only one that needs to be resolved before merging is the one in pyproject.toml (how the maritime-schema package is referenced).

pyproject.toml Outdated
global-land-mask = "^1.0.0"
folium = "^0.14.0"
pydantic = "^2.5"
maritime-schema = { git = "https://github.com/dnv-opensource/maritime-schema.git" }
Copy link
Contributor

Choose a reason for hiding this comment

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

change to maritime-schema = "^0.0.3" once the maritime-schema package is published.
(This line is the reason why the GitHub workflow fails. The workflow does not have permission to clone the maritime-schema repository)

Copy link
Author

Choose a reason for hiding this comment

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

also done :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Installing the ship-traffic-generator package on my own machine I found out that we also need to limit the python versions we allow.

python = "^3.9"
needs to be changed to
python = ">=3.9, <3.13"

This is needed because "^3.9" effectively means ">=3.9, <4.0" , and hence includes 3.13
There are multiple other dependencies, though, that require python <3.13 (which makes sense. Also we ourselves would want to require that).
If we implicitly allow python 3.13 (which "^3,9" does), then dependency resolution fails.

src/trafficgen/encounter.py Outdated Show resolved Hide resolved
src/trafficgen/read_files.py Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

we could think about applying the same improvements here that you introduced also in the caga.py module in maritime-schema. At least two minor things come to my mind; maybe there are more:
a) the to_camel function we could import from maritime_schema.utils.strings instead of implementing it here again
b) I remember you improved the way the model 'config' was handled, in maritime-schema. You created an additional base class that all models then inherited from. Not sure, but maybe this is an improvement that is worth to apply also here in ship-traffic-generator?

Copy link
Author

Choose a reason for hiding this comment

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

sure, I will look into these!

@minhemdnv
Copy link
Author

@tomarnepedersen I've fixed most of the issues that Claas pointed out, but perhaps you also want to take a look to make sure you are happy with the changes. I tried my best not to change anything too drastically! To get most things to work, I've had to modify the maritime-schema, and change a lot of fields to Optional. This is because in ship-traffic-gen the classes such as Initial() are created which are completely empty, and then subsequently populated. If the fields were not optional, Pydantic would throw an error and not allow the class to be created. But, setting all fields to optional makes it harder to use the built in Validation features that Pydantic provides, so in the long run I would consider refactoring some parts of ship-traffic-gen so that martime-schema classes are only created once all the values that are required actually exist.

@tomarnepedersen
Copy link
Collaborator

@tomarnepedersen I've fixed most of the issues that Claas pointed out, but perhaps you also want to take a look to make sure you are happy with the changes. I tried my best not to change anything too drastically! To get most things to work, I've had to modify the maritime-schema, and change a lot of fields to Optional. This is because in ship-traffic-gen the classes such as Initial() are created which are completely empty, and then subsequently populated. If the fields were not optional, Pydantic would throw an error and not allow the class to be created. But, setting all fields to optional makes it harder to use the built in Validation features that Pydantic provides, so in the long run I would consider refactoring some parts of ship-traffic-gen so that martime-schema classes are only created once all the values that are required actually exist.

See your point. Of course, possible to change the code in later release to do as you suggest. The reason for not having the fields optiona I guess is to not have to have checks if the parameter includes a value?
Will have a look at your changes.

@minhemdnv
Copy link
Author

minhemdnv commented Feb 28, 2024

The reason for not having the fields optiona I guess is to not have to have checks if the parameter includes a value?

Exactly. But I agree, we can fix this later on

@tomarnepedersen
Copy link
Collaborator

Already merged a branch which was based on this one. This could be deleted

@tomarnepedersen tomarnepedersen deleted the branch 17-dnv-is-suggesting-a-new-data-structure-for-inputoutput-which-may-affect-the-situation-generator April 10, 2024 08:34
@tomarnepedersen tomarnepedersen deleted the maritime-schema-integration branch April 10, 2024 08:35
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.

3 participants