From ec9161ef94404d674f80af66d8a130a07930ac19 Mon Sep 17 00:00:00 2001 From: "Gergely Daroczi (@daroczig)" Date: Wed, 11 Sep 2024 16:06:42 +0200 Subject: [PATCH 1/6] default to outbound prices --- src/sc_keeper/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sc_keeper/api.py b/src/sc_keeper/api.py index 4a4250e..8e534f1 100644 --- a/src/sc_keeper/api.py +++ b/src/sc_keeper/api.py @@ -7,7 +7,7 @@ from fastapi import Depends, FastAPI, HTTPException, Response from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.gzip import GZipMiddleware -from sc_crawler.table_fields import Status +from sc_crawler.table_fields import Status, TrafficDirection from sc_crawler.tables import ( Benchmark, ComplianceFramework, @@ -683,7 +683,7 @@ def search_traffic_prices( green_energy: options.green_energy = None, regions: options.regions = None, countries: options.countries = None, - direction: options.direction = None, + direction: options.direction = TrafficDirection.OUT, monthly_traffic: options.monthly_traffic = 1, limit: options.limit = 50, page: options.page = None, From cbd23aa60033ff8eb06014d57eb375834d2cd291 Mon Sep 17 00:00:00 2001 From: "Gergely Daroczi (@daroczig)" Date: Wed, 11 Sep 2024 16:08:22 +0200 Subject: [PATCH 2/6] round monthly traffic price --- src/sc_keeper/api.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/sc_keeper/api.py b/src/sc_keeper/api.py index 8e534f1..3cfb3b3 100644 --- a/src/sc_keeper/api.py +++ b/src/sc_keeper/api.py @@ -753,11 +753,11 @@ def search_traffic_prices( # update prices per tiers and to currency requested for price in prices: + def rounder(p): + return round(p, 6) + def local_price(p): - return round( - currency_converter.convert(p, price.currency, currency), - 6, - ) + return rounder(currency_converter.convert(p, price.currency, currency)) if currency: if hasattr(price, "price") and hasattr(price, "currency"): @@ -774,9 +774,9 @@ def local_price(p): max(monthly_traffic - traffic_paid, 0), (float(tier.upper) - float(tier.lower)), ) - price.price_monthly_traffic += tier.price * traffic_tier + price.price_monthly_traffic += rounder(tier.price * traffic_tier) traffic_paid += traffic_tier else: - price.price_monthly_traffic = price.price * monthly_traffic + price.price_monthly_traffic = rounder(price.price * monthly_traffic) return prices From 4ca89f2ca19a2e544930b056ed2ae8d9450477e4 Mon Sep 17 00:00:00 2001 From: "Gergely Daroczi (@daroczig)" Date: Wed, 11 Sep 2024 16:19:43 +0200 Subject: [PATCH 3/6] missed AI endpoint for traffic prices --- src/sc_keeper/routers/ai.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sc_keeper/routers/ai.py b/src/sc_keeper/routers/ai.py index a13be20..6c33609 100644 --- a/src/sc_keeper/routers/ai.py +++ b/src/sc_keeper/routers/ai.py @@ -38,3 +38,9 @@ def assist_server_price_filters(text: str, request: Request) -> dict: def assist_storage_price_filters(text: str, request: Request) -> dict: """Extract StoragePrice JSON filters from freetext.""" return assister(text, "/storage_prices") + + +@router.get("/assist_traffic_price_filters") +def assist_storage_price_filters(text: str, request: Request) -> dict: + """Extract TrafficPrice JSON filters from freetext.""" + return assister(text, "/traffic_prices") From 1e171ffffd5c001a97bce76b69f23df5505fbe52 Mon Sep 17 00:00:00 2001 From: "Gergely Daroczi (@daroczig)" Date: Wed, 11 Sep 2024 16:23:29 +0200 Subject: [PATCH 4/6] fix default value should be a list --- src/sc_keeper/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sc_keeper/api.py b/src/sc_keeper/api.py index 3cfb3b3..043d1d5 100644 --- a/src/sc_keeper/api.py +++ b/src/sc_keeper/api.py @@ -683,7 +683,7 @@ def search_traffic_prices( green_energy: options.green_energy = None, regions: options.regions = None, countries: options.countries = None, - direction: options.direction = TrafficDirection.OUT, + direction: options.direction = [TrafficDirection.OUT], monthly_traffic: options.monthly_traffic = 1, limit: options.limit = 50, page: options.page = None, From f11d6bf124f5ff547a7f1a1dbe759b4a04f61e43 Mon Sep 17 00:00:00 2001 From: "Gergely Daroczi (@daroczig)" Date: Wed, 11 Sep 2024 16:23:39 +0200 Subject: [PATCH 5/6] update all traffic records case --- tests/test_api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_api.py b/tests/test_api.py index 3f84dca..4137403 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -79,6 +79,7 @@ def test_healthcheck(): ] test_traffic_prices_params = [ + {"direction": ["inbound", "outbound"]}, *test_general_params, *test_region_params, {"direction": ["inbound"]}, @@ -243,7 +244,7 @@ def test_traffic_prices_with_params(params): assert response.status_code == 200 assert response.elapsed.total_seconds() < 5 # if params is empty, this is the full count - if params == {}: + if params == {"direction": ["inbound", "outbound"]}: global count count = len(response.json()) else: From 73d718aee5742227206d08bb85c3e99417aca4de Mon Sep 17 00:00:00 2001 From: "Gergely Daroczi (@daroczig)" Date: Wed, 11 Sep 2024 16:54:45 +0200 Subject: [PATCH 6/6] fix dupe fn name --- src/sc_keeper/routers/ai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sc_keeper/routers/ai.py b/src/sc_keeper/routers/ai.py index 6c33609..ca60e0d 100644 --- a/src/sc_keeper/routers/ai.py +++ b/src/sc_keeper/routers/ai.py @@ -41,6 +41,6 @@ def assist_storage_price_filters(text: str, request: Request) -> dict: @router.get("/assist_traffic_price_filters") -def assist_storage_price_filters(text: str, request: Request) -> dict: +def assist_traffic_price_filters(text: str, request: Request) -> dict: """Extract TrafficPrice JSON filters from freetext.""" return assister(text, "/traffic_prices")