Review/897/distinguish fallback value and max value#909
Conversation
Signed-off-by: F.N. Claessen <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
…ing a maximum capacity limit Signed-off-by: F.N. Claessen <[email protected]>
…n with the fallback Signed-off-by: F.N. Claessen <[email protected]>
victorgarcia98
left a comment
There was a problem hiding this comment.
Nice!
I agree, it's a good policy to have just one fallback and not multiple through chained attributes that have a fallback attribute). Even though in some settings might be interesting, It's better to have a consistent/expected behavior.
For example, in the case of a site power capacity, typically the consumption/production capacities are the same, thus, we can default the directional capacities to the global capacity. This is happening
flexmeasures/flexmeasures/data/models/planning/storage.py
Lines 285 to 330 in c1b24dd
…apacity-as-sensor' into review/897/distinguish-default-value-and-max-value
Signed-off-by: F.N. Claessen <[email protected]>
…tity, as its name already suggested Signed-off-by: F.N. Claessen <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
Signed-off-by: F.N. Claessen <[email protected]>
|
I refactored a bit further, which made for a much slimmer
|
Perhaps, we can make the function a static method of the class QuantityOrSensor.get_series(quantity_or_sensor, start, end, ...)However, this looks the same size if not more. An alternative name could be
Good idea! This is a feature that we are going to find a lot and it's better to bring the functionality into the marshmallow field. |
|
I'm expecting that moving the fallback logic into the schema will also lead to more clarity on choosing a new name for the util method. Maybe tackle those together. |
* add (device) consumption capacity and production capacity as sensors Signed-off-by: Victor Garcia Reolid <[email protected]> * convert units of the power limits to the sensor units Signed-off-by: Victor Garcia Reolid <[email protected]> * add QuantityOrSensor field Signed-off-by: Victor Garcia Reolid <[email protected]> * add annotations Signed-off-by: Victor Garcia Reolid <[email protected]> * introduce QuantityorSensor schema Signed-off-by: Victor Garcia Reolid <[email protected]> * add from __future__ import annotations Signed-off-by: Victor Garcia Reolid <[email protected]> * remove discarded revision Signed-off-by: Victor Garcia Reolid <[email protected]> * add target unit Signed-off-by: Victor Garcia Reolid <[email protected]> * change exception type to FMValidationError Signed-off-by: Victor Garcia Reolid <[email protected]> * add explicity default value Signed-off-by: Victor Garcia Reolid <[email protected]> * split into two functions Signed-off-by: Victor Garcia Reolid <[email protected]> * Review/897/refactoring (#908) * refactor: fix spelling Signed-off-by: F.N. Claessen <[email protected]> * style: missing type annotation Signed-off-by: F.N. Claessen <[email protected]> * refactor: method and variable renaming Signed-off-by: F.N. Claessen <[email protected]> * refactor: add test case explanations Signed-off-by: F.N. Claessen <[email protected]> --------- Signed-off-by: F.N. Claessen <[email protected]> * Review/897/distinguish fallback value and max value (#909) * refactor: fix spelling Signed-off-by: F.N. Claessen <[email protected]> * style: missing type annotation Signed-off-by: F.N. Claessen <[email protected]> * refactor: method and variable renaming Signed-off-by: F.N. Claessen <[email protected]> * refactor: add test case explanations Signed-off-by: F.N. Claessen <[email protected]> * fix: separate logic for falling back on a default attribute and applying a maximum capacity limit Signed-off-by: F.N. Claessen <[email protected]> * fix: fill gaps in capacity sensor data using the max_value rather than with the fallback Signed-off-by: F.N. Claessen <[email protected]> * fix: type annotation (see https://docs.python.org/3/library/typing.html#typing.Optional) Signed-off-by: F.N. Claessen <[email protected]> * refactor: clearly separate steps of falling back and performing a nanmin Signed-off-by: F.N. Claessen <[email protected]> * refactor: simplify and have get_quantity_from_attribute return a Quantity, as its name already suggested Signed-off-by: F.N. Claessen <[email protected]> * refactor: switch argument order Signed-off-by: F.N. Claessen <[email protected]> * refactor: update docstring Signed-off-by: F.N. Claessen <[email protected]> * style: flake8 Signed-off-by: F.N. Claessen <[email protected]> --------- Signed-off-by: F.N. Claessen <[email protected]> * fix test Signed-off-by: Victor Garcia Reolid <[email protected]> * add changelog entry Signed-off-by: Victor Garcia Reolid <[email protected]> * update changelog Signed-off-by: Victor Garcia Reolid <[email protected]> --------- Signed-off-by: Victor Garcia Reolid <[email protected]> Signed-off-by: F.N. Claessen <[email protected]> Co-authored-by: Felix Claessen <[email protected]>
* add (device) consumption capacity and production capacity as sensors Signed-off-by: Victor Garcia Reolid <[email protected]> * convert units of the power limits to the sensor units Signed-off-by: Victor Garcia Reolid <[email protected]> * add QuantityOrSensor field Signed-off-by: Victor Garcia Reolid <[email protected]> * add annotations Signed-off-by: Victor Garcia Reolid <[email protected]> * introduce QuantityorSensor schema Signed-off-by: Victor Garcia Reolid <[email protected]> * add from __future__ import annotations Signed-off-by: Victor Garcia Reolid <[email protected]> * remove discarded revision Signed-off-by: Victor Garcia Reolid <[email protected]> * add target unit Signed-off-by: Victor Garcia Reolid <[email protected]> * change exception type to FMValidationError Signed-off-by: Victor Garcia Reolid <[email protected]> * add explicity default value Signed-off-by: Victor Garcia Reolid <[email protected]> * split into two functions Signed-off-by: Victor Garcia Reolid <[email protected]> * add usage forecast Signed-off-by: Victor Garcia Reolid <[email protected]> * add test Signed-off-by: Victor Garcia Reolid <[email protected]> * Review/897/refactoring (#908) * refactor: fix spelling Signed-off-by: F.N. Claessen <[email protected]> * style: missing type annotation Signed-off-by: F.N. Claessen <[email protected]> * refactor: method and variable renaming Signed-off-by: F.N. Claessen <[email protected]> * refactor: add test case explanations Signed-off-by: F.N. Claessen <[email protected]> --------- Signed-off-by: F.N. Claessen <[email protected]> * use resolution to convert energy series to the target event resolution Signed-off-by: Victor Garcia Reolid <[email protected]> * simplify conftest Signed-off-by: Victor Garcia Reolid <[email protected]> * Review/897/distinguish fallback value and max value (#909) * refactor: fix spelling Signed-off-by: F.N. Claessen <[email protected]> * style: missing type annotation Signed-off-by: F.N. Claessen <[email protected]> * refactor: method and variable renaming Signed-off-by: F.N. Claessen <[email protected]> * refactor: add test case explanations Signed-off-by: F.N. Claessen <[email protected]> * fix: separate logic for falling back on a default attribute and applying a maximum capacity limit Signed-off-by: F.N. Claessen <[email protected]> * fix: fill gaps in capacity sensor data using the max_value rather than with the fallback Signed-off-by: F.N. Claessen <[email protected]> * fix: type annotation (see https://docs.python.org/3/library/typing.html#typing.Optional) Signed-off-by: F.N. Claessen <[email protected]> * refactor: clearly separate steps of falling back and performing a nanmin Signed-off-by: F.N. Claessen <[email protected]> * refactor: simplify and have get_quantity_from_attribute return a Quantity, as its name already suggested Signed-off-by: F.N. Claessen <[email protected]> * refactor: switch argument order Signed-off-by: F.N. Claessen <[email protected]> * refactor: update docstring Signed-off-by: F.N. Claessen <[email protected]> * style: flake8 Signed-off-by: F.N. Claessen <[email protected]> --------- Signed-off-by: F.N. Claessen <[email protected]> * fix test Signed-off-by: Victor Garcia Reolid <[email protected]> * add changelog entry Signed-off-by: Victor Garcia Reolid <[email protected]> * improve tests and implement consumption_is_positive Signed-off-by: Victor Garcia Reolid <[email protected]> * add resolution factor to convert from energy units to power units Signed-off-by: Victor Garcia Reolid <[email protected]> * fix test + add new case Signed-off-by: Victor Garcia Reolid <[email protected]> * split stock delta into stock gain and stock usage Signed-off-by: Victor Garcia Reolid <[email protected]> * update changelog Signed-off-by: Victor Garcia Reolid <[email protected]> * switch to power units Signed-off-by: Victor Garcia Reolid <[email protected]> * improve comments Signed-off-by: Victor Garcia Reolid <[email protected]> * add changelog Signed-off-by: Victor Garcia Reolid <[email protected]> * Update changelog.rst Fix typo (*los componentes*) and swap out some changelog entries between Features and Infrastructure. Signed-off-by: Felix Claessen <[email protected]> * Apply black Signed-off-by: Victor Garcia Reolid <[email protected]> --------- Signed-off-by: Victor Garcia Reolid <[email protected]> Signed-off-by: F.N. Claessen <[email protected]> Signed-off-by: Victor <[email protected]> Signed-off-by: Felix Claessen <[email protected]> Co-authored-by: Felix Claessen <[email protected]>
* add (device) consumption capacity and production capacity as sensors Signed-off-by: Victor Garcia Reolid <[email protected]> * convert units of the power limits to the sensor units Signed-off-by: Victor Garcia Reolid <[email protected]> * add QuantityOrSensor field Signed-off-by: Victor Garcia Reolid <[email protected]> * add annotations Signed-off-by: Victor Garcia Reolid <[email protected]> * introduce QuantityorSensor schema Signed-off-by: Victor Garcia Reolid <[email protected]> * add from __future__ import annotations Signed-off-by: Victor Garcia Reolid <[email protected]> * remove discarded revision Signed-off-by: Victor Garcia Reolid <[email protected]> * add target unit Signed-off-by: Victor Garcia Reolid <[email protected]> * change exception type to FMValidationError Signed-off-by: Victor Garcia Reolid <[email protected]> * add explicity default value Signed-off-by: Victor Garcia Reolid <[email protected]> * split into two functions Signed-off-by: Victor Garcia Reolid <[email protected]> * Review/897/refactoring (#908) * refactor: fix spelling Signed-off-by: F.N. Claessen <[email protected]> * style: missing type annotation Signed-off-by: F.N. Claessen <[email protected]> * refactor: method and variable renaming Signed-off-by: F.N. Claessen <[email protected]> * refactor: add test case explanations Signed-off-by: F.N. Claessen <[email protected]> --------- Signed-off-by: F.N. Claessen <[email protected]> * Review/897/distinguish fallback value and max value (#909) * refactor: fix spelling Signed-off-by: F.N. Claessen <[email protected]> * style: missing type annotation Signed-off-by: F.N. Claessen <[email protected]> * refactor: method and variable renaming Signed-off-by: F.N. Claessen <[email protected]> * refactor: add test case explanations Signed-off-by: F.N. Claessen <[email protected]> * fix: separate logic for falling back on a default attribute and applying a maximum capacity limit Signed-off-by: F.N. Claessen <[email protected]> * fix: fill gaps in capacity sensor data using the max_value rather than with the fallback Signed-off-by: F.N. Claessen <[email protected]> * fix: type annotation (see https://docs.python.org/3/library/typing.html#typing.Optional) Signed-off-by: F.N. Claessen <[email protected]> * refactor: clearly separate steps of falling back and performing a nanmin Signed-off-by: F.N. Claessen <[email protected]> * refactor: simplify and have get_quantity_from_attribute return a Quantity, as its name already suggested Signed-off-by: F.N. Claessen <[email protected]> * refactor: switch argument order Signed-off-by: F.N. Claessen <[email protected]> * refactor: update docstring Signed-off-by: F.N. Claessen <[email protected]> * style: flake8 Signed-off-by: F.N. Claessen <[email protected]> --------- Signed-off-by: F.N. Claessen <[email protected]> * fix test Signed-off-by: Victor Garcia Reolid <[email protected]> * add changelog entry Signed-off-by: Victor Garcia Reolid <[email protected]> * update changelog Signed-off-by: Victor Garcia Reolid <[email protected]> * add charge and discharge efficiencies Signed-off-by: Victor Garcia Reolid <[email protected]> * fix test Signed-off-by: Victor Garcia Reolid <[email protected]> * add extra validation and use 100 for the missing values instead of the roundtrip Signed-off-by: Victor Garcia Reolid <[email protected]> * fix validation rules Signed-off-by: Victor Garcia Reolid <[email protected]> * check roundtrip efficiency Signed-off-by: Victor Garcia Reolid <[email protected]> * add documentation Signed-off-by: Victor Garcia Reolid <[email protected]> --------- Signed-off-by: Victor Garcia Reolid <[email protected]> Signed-off-by: F.N. Claessen <[email protected]> Co-authored-by: Felix Claessen <[email protected]>
This is the second part of my post-review work, dealing with the distinction between:
I split this work into two commits, best considered separately:
In the second commit, I'm proposing to fill these with the power capacity, rather than with the value coming from the fallback attribute. I realize I am proposing this with the consideration of obtaining a consistent policy throughout our API, more so than practical considerations for a given use case. That API policy being that db model attributes are only used as fallbacks for missing fields, rather than as limitations on fields, of flex-models sent through the API.
I'm open to discussing potential merits of deviating from this policy, of course, perhaps by hands of an example?