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

refactor: use time series collection yaml classes #328

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

jsolaas
Copy link
Contributor

@jsolaas jsolaas commented Dec 20, 2023

Validate when getting time_series from yaml model.

@jsolaas jsolaas requested a review from a team as a code owner December 20, 2023 09:02
@@ -269,8 +273,15 @@ def facility_inputs(self):
return self._internal_datamodel.get(EcalcYamlKeywords.facility_inputs, [])

@property
def time_series(self):
return self._internal_datamodel.get(EcalcYamlKeywords.time_series, [])
def time_series(self) -> List[YamlTimeSeriesCollection]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should do this for all values in yaml model IMO. Doing it here when the properties are used makes it possible to work with the yaml file without everything being valid

Copy link
Collaborator

Choose a reason for hiding this comment

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

so, to only actually parse accordign to schema when we use a property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, we can have a separate validate function if we need to make sure the full model is valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could also require the model to be valid.

It would be nice if this class took care of it though. This class would then read the model, then we can get the properties in the model as yaml classes, removing the need to validate a lot of stuff in other places.

@@ -11,6 +13,7 @@
class YamlTimeSeriesCollectionBase(YamlBase):
class Config:
title = "TimeSeries"
use_enum_values = True
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes enum a str when calling dict()

@@ -112,7 +112,8 @@ def map_yaml_to_variables(
result_options: dto.ResultOptions,
) -> dto.VariablesMap:
timeseries_collections = [
TimeSeriesCollectionMapper(resources).from_yaml_to_dto(timeseries) for timeseries in configuration.time_series
TimeSeriesCollectionMapper(resources).from_yaml_to_dto(timeseries.dict(by_alias=True))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should look into removing this mapper and the classes, should be able to handle it in the yaml classes?

Converting back to dict as that is expected in TimeSeriesCollectionMapper

Copy link
Collaborator

Choose a reason for hiding this comment

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

you mean to implicitly and automatically handle the conversion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://equinor-ecalc.atlassian.net/browse/ECALC-586 Explained a bit here.
TimeSeriesCollectionMapper should not need to deal with validation of the yaml at least, it could be simplified to only deal with reading the resources and creating something that can easily be added to variables map

Validate when getting time_series from yaml model.
@jsolaas jsolaas force-pushed the refactor/use-time-series-yaml-classes branch from aceffca to 93baf08 Compare December 20, 2023 09:21
@@ -269,8 +273,15 @@ def facility_inputs(self):
return self._internal_datamodel.get(EcalcYamlKeywords.facility_inputs, [])

@property
def time_series(self):
return self._internal_datamodel.get(EcalcYamlKeywords.time_series, [])
Copy link
Collaborator

Choose a reason for hiding this comment

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

what was returned here? a "string dict"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously it was a list of dicts, each dict was a time series entry from yaml

@jsolaas jsolaas merged commit c36f62b into main Dec 20, 2023
6 checks passed
@jsolaas jsolaas deleted the refactor/use-time-series-yaml-classes branch December 20, 2023 09:41
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.

2 participants