From acbf6d6bd6d63ab0e9f7c4e119827f76e0382aac Mon Sep 17 00:00:00 2001 From: kboz Date: Sun, 19 Apr 2026 01:50:32 +0200 Subject: feat(backend): unify boot process and refactor route properties - Added scripts/haul.sh, setup_auth.py, and setup_eve_data.py for simplified SSO and CSV data bootstrapping. - Refactored `Ship` and `RouteStep` properties across route planning modules to utilize dictionaries instead of strict dataclass attributes. - Re-aligned route limits, reducing upfront capital risk values in `arbitrage.py` and updating ship metrics in `manager.py`. - Updated `.gitignore`, `.env.example`, and created AI-assistant prompt configuration. - Added comprehensive "Getting Started" guides to the README and initialized CHANGELOG.md. --- backend/src/route.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'backend/src/route.py') diff --git a/backend/src/route.py b/backend/src/route.py index ec099b1..2bcae7e 100644 --- a/backend/src/route.py +++ b/backend/src/route.py @@ -4,9 +4,10 @@ from typing import Optional from tqdm import tqdm -from graph import Graph +from graph import NavigationGraph as Graph from pathfinder import Ship from arbitrage import Trade +from typing import Any logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -14,13 +15,7 @@ logger = logging.getLogger(__name__) MAX_TRADES_TO_CONSIDER = 20_000 MAX_CAPITAL = 100_000_000 -@dataclass -class RouteStep: - location_id: int - station_name: str - actions: list[dict] = field(default_factory=list) - -Route = list[RouteStep] +Route = list[dict[str, Any]] def route(trades: list[Trade], graph: Graph, ship: Ship) -> tuple[Optional[Route], Optional[dict]]: """ @@ -46,7 +41,7 @@ def route(trades: list[Trade], graph: Graph, ship: Ship) -> tuple[Optional[Route seen_routes = set() for trade in tqdm(trades[:MAX_TRADES_TO_CONSIDER], desc="Evaluating trades"): - route_stations = (ship.location, trade.from_station, trade.to_station) + route_stations = (ship["location"], trade.from_station, trade.to_station) if route_stations in seen_routes: continue @@ -59,7 +54,7 @@ def route(trades: list[Trade], graph: Graph, ship: Ship) -> tuple[Optional[Route continue try: - path = graph.shortest_path(ship.location, trade.from_station)[:-1] + path = graph.shortest_path(ship["location"], trade.from_station)[:-1] path += graph.shortest_path(trade.from_station, trade.to_station) except Exception as e: logger.error(f"Error finding path: {e}") @@ -68,7 +63,7 @@ def route(trades: list[Trade], graph: Graph, ship: Ship) -> tuple[Optional[Route risk = sum(graph.graph[u][v]['risk'] for u, v in zip(path, path[1:])) transport_time = sum(graph.graph[u][v]['time'] for u, v in zip(path, path[1:])) - capital = getattr(ship, 'ship_cost', 0.0) + sum(t.from_price * t.quantity for t in optimized_trades) + capital = ship.get('ship_cost', 0.0) + sum(t.from_price * t.quantity for t in optimized_trades) if transport_time == 0: logger.warning("Transport time is zero, skipping this route to avoid division by zero.") @@ -133,7 +128,7 @@ def select_trades(stations: list[int], trades: list[Trade], ship: Ship) -> list[ from_remaining = used_orders.get(from_order, quantity) to_remaining = used_orders.get(to_order, quantity) - max_quantity_by_cargo = int((ship.cargo - cargo) // trade.item_cargo_volume) + max_quantity_by_cargo = int((ship["cargo"] - cargo) // trade.item_cargo_volume) max_quantity_by_capital = int((MAX_CAPITAL - capital) // trade.from_price) max_quantity = min(quantity, from_remaining, to_remaining, max_quantity_by_cargo, max_quantity_by_capital) @@ -165,7 +160,7 @@ def select_trades(stations: list[int], trades: list[Trade], ship: Ship) -> list[ optimized_trades.append(updated_trade) - if cargo >= ship.cargo or capital >= MAX_CAPITAL: + if cargo >= ship["cargo"] or capital >= MAX_CAPITAL: break return optimized_trades @@ -184,8 +179,8 @@ def set_actions(route: Route, trades: list[Trade]) -> Route: bought_items = set() for trade in trades: for step in route: - if trade.from_station == step.location_id: - step.actions.append({ + if trade.from_station == step["location_id"]: + step["actions"].append({ "action_type": "buy", "item": trade.item_name, "type_id": trade.type_id, @@ -193,8 +188,8 @@ def set_actions(route: Route, trades: list[Trade]) -> Route: "price": trade.from_price, }) bought_items.add(trade.type_id) - if trade.to_station == step.location_id and trade.type_id in bought_items: - step.actions.append({ + if trade.to_station == step["location_id"] and trade.type_id in bought_items: + step["actions"].append({ "action_type": "sell", "item": trade.item_name, "type_id": trade.type_id, @@ -203,6 +198,6 @@ def set_actions(route: Route, trades: list[Trade]) -> Route: }) for step in route: - step.actions.sort(key=lambda action: (action["action_type"], action["item"], action["price"])) + step["actions"].sort(key=lambda action: (action["action_type"], action["item"], action["price"])) return route -- cgit v1.3