fixed missing api calls and documentation

This commit is contained in:
Joel Klimont 2021-10-01 02:40:16 +02:00
parent c515c0062b
commit d58a41da69
6 changed files with 82 additions and 30 deletions

View file

@ -75,7 +75,7 @@ class Seeding:
return result, res.status_code
@staticmethod
def getCargo(color: str) -> Tuple[Dict, int]:
def get_cargo(color: str) -> Tuple[Dict, int]:
"""Makes the /api/listCargo call to the api.
:param color: Color parameter which specifies which cargo should be taken. (A string which is either "green", "red", "yellow" or "blue"
@ -110,7 +110,7 @@ class DoubleElim:
@staticmethod
def get_position() -> Tuple[Position, int]:
"""Get position of the robot
"""Makes the /api/getPos call to the api.
:return: A Position object with robot position
:rtype: Tuple[Position, int]
@ -127,7 +127,7 @@ class DoubleElim:
@staticmethod
def get_opponent() -> Tuple[Position, int]:
"""Get position of the opponents robot
"""Makes the /api/getOp call to the api.
:return: A Position object with opponents robot position
:rtype: Tuple[Position, int]
@ -144,7 +144,7 @@ class DoubleElim:
@staticmethod
def get_goal() -> Tuple[Position, int]:
"""Get position of the goal
"""Makes the /api/getGoal call to the api.
:return: A Position object with x and y coordinates of the goal, rotation is always -1
:rtype: Tuple[Position, int]
@ -161,7 +161,7 @@ class DoubleElim:
@staticmethod
def get_items() -> Tuple[List[Dict], int]:
"""Get a list with all current items
"""Makes the /api/getItems call to the api.
:return: A list will all items currently on the game field. Items are dictionaries that look like: {"id": 0, "x": 0, "y": 0}
:rtype: Tuple[List[Dict], int]
@ -178,7 +178,7 @@ class DoubleElim:
@staticmethod
def get_scores() -> Tuple[Dict, int]:
"""Get the current scores
"""Makes the /api/getScores call to the api.
:return: A dictionary with all scores included like: {"self":2,"opponent":0}
:rtype: Tuple[Dict, int]
@ -192,3 +192,20 @@ class DoubleElim:
response = json.loads(res.content)
Logging.get_logger().debug(f"DoubleElim.get_scores = {response}, status code = {res.status_code}")
return response, res.status_code
@staticmethod
def get_meteoroid() -> Tuple[Dict, int]:
"""Makes the /api/getMeteoroid call to the api.
:return: A dictionary with all scores included like: {"self":2,"opponent":0}
:rtype: Tuple[Dict, int]
"""
res = requests.get(API_URL_GET_METEOROID)
if res.status_code == 408:
Logging.get_logger().error(f"DoubleElim.get_meteoroid timeout!")
time.sleep(0.01)
return DoubleElim.get_scores()
response = json.loads(res.content)
Logging.get_logger().debug(f"DoubleElim.get_meteoroid = {response}, status code = {res.status_code}")
return response, res.status_code