Skip to content

Commit

Permalink
fix issues with postgres DB and waypoint orbitals - fix pathfinder su…
Browse files Browse the repository at this point in the history
…pport for waypoint orbitals
  • Loading branch information
Ctri-The-Third committed Mar 7, 2024
1 parent bab62de commit 5ea3c4e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
42 changes: 26 additions & 16 deletions straders_sdk/client_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def waypoints_view(
Either a dict of Waypoint objects or a SpaceTradersResponse object on failure.
"""

sql = """SELECT * FROM waypoints w
sql = """SELECT w.waypoint_symbol, type, system_symbol, x, y --0-4
, checked, modifiers, under_construction, parent_symbol, orbital_symbols --5-9
FROM waypoints w
left join waypoint_charts wc on w.waypoint_symbol = wc.waypoint_symbol
WHERE system_symbol = %s"""
Expand All @@ -206,18 +208,21 @@ def waypoints_view(
"submittedBy": row[7],
"submittedOn": row[8],
}
# orbitals = [{"symbol": o} for o in row[9] or []]

orbitals = [{"symbol": o} for o in row[9] or []]

waypoint = Waypoint(
row[2],
row[0],
row[1],
row[3],
row[4],
[],
traits,
{},
{},
row[6],
row[7],
orbitals=orbitals,
traits=traits,
chart=chart,
modifiers=row[6],
under_construction=row[7],
)
waypoints[waypoint.symbol] = waypoint
return waypoints
Expand Down Expand Up @@ -253,8 +258,15 @@ def waypoints_view_one(
chart_rows = try_execute_select(
chart_sql, (waypoint_symbol,), self.connection
)
orbitals = [{"symbol": o} for o in row[9]]
chart = {"submittedBy": chart_rows[0][1], "submittedOn": chart_rows[0][2]}
if chart_rows:
chart = {
"submittedBy": chart_rows[0][1],
"submittedOn": chart_rows[0][2],
}
else:
chart = {}
orbitals = [{"symbol": o} for o in row[9] or []]

for trait_row in trait_rows:
traits.append(WaypointTrait(trait_row[1], trait_row[2], trait_row[3]))
waypoint = Waypoint(
Expand All @@ -263,13 +275,11 @@ def waypoints_view_one(
row[1],
row[3],
row[4],
row[8],
orbitals,
traits,
chart,
None,
row[6],
row[7],
orbitals=orbitals,
traits=traits,
chart=chart,
modifiers=row[6],
under_construction=row[7],
)
waypoints.append(waypoint)

Expand Down
24 changes: 17 additions & 7 deletions straders_sdk/pathfinder/pathfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,8 @@ def load_system_graph_from_db(self, system_s: str, fuel_capacity=400):
result[1],
result[2],
result[4],
t if result[3] else [],
{},
{},
[],
result[5],
traits=t if result[3] else [],
under_construction=result[5],
)
wayps[result[0]] = wayp

Expand Down Expand Up @@ -517,11 +514,16 @@ def plot_system_nav(
cached_route = self.load_system_nav(start, goal, fuel_capacity)
if cached_route:
return cached_route
if not graph:
if not graph and not force_recalc:
graph = self.load_graph_from_file(
f"resources/systemgraph-{system}({fuel_capacity}).json"
)
if not graph or force_recalc == True:
if (
not graph
or force_recalc == True
or start.symbol not in graph.nodes
or goal.symbol not in graph.nodes
):
graph = self.load_system_graph_from_db(system, fuel_capacity)

self.save_graph(
Expand All @@ -534,6 +536,11 @@ def plot_system_nav(
if not graph:
return None

if start.symbol not in graph.nodes:
return None
if goal.symbol not in graph.nodes:
return None

# f"{destination_folder}{self.start_waypoint.symbol}-{self.end_waypoint.symbol}[{self.max_fuel}].json",

# f-score is the time of the route so far
Expand Down Expand Up @@ -612,6 +619,9 @@ def plot_system_nav(

came_from[neighbour.symbol] = current.symbol
g_score[neighbour.symbol] = tentative_global_score

# g_score is the travel time to the location so far
# f_score is the remaining direct-travel time from the current location to the destination - so lowest f_score should represent the nearest
f_score = tentative_global_score + self.h(
neighbour, goal, fuel_capacity
) # total weight + weight
Expand Down

0 comments on commit 5ea3c4e

Please sign in to comment.