Skip to content

Commit ab52385

Browse files
authored
Merge pull request #246 from ecmwf-projects/feature/costing-classes
Allow for str type costs
2 parents 5a64d72 + 99f51e9 commit ab52385

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

cads_processing_api_service/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def verify_if_disabled(disabled_reason: str | None, user_role: str | None) -> No
341341

342342
def verify_cost(
343343
request: dict[str, Any], adaptor_properties: dict[str, Any], request_origin: str
344-
) -> dict[str, float] | None:
344+
) -> dict[str, float | str] | None:
345345
"""Verify if the cost of a process execution request is within the allowed limits.
346346
347347
Parameters

cads_processing_api_service/costing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,16 @@ def compute_highest_cost_limit_ratio(
143143
Info on the cost with the highest cost/limit ratio.
144144
"""
145145
costs = costing_info.costs
146+
costs_numeric = {
147+
cost_id: cost
148+
for cost_id, cost in costs.items()
149+
if isinstance(cost, (int, float))
150+
}
146151
limits = costing_info.limits
147152
highest_cost_limit_ratio = 0.0
148153
highest_cost = models.RequestCost()
149154
for limit_id, limit in limits.items():
150-
cost = costs.get(limit_id, 0.0)
155+
cost = costs_numeric.get(limit_id, 0.0)
151156
cost_limit_ratio = cost / limit if limit > 0 else 1.1
152157
if cost_limit_ratio > highest_cost_limit_ratio:
153158
highest_cost_limit_ratio = cost_limit_ratio
@@ -184,17 +189,12 @@ def compute_costing(
184189
costs: dict[str, Any] = adaptor.estimate_costs(
185190
request=request, cost_threshold=cost_threshold
186191
)
187-
costs_numeric = {
188-
cost_id: cost
189-
for cost_id, cost in costs.items()
190-
if isinstance(cost, (int, float))
191-
}
192192
costing_config: dict[str, Any] = adaptor_properties["config"].get("costing", {})
193193
limits: dict[str, Any] = costing_config.get("max_costs", {})
194194
cost_bar_steps = (
195195
costing_config.get("cost_bar_steps", None) if request_origin == "ui" else None
196196
)
197197
costing_info = models.CostingInfo(
198-
costs=costs_numeric, limits=limits, cost_bar_steps=cost_bar_steps
198+
costs=costs, limits=limits, cost_bar_steps=cost_bar_steps
199199
)
200200
return costing_info

cads_processing_api_service/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Exception(ogc_api_processes_fastapi.models.Exception):
7878

7979

8080
class CostingInfo(pydantic.BaseModel):
81-
costs: dict[str, float] = {}
81+
costs: dict[str, float | str] = {}
8282
limits: dict[str, float] = {}
8383
cost_bar_steps: list[int] | None = None
8484

0 commit comments

Comments
 (0)