changed api according to specification
This commit is contained in:
parent
5e46e8068a
commit
d468732040
6 changed files with 150 additions and 58 deletions
|
@ -1,4 +1,4 @@
|
|||
from typing import Dict, Tuple
|
||||
from typing import Dict, Tuple, List
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
@ -59,6 +59,7 @@ class Seeding:
|
|||
class Position:
|
||||
"""Datastructure for holding a position
|
||||
"""
|
||||
|
||||
def __init__(self, x, y, degrees):
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
@ -68,46 +69,51 @@ class Position:
|
|||
class DoubleElim:
|
||||
"""Class used for communicating with double elimination api
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def get_position() -> Position:
|
||||
def get_position() -> Tuple[Position, int]:
|
||||
"""Get position of the robot
|
||||
|
||||
:return: A Position object with robot position
|
||||
:rtype: Position
|
||||
:rtype: Tuple[Position, int]
|
||||
"""
|
||||
response = json.loads(requests.get(API_URL_GET_POS).content)
|
||||
Logging.get_logger().debug(f"DoubleElim.get_position = {response}")
|
||||
return Position(response["x"], response["y"], response["degrees"])
|
||||
res = requests.get(API_URL_GET_POS)
|
||||
response = json.loads(res.content)
|
||||
Logging.get_logger().debug(f"DoubleElim.get_position = {response}, status code = {res.status_code}")
|
||||
return Position(response["x"], response["y"], response["degrees"]), res.status_code
|
||||
|
||||
@staticmethod
|
||||
def get_opponent() -> Position:
|
||||
def get_opponent() -> Tuple[Position, int]:
|
||||
"""Get position of the opponents robot
|
||||
|
||||
:return: A Position object with opponents robot position
|
||||
:rtype: Position
|
||||
:rtype: Tuple[Position, int]
|
||||
"""
|
||||
response = json.loads(requests.get(API_URL_GET_OP).content)
|
||||
Logging.get_logger().debug(f"DoubleElim.get_opponent = x:{response}")
|
||||
return Position(response["x"], response["y"], response["degrees"])
|
||||
res = requests.get(API_URL_GET_OP)
|
||||
response = json.loads(res.content)
|
||||
Logging.get_logger().debug(f"DoubleElim.get_opponent = x:{response}, status code = {res.status_code}")
|
||||
return Position(response["x"], response["y"], response["degrees"]), res.status_code
|
||||
|
||||
@staticmethod
|
||||
def get_goal() -> Position:
|
||||
def get_goal() -> Tuple[Position, int]:
|
||||
"""Get position of the goal
|
||||
|
||||
:return: A Position object with x and y coordinates of the goal, rotation is always -1
|
||||
:rtype: Position
|
||||
:rtype: Tuple[Position, int]
|
||||
"""
|
||||
response = json.loads(requests.get(API_URL_GET_GOAL).content)
|
||||
Logging.get_logger().debug(f"DoubleElim.get_goal = x:{response}")
|
||||
return Position(response["x"], response["y"], -1)
|
||||
res = requests.get(API_URL_GET_GOAL)
|
||||
response = json.loads(res.content)
|
||||
Logging.get_logger().debug(f"DoubleElim.get_goal = {response}, status code = {res.status_code}")
|
||||
return Position(response["x"], response["y"], -1), res.status_code
|
||||
|
||||
@staticmethod
|
||||
def get_items() -> list:
|
||||
def get_items() -> Tuple[List[Dict], int]:
|
||||
"""Get a list with all current items
|
||||
|
||||
:return: A list will all items currently on the game field. Items are dictionaries that look like: {"id": 0}
|
||||
:rtype: list
|
||||
: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]
|
||||
"""
|
||||
result = json.loads(requests.get(API_URL_GET_ITEMS).content)
|
||||
Logging.get_logger().debug(f"DoubleElim.get_items = {result}")
|
||||
return result
|
||||
res = requests.get(API_URL_GET_ITEMS)
|
||||
response = json.loads(res.content)
|
||||
Logging.get_logger().debug(f"DoubleElim.get_items = {response}, status code = {res.status_code}")
|
||||
return response, res.status_code
|
||||
|
|
Reference in a new issue