No project description provided
Project description
NERC Rates
This repository stores rates, outages and invoicing configuration for the New England Research Cloud.
To make use of the rates and outages data, install the package and import the modules:
Usage
Loading Rates
from nerc_rates import rates
rate_data = rates.load_from_url()
rate_data.get_value_at("CPU SU Rate", "2024-06", Decimal)
Loading Outages
from nerc_rates import outages
outage_data = outages.load_from_url()
outage_data.get_outages_during("2024-05-01", "2024-06-01", "NERC OpenStack")
Loading Rates from file
from nerc_rates import rates
rate_data = rates.load_from_file("rates.yaml")
rate_data.get_value_at("CPU SU Rate", "2024-06", Decimal)
Loading Outages from file
from nerc_rates import outages
outage_data = outages.load_from_file("outages.yaml")
outage_data.get_outages_during("2024-05-01", "2024-06-01", "NERC OpenStack")
How To Verify Rates and Outages Data
This guide explains how the system automatically verifies the integrity and correctness of rates and outages data when it is loaded. The data models are designed with built-in validation rules to catch common errors, such as overlapping date ranges, incorrect data types, or duplicate entries.
How Verification Works
When you load data using rates.load_from_file() or outages.load_from_file(), the system attempts to parse your YAML data into its internal data models. During this process, several validation checks are performed automatically:
-
Rates Verification Checks:
- Date Range Order: Ensures that
date_untilis always afterdate_fromwithin aRateValue. - No Overlapping Date Ranges: Verifies that there are no overlapping timeframes for
RateValueentries within aRateItem'shistory. - Rate Type Consistency: Checks that
valuestrings can be correctly converted to theRateTypespecified for theRateItem(e.g., aDecimalrate is a valid number,boolrates are "true" or "false"). - Unique Rate Names: Ensures that each
RateItemhas a uniquenameacross the entire rates list.
- Date Range Order: Ensures that
-
Outages Verification Checks:
- Time Range Order: Ensures that
time_untilis always aftertime_fromwithin anOutageTimeFrames. - Unique Affected Services: Verifies that
affected_serviceswithin anOutageTimeFramesdo not contain duplicate service names. - Unique Outage URLs: Checks for duplicate
urlentries across allOutageItems in the outages list. - UTC Timezone Enforcement: Ensures all outage
datetimevalues (time_from,time_until) are provided with UTC timezone information and are not naive datetimes.
- Time Range Order: Ensures that
If any of these validation rules are violated, the loading process will raise a ValueError or TypeError, providing a clear message about what went wrong and where.
Example: Rates Verification
Let's say you have a rates.yaml file with an overlapping date range, which is an invalid configuration:
- name: CPU SU Rate
history:
- value: 0.013
from: 2023-06
until: 2024-06
- value: 0.15
from: 2024-05 # This date range overlaps with the previous one
When you try to load this data, you would see an error like this:
from nerc_rates import rates
try:
rate_data = rates.load_from_file("rates.yaml")
except ValueError as e:
print(f"Rates data validation failed: {e}")
Expected Output:
Rates data validation failed: date ranges overlap
Example: Outages Verification
Similarly, if your outages.yaml contains an outage with a naive datetime (missing timezone information), it will trigger a validation error:
- url: http://example.com/outage-1
timeframes:
- from: 2024-01-01T12:00:00 # Missing timezone info (e.g., Z or +00:00)
until: 2024-01-01T14:00:00Z
affected_services: ["NERC OpenStack"]
Loading this file would result in:
from nerc_rates import outages
try:
outage_data = outages.load_from_file("outages.yaml")
except ValueError as e:
print(f"Outages data validation failed: {e}")
Expected Output:
Outages data validation failed: Naive datetime without timezone information is not allowed. Please provide timezone information (e.g., '2024-01-01T12:00:00Z' or '2024-01-01T12:00:00+00:00')
How To Run Tests
This section guides you through setting up and running the test suite for this project using pytest. Running tests is crucial for verifying that all components of the system are working as expected and that any changes introduced do not break existing functionality.
Prerequisites
- Python 3.8+ installed
pipinstalled for dependency management
Steps
-
Install Dependencies: Navigate to the root directory of the project in your terminal and install the project dependencies.
pip install -r requirements.txt pip install -r test-requirements.txt
-
Run Tests: After installing the dependencies, you can run the test suite from the project's root directory:
pytest
This command will discover and execute all tests located in the
tests/directory.
Additional Information
- Specific Tests: To run a specific test file or test case, you can provide its path to
pytest:pytest tests/test_rates.py pytest tests/test_rates.py::test_get_cpu_rate
- Verbose Output: Use the
-vflag for more detailed output during test execution:pytest -v
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nerc_rates-1.0.1.tar.gz.
File metadata
- Download URL: nerc_rates-1.0.1.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab72c418f5e9291e8495d4fef46520930f238692aa89f90fbd74feb2a4458e18
|
|
| MD5 |
acb684c89748b3f9af78e17889a38fa3
|
|
| BLAKE2b-256 |
b6c90d779cd84306c384f12a036f7a145f73fb46478d1b79ffc32eb02eb543a6
|
Provenance
The following attestation bundles were made for nerc_rates-1.0.1.tar.gz:
Publisher:
publish-pypi.yaml on CCI-MOC/nerc-rates
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nerc_rates-1.0.1.tar.gz -
Subject digest:
ab72c418f5e9291e8495d4fef46520930f238692aa89f90fbd74feb2a4458e18 - Sigstore transparency entry: 753714747
- Sigstore integration time:
-
Permalink:
CCI-MOC/nerc-rates@d7ce862a249ed6e42b4cde3a78114a39b86e70e5 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/CCI-MOC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yaml@d7ce862a249ed6e42b4cde3a78114a39b86e70e5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nerc_rates-1.0.1-py3-none-any.whl.
File metadata
- Download URL: nerc_rates-1.0.1-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ee622a9d2355b0d6d8b4436653caccd5ede55177d097ee9d4659c248f31e154
|
|
| MD5 |
d815082f560eb3cc030b4a4c2ef3367f
|
|
| BLAKE2b-256 |
3c5ecf161ac4f81a51e940855342a7b84aa35b2c65204b28e485785a544399fd
|
Provenance
The following attestation bundles were made for nerc_rates-1.0.1-py3-none-any.whl:
Publisher:
publish-pypi.yaml on CCI-MOC/nerc-rates
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nerc_rates-1.0.1-py3-none-any.whl -
Subject digest:
9ee622a9d2355b0d6d8b4436653caccd5ede55177d097ee9d4659c248f31e154 - Sigstore transparency entry: 753714769
- Sigstore integration time:
-
Permalink:
CCI-MOC/nerc-rates@d7ce862a249ed6e42b4cde3a78114a39b86e70e5 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/CCI-MOC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yaml@d7ce862a249ed6e42b4cde3a78114a39b86e70e5 -
Trigger Event:
release
-
Statement type: