Skip to content

Support other APIs and metric types using a new providers interface#196

Open
abhidg wants to merge 16 commits into
mainfrom
192-refactor-main-support-other-apis
Open

Support other APIs and metric types using a new providers interface#196
abhidg wants to merge 16 commits into
mainfrom
192-refactor-main-support-other-apis

Conversation

@abhidg

@abhidg abhidg commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

This PR adds a providers interface that replaces the current CI_api_query and CI_api_interface classes. The advantage of the new approach is that it allows further customisation of the provider rather than customising the URL; this is useful to support providers that might need us to interface directly with a databases or with HTTP APIs requiring authentication. New types (Timeseries) have been added to support not just carbon intensity, but any other type of forecast timeseries with customizable units.

Other changes:

  • Added type hinting throughout
  • Using Exceptions for error handling (cats.exceptions) which allows us to consolidate error handling in one place (main()) as well as providing type based checking
  • Added --save-plot to save plots to file

Remaining refactor would be to move configuration parsing and error handling out of cats/cli.py, this will be done in a subsequent PR.

@abhidg
abhidg force-pushed the 192-refactor-main-support-other-apis branch from ec6aae4 to 4c59ac1 Compare June 28, 2026 14:23
@abhidg abhidg changed the title Support other APIs using a new providers interface Support other APIs and metric types using a new providers interface Jun 28, 2026
@abhidg
abhidg force-pushed the 192-refactor-main-support-other-apis branch from 4c59ac1 to 4a93af2 Compare June 28, 2026 14:27
@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.12698% with 50 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.83%. Comparing base (f623ba4) to head (6d6402d).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
cats/plotting.py 19.44% 29 Missing ⚠️
cats/cli.py 81.13% 10 Missing ⚠️
tests/test_configure.py 36.36% 7 Missing ⚠️
cats/providers/uk_carbonintensity.py 93.02% 3 Missing ⚠️
cats/providers/base.py 97.22% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #196      +/-   ##
==========================================
+ Coverage   87.17%   87.83%   +0.65%     
==========================================
  Files          20       22       +2     
  Lines        1092     1192     +100     
==========================================
+ Hits          952     1047      +95     
- Misses        140      145       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andreww andreww left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Happy overall. Probably worth briefly thinking about the location / time aspect of the API. Does this also close some further issues (e.g. renaming CI modules)? If so worth making sure we capture these.

Comment thread cats/providers/base.py Outdated
Comment thread cats/providers/base.py
-----------------

This module provides the base provider class from which all API providers for
CATS are derived from. To define a new provider, create a new class derived from

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should probably create space in the documentation for how to do this. Happy to write it as I work out how (probably via wattnet) or you can put a stub in place as part of this PR.

Comment thread cats/providers/uk_carbonintensity.py Outdated
Comment thread cats/cli.py Outdated
Comment thread tests/test_regressions.py Outdated
@andreww

andreww commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

The readthedocs and cluster-tests failures look like they linked. Both report not being able to import "cats.providers", but I cannot immediately reproduce locally.

@andreww andreww linked an issue Jul 3, 2026 that may be closed by this pull request
@abhidg
abhidg force-pushed the 192-refactor-main-support-other-apis branch 2 times, most recently from 6acfb37 to 5cdf627 Compare July 5, 2026 13:00
@abhidg
abhidg force-pushed the 192-refactor-main-support-other-apis branch from 5cdf627 to 1a3b160 Compare July 6, 2026 09:09
@abhidg
abhidg force-pushed the 192-refactor-main-support-other-apis branch from 1a3b160 to 6d6402d Compare July 7, 2026 17:48
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.

Headless mode access to plot by means to save

2 participants