Skip to main content

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_until is always after date_from within a RateValue.
    • No Overlapping Date Ranges: Verifies that there are no overlapping timeframes for RateValue entries within a RateItem's history.
    • Rate Type Consistency: Checks that value strings can be correctly converted to the RateType specified for the RateItem (e.g., a Decimal rate is a valid number, bool rates are "true" or "false").
    • Unique Rate Names: Ensures that each RateItem has a unique name across the entire rates list.
  • Outages Verification Checks:

    • Time Range Order: Ensures that time_until is always after time_from within an OutageTimeFrames.
    • Unique Affected Services: Verifies that affected_services within an OutageTimeFrames do not contain duplicate service names.
    • Unique Outage URLs: Checks for duplicate url entries across all OutageItems in the outages list.
    • UTC Timezone Enforcement: Ensures all outage datetime values (time_from, time_until) are provided with UTC timezone information and are not naive datetimes.

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
  • pip installed for dependency management

Steps

  1. 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
    
  2. 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 -v flag for more detailed output during test execution:
    pytest -v
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nerc_rates-1.0.1.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nerc_rates-1.0.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

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

Hashes for nerc_rates-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ab72c418f5e9291e8495d4fef46520930f238692aa89f90fbd74feb2a4458e18
MD5 acb684c89748b3f9af78e17889a38fa3
BLAKE2b-256 b6c90d779cd84306c384f12a036f7a145f73fb46478d1b79ffc32eb02eb543a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nerc_rates-1.0.1.tar.gz:

Publisher: publish-pypi.yaml on CCI-MOC/nerc-rates

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for nerc_rates-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9ee622a9d2355b0d6d8b4436653caccd5ede55177d097ee9d4659c248f31e154
MD5 d815082f560eb3cc030b4a4c2ef3367f
BLAKE2b-256 3c5ecf161ac4f81a51e940855342a7b84aa35b2c65204b28e485785a544399fd

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page