Skip to content

Commit

Permalink
add default params to each behaviour - dispatcher adds them to DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Ctri-The-Third committed Jan 19, 2024
1 parent 2180a4f commit 8f82eca
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 3 deletions.
6 changes: 6 additions & 0 deletions behaviours/chain_trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ def __init__(

self.target_sys_symbol = behaviour_params.get("target_sys", None)

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["target_sys"] = "X1-TEST"

return return_obj

def run(self):
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
Expand Down
2 changes: 1 addition & 1 deletion behaviours/chill_and_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
session,
connection,
)
self.target_wp_s = behaviour_params["asteroid_wp"]
self.target_wp_s = behaviour_params.get("asteroid_wp", None)

def default_params_obj(self):
return_obj = super().default_params_obj()
Expand Down
21 changes: 21 additions & 0 deletions behaviours/extract_and_sell.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,29 @@ def __init__(
self
self.logger = logging.getLogger("bhvr_extract_and_sell")

def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["asteroid_wp"] = "X1-PK16-AB12"
return_obj["cargo_to_transfer"] = ["*"]
return_obj["fulfil_wp"] = "X1-TEST-F99"

return return_obj

def run(self):
super().run()
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
self.ship.name,
self.agent.credits,
behaviour_params=self.behaviour_params,
)

self._run()
self.end()

def run(self):
# all threads should have this.

starting_credts = self.agent.credits
Expand Down
6 changes: 6 additions & 0 deletions behaviours/manage_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,21 @@ def __init__(
self.agent = self.st.view_my_self()
self.logger = logging.getLogger(BEHAVIOUR_NAME)

def default_params_obj(self):
return_obj = super().default_params_obj()
return return_obj

def run(self):
super().run()
self.ship = self.st.ships_view_one(self.ship_name)
self.sleep_until_ready()
self.st.logging_client.log_beginning(
BEHAVIOUR_NAME,
self.ship.name,
self.agent.credits,
behaviour_params=self.behaviour_params,
)

self._run()
self.end()

Expand Down
1 change: 0 additions & 1 deletion behaviours/monitor_cheapest_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def __init__(
session,
connection,
)
self

def default_params_obj(self):
return_obj = super().default_params_obj()
Expand Down
2 changes: 2 additions & 0 deletions behaviours/receive_and_refine.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def __init__(
def default_params_obj(self):
return_obj = super().default_params_obj()
return_obj["asteroid_wp"] = "X1-PK16-AB12"
return_obj["cargo_to_transfer"] = ["*"]

return return_obj

def run(self):
Expand Down
5 changes: 5 additions & 0 deletions behaviours/sell_or_jettison_all_cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def __init__(

self.logger = logging.getLogger(BEHAVIOUR_NAME)

def default_params_obj(self):
return_obj = super().default_params_obj()

return return_obj

def run(self):
super().run()
self.sleep_until_ready()
Expand Down
12 changes: 12 additions & 0 deletions dispatcherWK25.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def run(self):

scan_thread = threading.Thread(target=self.maybe_scan_all_systems, daemon=True)
scan_thread.start()

self.upload_behaviour_definitions()
# ships_and_threads["scan_thread"].start()
startime = datetime.now()
while not self.exit_flag:
Expand Down Expand Up @@ -425,6 +427,16 @@ def map_behaviour_to_class(
bhvr = behaviours_and_classes[id](aname, sname, bhvr_params)
return bhvr

def upload_behaviour_definitions(self):
for behaviour_id, bhvr_class in behaviours_and_classes.items():
bhvr_obj = bhvr_class("", "", {})
bhvr_obj: Behaviour

params = json.dumps(bhvr_obj.default_params_obj())
sql = "insert into behaviour_definitions (behaviour_id, default_params) values (%s, %s) on conflict (behaviour_id) do update set default_params = EXCLUDED.default_params;"
try_execute_upsert(sql, (behaviour_id, params), self.connection)
pass

def maybe_scan_all_systems(self):
ships = self.client.ships_view()
ship = list(ships.values())[0]
Expand Down
2 changes: 1 addition & 1 deletion spacetraders_sdk

0 comments on commit 8f82eca

Please sign in to comment.