Skip to content

Commit

Permalink
update schema and DB sections, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ctri-The-Third committed Mar 10, 2024
1 parent 0439156 commit f81e860
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 90 deletions.
20 changes: 13 additions & 7 deletions PostgresSchema.SQL
Original file line number Diff line number Diff line change
Expand Up @@ -1863,16 +1863,22 @@ ALTER VIEW public.ship_cooldown OWNER TO spacetraders;
-- Name: ship_frame_links; Type: TABLE; Schema: public; Owner: spacetraders
--

CREATE TABLE public.ship_frame_links (
ship_symbol text NOT NULL,
frame_symbol text NOT NULL,
condition numeric,
integrity numeric
-- Table: public.ship_frame_links

);
-- DROP TABLE IF EXISTS public.ship_frame_links;

CREATE TABLE IF NOT EXISTS public.ship_frame_links
(
ship_symbol text COLLATE pg_catalog."default" NOT NULL,
frame_symbol text COLLATE pg_catalog."default" NOT NULL,
condition numeric,
integrity numeric,
CONSTRAINT ship_frame_links_pkey PRIMARY KEY (ship_symbol, frame_symbol)
)


ALTER TABLE public.ship_frame_links OWNER TO spacetraders;
ALTER TABLE IF EXISTS public.ship_frame_links
OWNER to spacetraders;

--
-- TOC entry 277 (class 1259 OID 16714)
Expand Down
2 changes: 1 addition & 1 deletion straders_sdk/models_ship.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(self) -> None:
self.role: str = ""
self.faction: str = ""
self.nav = ShipNav("", "", "", None, None, None, "", "")
self.frame = ShipFrame("", "", "", 0, 0, 0, 0, ShipRequirements(0, 0, 0))
self.frame = ShipFrame("", "", "", 0, 0, 0, 0, 0, ShipRequirements(0, 0, 0))
self.reactor = ShipReactor("", "", "", 0, 0, ShipRequirements(0, 0, 0))
self.engine = ShipEngine("", "", "", 0, 0, ShipRequirements(0, 0, 0))
self.crew_capacity: int = 0
Expand Down
145 changes: 69 additions & 76 deletions straders_sdk/pg_pieces/select_ship.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
def _select_ships(agent_name, db_client: SpaceTradersClient):
sql = """select s.ship_symbol, s.agent_name, s.faction_symbol, s.ship_role, s.cargo_capacity, s.cargo_in_use
, n.waypoint_symbol, n.departure_time, n.arrival_time, n.o_waypoint_symbol, n.d_waypoint_symbol, n.flight_status, n.flight_mode
, sfl.condition --13
, sfl.condition, sfl.integrity --13
, sf.frame_symbol, sf.name, sf.description, sf.module_slots, sf.mount_points, sf.fuel_capacity, sf.required_power, sf.required_crew, sf.required_slots
, s.fuel_capacity, s.fuel_current --24
, sc.expiration, sc.total_seconds --26
, n.o_waypoint_symbol, o.type, o.system_symbol, o.x, o.y --31
, n.d_waypoint_symbol, d.type, n.system_symbol, d.x, d.y --37
, s.mount_symbols, s.module_symbols --39
, s.fuel_capacity, s.fuel_current --25
, sc.expiration, sc.total_seconds --27
, n.o_waypoint_symbol, o.type, o.system_symbol, o.x, o.y --32
, n.d_waypoint_symbol, d.type, n.system_symbol, d.x, d.y --38
, s.mount_symbols, s.module_symbols --40
from ships s join ship_nav n on s.ship_symbol = n.ship_symbol
left join ship_frame_links sfl on s.ship_symbol = sfl.ship_symbol
Expand All @@ -37,14 +39,13 @@ def _select_ships(agent_name, db_client: SpaceTradersClient):
def _select_ship_one(ship_symbol: str, db_client: SpaceTradersClient):
sql = """select s.ship_symbol, s.agent_name, s.faction_symbol, s.ship_role, s.cargo_capacity, s.cargo_in_use
, n.waypoint_symbol, n.departure_time, n.arrival_time, n.o_waypoint_symbol, n.d_waypoint_symbol, n.flight_status, n.flight_mode
, sfl.condition --13
, sfl.condition, sfl.integrity --13
, sf.frame_symbol, sf.name, sf.description, sf.module_slots, sf.mount_points, sf.fuel_capacity, sf.required_power, sf.required_crew, sf.required_slots
, s.fuel_capacity, s.fuel_current --24
, sc.expiration, sc.total_seconds --26
, n.o_waypoint_symbol, o.type, o.system_symbol, o.x, o.y --31
, n.d_waypoint_symbol, d.type, n.system_symbol, d.x, d.y --37
, s.mount_symbols, s.module_symbols --38
, s.fuel_capacity, s.fuel_current --25
, sc.expiration, sc.total_seconds --27
, n.o_waypoint_symbol, o.type, o.system_symbol, o.x, o.y --32
, n.d_waypoint_symbol, d.type, n.system_symbol, d.x, d.y --38
, s.mount_symbols, s.module_symbols --40
from ships s join ship_nav n on s.ship_symbol = n.ship_symbol
left join ship_frame_links sfl on s.ship_symbol = sfl.ship_symbol
Expand Down Expand Up @@ -113,14 +114,14 @@ def _select_some_ships(db_client: SpaceTradersClient, sql, params):
ship.cargo_inventory = []
# , 6: n.waypoint_symbol, n.departure_time, n.arrival_time, n.origin_waypoint, n.destination_waypoint, n.flight_status, n.flight_mode

ship.nav = _nav_from_row(row[6:13], row[27:37])
ship.frame = _frame_from_row(row[13:24])
ship.fuel_capacity = row[23]
ship.fuel_current = row[24]
ship._cooldown_expiration = row[25]
ship._cooldown_length = row[26]
ship.mounts = row[37]
ship.modules = row[38]
ship.nav = _nav_from_row(row)
ship.frame = _frame_from_row(row)
ship.fuel_capacity = row[24]
ship.fuel_current = row[25]
ship._cooldown_expiration = row[26]
ship._cooldown_length = row[27]
ship.mounts = row[38]
ship.modules = row[39]
ships[ship.name] = ship
ship.mark_clean()

Expand All @@ -134,52 +135,42 @@ def _select_some_ships(db_client: SpaceTradersClient, sql, params):
)


def _nav_from_row(row, nav_row) -> ShipNav:
def _nav_from_row(row) -> ShipNav:
"""
expected:
0: n.waypoint_symbol,
1: n.departure_time,
2: n.arrival_time,
3: n.origin_waypoint,
4: n.destination_waypoint,
5: n.flight_status,
6: n.flight_mode
nav_row
0: origin.waypoint_symbol,
1: origin.type,
2: origin.system_symbol,
3: origin.x,
4: origin.y,
5: destination.waypoint_symbol,
6: destination.type,
7: destination.system_symbol,
8: destination.x,
9: destination.y,
s.ship_symbol, s.agent_name, s.faction_symbol, s.ship_role, s.cargo_capacity, s.cargo_in_use -- 6
, n.waypoint_symbol, n.departure_time, n.arrival_time, n.o_waypoint_symbol, n.d_waypoint_symbol, n.flight_status, n.flight_mode
, sfl.condition, sfl.integrity --13
, sf.frame_symbol, sf.name, sf.description, sf.module_slots, sf.mount_points, sf.fuel_capacity, sf.required_power, sf.required_crew, sf.required_slots
, s.fuel_capacity, s.fuel_current --25
, sc.expiration, sc.total_seconds --27
, n.o_waypoint_symbol, o.type, o.system_symbol, o.x, o.y --32
, n.d_waypoint_symbol, d.type, n.system_symbol, d.x, d.y --38
, s.mount_symbols, s.module_symbols --40
"""

return_obj = ShipNav(
nav_row[7],
nav_row[5],
row[35],
row[6],
RouteNode(
nav_row[5],
nav_row[6],
nav_row[7],
nav_row[8],
nav_row[9],
symbol=row[33],
type=row[35],
systemSymbol=row[36],
x=row[37],
y=row[38],
),
RouteNode(
nav_row[0],
nav_row[1],
nav_row[2],
nav_row[3],
nav_row[4],
symbol=row[10],
type=row[33],
systemSymbol=row[34],
x=row[35],
y=row[36],
),
row[2],
row[1],
row[5],
row[6],
arrival_time=row[8],
departure_time=row[7],
status=row[11],
flight_mode=row[12],
)
# SHIP NAV ENDS

Expand All @@ -188,28 +179,30 @@ def _nav_from_row(row, nav_row) -> ShipNav:

def _frame_from_row(row) -> ShipFrame:
"""
0: sf.frame_symbol,
1: sf.name,
2: sf.description,
3: sf.module_slots,
4: sf.mount_points,
5: sf.fuel_capacity,
6: sf.required_power,
7: sf.required_crew,
8: sf.required_slots,
9: s.fuel_capacity,
10: s.fuel_current,
11: sfl.condition
expected:
s.ship_symbol, s.agent_name, s.faction_symbol, s.ship_role, s.cargo_capacity, s.cargo_in_use -- 6
, n.waypoint_symbol, n.departure_time, n.arrival_time, n.o_waypoint_symbol, n.d_waypoint_symbol, n.flight_status, n.flight_mode
, sfl.condition, sfl.integrity --13
, sf.frame_symbol, sf.name, sf.description, sf.module_slots, sf.mount_points, sf.fuel_capacity, sf.required_power, sf.required_crew, sf.required_slots
, s.fuel_capacity, s.fuel_current --25
, sc.expiration, sc.total_seconds --27
, n.o_waypoint_symbol, o.type, o.system_symbol, o.x, o.y --32
, n.d_waypoint_symbol, d.type, n.system_symbol, d.x, d.y --38
, s.mount_symbols, s.module_symbols --40
"""

##crew moduels power
reqiurements = ShipRequirements(row[8], row[9], row[7])
reqiurements = ShipRequirements(row[21], row[22], row[23])
return_obj = ShipFrame(
row[1], row[2], row[3], row[4], row[5], row[6], row[0], reqiurements
row[15],
row[16],
row[17],
row[18],
row[19],
row[20],
row[13],
row[14],
reqiurements,
)

return return_obj
10 changes: 5 additions & 5 deletions straders_sdk/pg_pieces/upsert_ship.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ def _upsert_ship_frame(ship: Ship, connection):
return resp

"""INSERT INTO public.ship_frame_links(
ship_symbol, frame_symbol, condition)
ship_symbol, frame_symbol, condition, integrity)
VALUES (?, ?, ?);"""
sql = """INSERT INTO ship_frame_links
(ship_symbol, frame_symbol, condition)
VALUES (%s, %s, %s)
ON CONFLICT (ship_symbol, frame_symbol) DO UPDATE set condition = %s;"""
values = (ship.name, ship.frame.symbol, ship.frame.condition, ship.frame.condition)
(ship_symbol, frame_symbol, condition, integrity)
VALUES (%s, %s, %s, %s)
ON CONFLICT (ship_symbol, frame_symbol) DO UPDATE set condition = EXCLUDED.condition, integrity = EXCLUDED.integrity;"""
values = (ship.name, ship.frame.symbol, ship.frame.condition, ship.frame.integrity)
resp = try_execute_upsert(sql, values, connection)
return resp

Expand Down
2 changes: 2 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def test_move():
resp = client.ship_move(ship, wp.symbol)

assert resp
events = resp.data["events"]
assert events


def test_warp():
Expand Down
Loading

0 comments on commit f81e860

Please sign in to comment.