Skip to content

Commit

Permalink
Reset player error fix(#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoiv authored Apr 4, 2024
1 parent 6818b87 commit 78caccb
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 15 deletions.
8 changes: 4 additions & 4 deletions backend/model/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ async def cancel_player_orders(cls, player_id):
"""
values = {
"player_id": player_id,
"new_order_status": OrderStatus.USER_CANCELLED,
"order_status": OrderStatus.ACTIVE,
"new_order_status": OrderStatus.USER_CANCELLED.value,
"order_status": OrderStatus.ACTIVE.value,
}
await database.fetch_val(query, values)
values = {
"player_id": player_id,
"new_order_status": OrderStatus.PENDING,
"order_status": OrderStatus.CANCELLED,
"new_order_status": OrderStatus.PENDING.value,
"order_status": OrderStatus.CANCELLED.value,
}
await database.fetch_val(query, values)

Expand Down
4 changes: 4 additions & 0 deletions testing/algotrade_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def create_player(self, player_name: str = None):
params={"team_secret": self.team_secret},
json={"player_name": player_name})

def reset_player(self):
return requests.get(f"http://{self.URL}/game/{self.game_id}/player/{self.player_id}/reset",
params={"team_secret": self.team_secret})

def get_player(self):
return requests.get(f"http://{self.URL}/game/{self.game_id}/player/{self.player_id}",
params={"team_secret": self.team_secret})
Expand Down
133 changes: 122 additions & 11 deletions testing/cheat_sheet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "25d31bcd-1861-4583-ac64-45f421e99440",
"metadata": {},
"outputs": [],
Expand All @@ -16,56 +16,167 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "b5b58cce-d433-4f3d-8f84-42aae47ee77e",
"metadata": {},
"outputs": [],
"source": [
"url = \"localhost:3000\"\n",
"\n",
"team_secret = \"gogi\"\n",
"game_id = 1\n",
"game_id = 2\n",
"player_id = -1 # we will get this later\n",
"\n",
"api = AlgotradeApi(url, team_secret, game_id, player_id)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "0d4836fb-959d-45d5-9f99-29e6134dfe94",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'detail': 'Only one player per team can be created in contest mode'}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"api.create_player().json()"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"id": "91d9cb44-25bb-4a43-b2b0-ac6df285ba21",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"api.get_players().json()[0]['player_id']"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "bbb3dd0d-44cc-4bc8-a446-ee2364d0740f",
"metadata": {},
"outputs": [],
"source": [
"api.set_player_id(11)"
"api.set_player_id(1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"id": "c38850b8-d12f-4d22-adea-c4ed86aef7d3",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'player_id': 1,\n",
" 'player_name': 'Goranov_tim_1',\n",
" 'game_id': 2,\n",
" 'energy_price': 1000000000,\n",
" 'money': 50000000,\n",
" 'coal': 0,\n",
" 'uranium': 0,\n",
" 'biomass': 0,\n",
" 'gas': 0,\n",
" 'oil': 0,\n",
" 'coal_plants_owned': 0,\n",
" 'uranium_plants_owned': 0,\n",
" 'biomass_plants_owned': 0,\n",
" 'gas_plants_owned': 0,\n",
" 'oil_plants_owned': 0,\n",
" 'geothermal_plants_owned': 0,\n",
" 'wind_plants_owned': 0,\n",
" 'solar_plants_owned': 0,\n",
" 'hydro_plants_owned': 0,\n",
" 'coal_plants_powered': 0,\n",
" 'uranium_plants_powered': 0,\n",
" 'biomass_plants_powered': 0,\n",
" 'gas_plants_powered': 0,\n",
" 'oil_plants_powered': 0,\n",
" 'geothermal_plants_powered': 0,\n",
" 'wind_plants_powered': 0,\n",
" 'solar_plants_powered': 0,\n",
" 'hydro_plants_powered': 0}"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"api.get_player().json()"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"id": "2be0fa5c-6ad7-4b31-b73b-dd573d291851",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'detail': 'Players cannot be reset in contest mode'}"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"api.reset_player().json()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "6b0d2f54-8518-4490-9270-427986507a6b",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'game_id': 1,\n",
" 'game_name': 'Stalna igra',\n",
" 'is_contest': False,\n",
" 'start_time': '2024-04-05T00:09:47.217932',\n",
" 'total_ticks': 2300,\n",
" 'tick_time': 3000,\n",
" 'current_tick': 0,\n",
" 'is_finished': False,\n",
" 'current_time': '2024-04-05T00:08:56.800435',\n",
" 'next_tick_time': '2024-04-05T00:09:47.217932'}"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"api.get_game().json()"
]
Expand Down

0 comments on commit 78caccb

Please sign in to comment.