You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import random
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import Delete, Select
|
|
|
|
from src.auth.service import CurrentUser
|
|
from src.database.core import DbSession
|
|
from src.scope_equipment.model import ScopeEquipment
|
|
from src.scope_equipment.service import get_by_scope_name
|
|
|
|
|
|
async def get_all_budget_constrains(
|
|
*, db_session: DbSession, scope_name: str, cost_threshold: float = 100.0
|
|
):
|
|
"""Get all overhaul overview with EAF values that sum to 100%."""
|
|
equipments = await get_by_scope_name(db_session=db_session, scope_name=scope_name)
|
|
|
|
# If no equipments found, return empty list
|
|
if not equipments:
|
|
return []
|
|
# Create result array of dictionaries
|
|
result = [
|
|
{
|
|
"id": equipment.id,
|
|
"assetnum": equipment.assetnum,
|
|
"location_tag": equipment.master_equipment.location_tag,
|
|
"name": equipment.master_equipment.name,
|
|
"total_cost": 1000000 + random.randint(10000, 5000000),
|
|
}
|
|
for equipment in equipments
|
|
]
|
|
|
|
result.sort(key=lambda x: x["total_cost"], reverse=True)
|
|
|
|
# Filter equipment up to threshold
|
|
cumulative_cost = 0
|
|
filtered_result = []
|
|
|
|
for equipment in result:
|
|
cumulative_cost += equipment["total_cost"]
|
|
|
|
if cumulative_cost >= cost_threshold:
|
|
break
|
|
|
|
filtered_result.append(equipment)
|
|
|
|
return filtered_result
|