Skip to content

Commit

Permalink
Merge pull request #854 from rtdip/develop
Browse files Browse the repository at this point in the history
v0.13.1
  • Loading branch information
GBBBAS authored Jan 13, 2025
2 parents 1bbe8fb + 94ef54a commit 8e73d96
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 124 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/stale_issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Close inactive issues
on:
schedule:
- cron: "30 1 * * *"

jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
days-before-issue-stale: 30
days-before-issue-close: 14
stale-issue-label: "stale"
stale-issue-message: "This issue is stale because it has been open for 30 days with no activity."
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale."
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![PyPI version](https://img.shields.io/pypi/v/rtdip-sdk.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/rtdip-sdk/)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/rtdip-sdk.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/rtdip-sdk/)
[![PyPI downloads](https://img.shields.io/pypi/dm/rtdip-sdk.svg)](https://pypistats.org/packages/rtdip-sdk)
![PyPI Downloads](https://static.pepy.tech/badge/rtdip-sdk)
[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7557/badge)](https://bestpractices.coreinfrastructure.org/projects/7557)
[![Code Style Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Expand Down Expand Up @@ -115,4 +116,4 @@ Distributed under the Apache License Version 2.0. See [LICENSE.md](https://githu
* Check previous questions and answers or ask new ones on our slack channel [**#rtdip**](https://lfenergy.slack.com/archives/C0484R9Q6A0)

### Community
* Chat with other community members by joining the **#rtdip** Slack channel. [Click here to join our slack community](https://lfenergy.slack.com/archives/C0484R9Q6A0)
* Chat with other community members by joining the **#rtdip** Slack channel. [Click here to join our slack community](https://lfenergy.slack.com/archives/C0484R9Q6A0)
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ def _sample_query(parameters_dict: dict) -> tuple:
"`{{ business_unit|lower }}`.`sensors`.`{{ asset|lower }}_{{ data_security_level|lower }}_events_{{ data_type|lower }}` "
"{% endif %}"
"{% if case_insensitivity_tag_search is defined and case_insensitivity_tag_search == true %}"
"WHERE `{{ timestamp_column }}` BETWEEN to_timestamp(\"{{ start_date }}\") AND to_timestamp(\"{{ end_date }}\") AND UPPER(`{{ tagname_column }}`) IN ('{{ tag_names | join('\\', \\'') | upper }}') "
"WHERE `{{ timestamp_column }}` BETWEEN to_timestamp(\"{{ start_date }}\") AND timestampadd({{ time_interval_unit }}, {{ time_interval_rate }}, to_timestamp(\"{{ end_date }}\")) AND UPPER(`{{ tagname_column }}`) IN ('{{ tag_names | join('\\', \\'') | upper }}') "
"{% else %}"
"WHERE `{{ timestamp_column }}` BETWEEN to_timestamp(\"{{ start_date }}\") AND to_timestamp(\"{{ end_date }}\") AND `{{ tagname_column }}` IN ('{{ tag_names | join('\\', \\'') }}') "
"WHERE `{{ timestamp_column }}` BETWEEN to_timestamp(\"{{ start_date }}\") AND timestampadd({{ time_interval_unit }}, {{ time_interval_rate }}, to_timestamp(\"{{ end_date }}\")) AND `{{ tagname_column }}` IN ('{{ tag_names | join('\\', \\'') }}') "
"{% endif %}"
"{% if include_status is defined and include_status == true and include_bad_data is defined and include_bad_data == false %} AND `{{ status_column }}` <> 'Bad' {% endif %}) "
',date_array AS (SELECT explode(sequence(from_utc_timestamp(to_timestamp("{{ start_date }}"), "{{ time_zone }}"), from_utc_timestamp(to_timestamp("{{ end_date }}"), "{{ time_zone }}"), INTERVAL \'{{ time_interval_rate + \' \' + time_interval_unit }}\')) AS timestamp_array) '
",window_buckets AS (SELECT timestamp_array AS window_start, timestampadd({{time_interval_unit }}, {{ time_interval_rate }}, timestamp_array) AS window_end FROM date_array) "
",window_buckets AS (SELECT timestamp_array AS window_start, timestampadd({{ time_interval_unit }}, {{ time_interval_rate }}, timestamp_array) AS window_end FROM date_array) "
",resample AS (SELECT /*+ RANGE_JOIN(d, {{ range_join_seconds }} ) */ d.window_start, d.window_end, e.`{{ tagname_column }}`, {{ agg_method }}(e.`{{ value_column }}`) OVER (PARTITION BY e.`{{ tagname_column }}`, d.window_start ORDER BY e.`{{ timestamp_column }}` ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS `{{ value_column }}` FROM window_buckets d INNER JOIN raw_events e ON d.window_start <= e.`{{ timestamp_column }}` AND d.window_end > e.`{{ timestamp_column }}`) "
",project AS (SELECT window_start AS `{{ timestamp_column }}`, `{{ tagname_column }}`, `{{ value_column }}` FROM resample GROUP BY window_start, `{{ tagname_column }}`, `{{ value_column }}` "
"{% if is_resample is defined and is_resample == true %}"
Expand Down
18 changes: 9 additions & 9 deletions tests/api/v1/test_api_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
RawResponse,
)
from pandas.io.json import build_table_schema
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport
from src.api.v1 import app
from src.api.v1.common import json_response_batch
from src.sdk.python.rtdip_sdk.queries.time_series import batch
Expand Down Expand Up @@ -87,7 +87,7 @@ async def test_api_batch_single_get_success(mocker: MockerFixture):
mock_lookup = "src.api.v1.batch.lookup_before_get"
mocked_lookup_before_get = mocker.patch(mock_lookup, return_value=None)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -175,7 +175,7 @@ async def test_api_batch_single_get_success_with_lookup(mocker: MockerFixture):
mock_lookup = "src.api.v1.batch.lookup_before_get"
mocked_lookup_before_get = mocker.patch(mock_lookup, return_value=test_data)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -255,7 +255,7 @@ async def test_api_batch_single_post_success(mocker: MockerFixture):
# Make a surveillance batch method reference to check if called and what args with
surveillance_batch = mocker.patch(mock_method, return_value=mock_method_return_data)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -300,7 +300,7 @@ async def test_api_batch_single_get_unsupported_route_error(mocker: MockerFixtur
os.environ, {"DATABRICKS_SERVING_ENDPOINT": MOCK_MAPPING_ENDPOINT_URL}
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -343,7 +343,7 @@ async def test_api_batch_single_post_missing_body_error(mocker: MockerFixture):
os.environ, {"DATABRICKS_SERVING_ENDPOINT": MOCK_MAPPING_ENDPOINT_URL}
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -406,7 +406,7 @@ async def test_api_batch_multiple_success(mocker: MockerFixture):
# Make a surveillance batch method reference to check if called and what args with
surveillance_batch = mocker.patch(mock_method, side_effect=mock_patch_side_effect)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -464,7 +464,7 @@ async def test_api_batch_one_success_one_fail(mocker: MockerFixture):
os.environ, {"DATABRICKS_SERVING_ENDPOINT": MOCK_MAPPING_ENDPOINT_URL}
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -515,7 +515,7 @@ async def test_api_batch_one_success_one_fail(mocker: MockerFixture):
os.environ, {"DATABRICKS_SERVING_ENDPOINT": MOCK_MAPPING_ENDPOINT_URL}
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down
20 changes: 10 additions & 10 deletions tests/api/v1/test_api_circular_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
MOCK_TAG_MAPPING_EMPTY,
MOCK_MAPPING_ENDPOINT_URL,
)
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport
from src.api.v1 import app

MOCK_METHOD = "src.sdk.python.rtdip_sdk.queries.time_series.circular_average.get"
Expand All @@ -42,7 +42,7 @@
async def test_api_circular_average_get_success(mocker: MockerFixture, api_test_data):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -59,7 +59,7 @@ async def test_api_circular_average_get_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -82,7 +82,7 @@ async def test_api_circular_average_get_error(mocker: MockerFixture, api_test_da
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -97,7 +97,7 @@ async def test_api_circular_average_get_error(mocker: MockerFixture, api_test_da
async def test_api_circular_average_post_success(mocker: MockerFixture, api_test_data):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -115,7 +115,7 @@ async def test_api_circular_average_post_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -139,7 +139,7 @@ async def test_api_circular_average_post_error(mocker: MockerFixture, api_test_d
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -182,7 +182,7 @@ async def test_api_circular_average_get_lookup_success(mocker: MockerFixture):
modified_param_dict = CIRCULAR_AVERAGE_MOCKED_PARAMETER_DICT.copy()
del modified_param_dict["business_unit"]

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.get(
MOCK_API_NAME, headers=TEST_HEADERS, params=modified_param_dict
)
Expand Down Expand Up @@ -228,7 +228,7 @@ async def test_api_circular_average_post_lookup_success(mocker: MockerFixture):
modified_param_dict = CIRCULAR_AVERAGE_MOCKED_PARAMETER_DICT.copy()
del modified_param_dict["business_unit"]

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down Expand Up @@ -278,7 +278,7 @@ async def test_api_circular_average_get_lookup_no_tag_map_error(mocker: MockerFi
modified_param_dict["tagname"] = ["NonExistentTag"]
del modified_param_dict["business_unit"]

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
actual = await ac.get(
MOCK_API_NAME, headers=TEST_HEADERS, params=modified_param_dict
)
Expand Down
14 changes: 7 additions & 7 deletions tests/api/v1/test_api_circular_standard_deviation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
TEST_HEADERS,
BASE_URL,
)
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport
from src.api.v1 import app

MOCK_METHOD = (
Expand All @@ -41,7 +41,7 @@ async def test_api_circular_standard_deviation_get_success(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -58,7 +58,7 @@ async def test_api_circular_standard_deviation_get_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -83,7 +83,7 @@ async def test_api_circular_standard_deviation_get_error(
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -100,7 +100,7 @@ async def test_api_circular_standard_deviation_post_success(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -118,7 +118,7 @@ async def test_api_circular_standard_deviation_post_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -144,7 +144,7 @@ async def test_api_circular_standard_deviation_post_error(
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down
14 changes: 7 additions & 7 deletions tests/api/v1/test_api_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
TEST_HEADERS,
BASE_URL,
)
from httpx import AsyncClient
from httpx import AsyncClient, ASGITransport
from src.api.v1 import app

MOCK_METHOD = "src.sdk.python.rtdip_sdk.queries.time_series.interpolate.get"
Expand All @@ -37,7 +37,7 @@
async def test_api_interpolate_get_success(mocker: MockerFixture, api_test_data):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -54,7 +54,7 @@ async def test_api_interpolate_get_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -77,7 +77,7 @@ async def test_api_interpolate_get_error(mocker: MockerFixture, api_test_data):
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.get(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -92,7 +92,7 @@ async def test_api_interpolate_get_error(mocker: MockerFixture, api_test_data):
async def test_api_interpolate_post_success(mocker: MockerFixture, api_test_data):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -110,7 +110,7 @@ async def test_api_interpolate_post_validation_error(
):
mocker = mocker_setup(mocker, MOCK_METHOD, api_test_data["mock_data_agg"])

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand All @@ -134,7 +134,7 @@ async def test_api_interpolate_post_error(mocker: MockerFixture, api_test_data):
Exception("Error Connecting to Database"),
)

async with AsyncClient(app=app, base_url=BASE_URL) as ac:
async with AsyncClient(transport=ASGITransport(app=app), base_url=BASE_URL) as ac:
response = await ac.post(
MOCK_API_NAME,
headers=TEST_HEADERS,
Expand Down
Loading

0 comments on commit 8e73d96

Please sign in to comment.