Skip to content
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

Dev 349 v2 #43

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/sc_keeper/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"):
Expand All @@ -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
6 changes: 6 additions & 0 deletions src/sc_keeper/routers/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_traffic_price_filters(text: str, request: Request) -> dict:
"""Extract TrafficPrice JSON filters from freetext."""
return assister(text, "/traffic_prices")
3 changes: 2 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_healthcheck():
]

test_traffic_prices_params = [
{"direction": ["inbound", "outbound"]},
*test_general_params,
*test_region_params,
{"direction": ["inbound"]},
Expand Down Expand Up @@ -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:
Expand Down
Loading