-
Notifications
You must be signed in to change notification settings - Fork 0
[PD1-588] Allow access to data marketplace data #6
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from cvec import CVec | ||
| import io | ||
| import pyarrow.ipc as ipc # type: ignore[import-untyped] | ||
| import os | ||
|
|
||
|
|
||
| def main() -> None: | ||
| cvec = CVec( | ||
| host=os.environ.get("CVEC_HOST", "https://your-subdomain.cvector.dev"), | ||
| api_key=os.environ.get("CVEC_API_KEY", "your-api-key"), | ||
| ) | ||
| test_metric_name = "Data_Marketplace/PROD/Miso_5min/ILLINOIS_HUB_lmp" | ||
| print("\nGetting modeling metrics data as Arrow...") | ||
| arrow_data = cvec.get_modeling_metrics_data_arrow(names=[test_metric_name]) | ||
| reader = ipc.open_file(io.BytesIO(arrow_data)) | ||
| table = reader.read_all() | ||
| print(f"Arrow table shape: {len(table)} rows") | ||
| print("\nFirst few rows:") | ||
| for i in range(min(5, len(table))): | ||
| print( | ||
| f"- {table['name'][i].as_py()}: {table['value_double'][i].as_py() or table['value_string'][i].as_py()} at {table['time'][i].as_py()}" | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from cvec import CVec | ||
| import os | ||
| from datetime import datetime, timedelta | ||
|
|
||
|
|
||
| def main() -> None: | ||
| cvec = CVec( | ||
| host=os.environ.get("CVEC_HOST", "https://your-subdomain.cvector.dev"), | ||
| api_key=os.environ.get("CVEC_API_KEY", "your-api-key"), | ||
| ) | ||
| end_date = datetime.now() | ||
| start_date = end_date - timedelta(hours=3) | ||
| print("\nGetting modeling metrics data...") | ||
| modeling_data = cvec.get_modeling_metrics_data( | ||
| names=["Data_Marketplace/PROD/Miso_5min/ILLINOIS_HUB_lmp"], | ||
| start_at=start_date, | ||
| end_at=end_date, | ||
| ) | ||
| print(f"Found {len(modeling_data)} data points") | ||
|
|
||
| if modeling_data: | ||
| print("\nFirst few data points:") | ||
| for i, point in enumerate(modeling_data[:5]): | ||
| print( | ||
| f"- {point.name}: {point.value_double or point.value_string} at {point.time}" | ||
| ) | ||
|
|
||
| if len(modeling_data) > 5: | ||
| print(f"... and {len(modeling_data) - 5} more data points") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| from cvec import CVec | ||
| import os | ||
|
|
||
|
|
||
| def main() -> None: | ||
| cvec = CVec( | ||
| host=os.environ.get("CVEC_HOST", "https://your-subdomain.cvector.dev"), | ||
| api_key=os.environ.get("CVEC_API_KEY", "your-api-key"), | ||
| ) | ||
| print("\nGetting available modeling metrics...") | ||
| modeling_metrics = cvec.get_modeling_metrics() | ||
| print(f"Found {len(modeling_metrics)} modeling metrics") | ||
| for metric in modeling_metrics: | ||
| print(f"- {metric.name}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| from .metric import Metric, MetricDataPoint | ||
| from .span import Span | ||
|
|
||
| __all__ = ["Metric", "MetricDataPoint", "Span"] | ||
| __all__ = [ | ||
| "Metric", | ||
| "MetricDataPoint", | ||
| "Span", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| """ | ||
| Tests for the modeling functionality in the CVec client. | ||
| """ | ||
|
|
||
| import pytest | ||
| from datetime import datetime | ||
| from unittest.mock import Mock, patch | ||
|
|
||
|
|
||
| from cvec.cvec import CVec | ||
|
|
||
|
|
||
| class TestModelingMethods: | ||
| """Test the modeling methods in the CVec class.""" | ||
|
|
||
| @patch("cvec.cvec.CVec._fetch_publishable_key") | ||
| @patch("cvec.cvec.CVec._login_with_supabase") | ||
| @patch("cvec.cvec.CVec._make_request") | ||
| def test_get_modeling_metrics( | ||
| self, mock_make_request: Mock, mock_login: Mock, mock_fetch_key: Mock | ||
| ) -> None: | ||
| """Test get_modeling_metrics method.""" | ||
| # Mock the publishable key fetch | ||
| mock_fetch_key.return_value = "test_publishable_key" | ||
|
|
||
| # Mock the login method | ||
| mock_login.return_value = None | ||
|
|
||
| # Mock the response | ||
| mock_response = [ | ||
| { | ||
| "id": 1, | ||
| "name": "test_metric", | ||
| "birth_at": "2024-01-01T12:00:00", | ||
| "death_at": None, | ||
| } | ||
| ] | ||
| mock_make_request.return_value = mock_response | ||
|
|
||
| # Create CVec instance | ||
| cvec = CVec( | ||
| host="http://test.com", api_key="cva_test12345678901234567890123456789012" | ||
| ) | ||
|
|
||
| # Call the method | ||
| start_date = datetime(2024, 1, 1, 12, 0, 0) | ||
| end_date = datetime(2024, 1, 1, 13, 0, 0) | ||
| result = cvec.get_modeling_metrics( | ||
| start_at=start_date, | ||
| end_at=end_date, | ||
| ) | ||
|
|
||
| # Verify the result | ||
| assert isinstance(result, list) | ||
| assert len(result) == 1 | ||
| assert result[0].id == 1 | ||
| assert result[0].name == "test_metric" | ||
|
|
||
| # Verify the request was made correctly | ||
| mock_make_request.assert_called_once() | ||
| call_args = mock_make_request.call_args | ||
| assert call_args[0][0] == "GET" | ||
| assert call_args[0][1] == "/api/modeling/metrics" | ||
| assert call_args[1]["params"]["start_at"] == "2024-01-01T12:00:00" | ||
| assert call_args[1]["params"]["end_at"] == "2024-01-01T13:00:00" | ||
|
|
||
| @patch("cvec.cvec.CVec._fetch_publishable_key") | ||
| @patch("cvec.cvec.CVec._login_with_supabase") | ||
| @patch("cvec.cvec.CVec._make_request") | ||
| def test_get_modeling_metrics_data( | ||
| self, mock_make_request: Mock, mock_login: Mock, mock_fetch_key: Mock | ||
| ) -> None: | ||
| """Test get_modeling_metrics_data method.""" | ||
| # Mock the publishable key fetch | ||
| mock_fetch_key.return_value = "test_publishable_key" | ||
|
|
||
| # Mock the login method | ||
| mock_login.return_value = None | ||
|
|
||
| # Mock the response | ||
| mock_response = [ | ||
| { | ||
| "name": "test_metric", | ||
| "time": "2024-01-01T12:00:00", | ||
| "value_double": 42.5, | ||
| "value_string": None, | ||
| } | ||
| ] | ||
| mock_make_request.return_value = mock_response | ||
|
|
||
| # Create CVec instance | ||
| cvec = CVec( | ||
| host="http://test.com", api_key="cva_test12345678901234567890123456789012" | ||
| ) | ||
|
|
||
| # Call the method | ||
| start_date = datetime(2024, 1, 1, 12, 0, 0) | ||
| end_date = datetime(2024, 1, 1, 13, 0, 0) | ||
| result = cvec.get_modeling_metrics_data( | ||
| names=["test_metric"], | ||
| start_at=start_date, | ||
| end_at=end_date, | ||
| ) | ||
|
|
||
| # Verify the result | ||
| assert isinstance(result, list) | ||
| assert len(result) == 1 | ||
| assert result[0].name == "test_metric" | ||
| assert result[0].value_double == 42.5 | ||
|
|
||
| # Verify the request was made correctly | ||
| mock_make_request.assert_called_once() | ||
| call_args = mock_make_request.call_args | ||
| assert call_args[0][0] == "GET" | ||
| assert call_args[0][1] == "/api/modeling/metrics/data" | ||
| assert call_args[1]["params"]["names"] == "test_metric" | ||
| assert call_args[1]["params"]["start_at"] == "2024-01-01T12:00:00" | ||
| assert call_args[1]["params"]["end_at"] == "2024-01-01T13:00:00" | ||
|
|
||
| @patch("cvec.cvec.CVec._fetch_publishable_key") | ||
| @patch("cvec.cvec.CVec._login_with_supabase") | ||
| @patch("cvec.cvec.CVec._make_request") | ||
| def test_get_modeling_metrics_data_arrow( | ||
| self, mock_make_request: Mock, mock_login: Mock, mock_fetch_key: Mock | ||
| ) -> None: | ||
| """Test get_modeling_metrics_data_arrow method.""" | ||
| # Mock the publishable key fetch | ||
| mock_fetch_key.return_value = "test_publishable_key" | ||
|
|
||
| # Mock the login method | ||
| mock_login.return_value = None | ||
|
|
||
| # Mock the response (Arrow data as bytes) | ||
| mock_response = b"fake_arrow_data" | ||
| mock_make_request.return_value = mock_response | ||
|
|
||
| # Create CVec instance | ||
| cvec = CVec( | ||
| host="http://test.com", api_key="cva_test12345678901234567890123456789012" | ||
| ) | ||
|
|
||
| # Call the method | ||
| start_date = datetime(2024, 1, 1, 12, 0, 0) | ||
| end_date = datetime(2024, 1, 1, 13, 0, 0) | ||
| result = cvec.get_modeling_metrics_data_arrow( | ||
| names=["test_metric"], | ||
| start_at=start_date, | ||
| end_at=end_date, | ||
| ) | ||
|
|
||
| # Verify the result | ||
| assert isinstance(result, bytes) | ||
| assert result == b"fake_arrow_data" | ||
|
|
||
| # Verify the request was made correctly | ||
| mock_make_request.assert_called_once() | ||
| call_args = mock_make_request.call_args | ||
| assert call_args[0][0] == "GET" | ||
| assert call_args[0][1] == "/api/modeling/metrics/data/arrow" | ||
| assert call_args[1]["params"]["names"] == "test_metric" | ||
| assert call_args[1]["params"]["start_at"] == "2024-01-01T12:00:00" | ||
| assert call_args[1]["params"]["end_at"] == "2024-01-01T13:00:00" | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| pytest.main([__file__]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.