-
Notifications
You must be signed in to change notification settings - Fork 4
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
Initial commit #1
Conversation
knikolla
commented
May 14, 2024
- Implemented library for loading rates.yaml
- Wrote simple tests for library
- Updated README with description
- Made the package installable
- Updated current rates
- Implemented library for loading rates.yaml - Wrote simple tests for library - Updated README with description - Made the package installable - Updated current rates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a little bothered by the structure of rates.yaml
. We're storing different data types in the same attribute, and we're storing different types of "objects" in the same list. Here, value
is a float:
- name: CPU SU Rate
history:
- value: 0.013
from: 2023-06
But here it's a boolean (although this should technically be spelled false
):
- name: Charge for Stopped Instances
history:
- value: False
from: 2023-06
until: 2024-02
And later on it's an integer.
Is that ever going to bite us? It certainly makes the file difficult to validate, and difficult to parse in languages with strict typing. We're cheating a bit in the code by using yaml.BaseLoader
, which returns everything as strings.
I wonder if we should split the file into sections:
rates:
- name: CPU SU Rate
history:
- value: 0.013
from: 2023-06
feature_flags:
- name: Charge for Stopped Instances
history:
- value: false
from: 2023-06
until: 2024-02
- value: true
from: 2024-03
definitions:
- name: VCPUs in CPU SU
history:
- value: 1
from: 2023-06
That would allow us to iterate over a thing (like rates
) and know what to expect in the value
field.
Maybe the content of rates.yaml
is entirely internal to this code, and rather than YAML format it's actually "nerc-rates-YAML" format, and we don't expect it to be parsed by anything else, in which case none of the above concerns are relevant.
@larsks Yeah, I was bothered by the inconsistent value types too, hence in the code I used the BaseLoader to keep everything as strings and let the downstream code accessing the specific values handle the conversion since it would know what it is trying to access. Reading your comment, I see the ambiguity that that may lead to tools that are attempting to parse the YAML directly without using the python library, since those values appear to be floats, whereas the I tried an approach that divided things into sections initially, but I found that a better approach was to have a I can reintroduce the Do you have a preference? |
I don't think a I guess my preference in the short term would be to quote everything if it's expected to be a string, but I would combine that with validation in the code. |
E.g., like: https://github.com/larsks/nerc-rates/tree/feature/pydantic (which also drops setup.*). The interesting bit is probably |
@knikolla I've pushed changes that add support for validation using pydantic, along with specific validations for the ordering between |
988dd62
to
4b9c96e
Compare
It looks like |
Drop setup.cfg and setup.py which are no longer required with modern Python. I've moved all the metadata from setup.cfg into pyproject.toml.
Ensure that all values in rates.yaml are string values by (a) editing the file to quote all values and (b) implementing pydantic models for the rate data so that we can validate the values on input.
Ensure that the `from` field for a given rate entry is always earlier than the `until` field.
Ensure that date ranges in a `history` list do not overlap.
Raise an error if two rate items have the same name. E.g, this would trigger an error: ``` - name: Test Rate history: - values: "1"" from: 2023-06 until: 2023-11 - name: Test Rate history: - values: "2"" from: 2023-12 ```