in deepracer_offroad_ws/webserver_pkg/webserver_pkg/models.py [0:0]
def validate_action_space(action_space, action_space_type):
"""Helper method that validates the action space for specific action space type.
Args:
action_space (dict): Dictionary with the action space information.
action_space_type (ActionSpaceTypes): ActionSpaceTypes enum value indicating
action space type.
Returns:
bool: True if the action space and action space type combinatino is valid
else False.
"""
valid_action_space = True
if action_space_type == constants.ActionSpaceTypes.discrete:
for action_dict in action_space:
if (constants.ModelMetadataKeys.STEERING not in action_dict
or constants.ModelMetadataKeys.SPEED not in action_dict):
valid_action_space = False
break
elif action_space_type == constants.ActionSpaceTypes.continuous:
if (constants.ModelMetadataKeys.STEERING not in action_space
or constants.ModelMetadataKeys.SPEED not in action_space):
valid_action_space = False
else:
steering_action_dict = action_space[constants.ModelMetadataKeys.STEERING]
speed_action_dict = action_space[constants.ModelMetadataKeys.SPEED]
if (constants.ModelMetadataKeys.CONTINUOUS_HIGH not in steering_action_dict
or constants.ModelMetadataKeys.CONTINUOUS_LOW not in steering_action_dict
or constants.ModelMetadataKeys.CONTINUOUS_HIGH not in speed_action_dict
or constants.ModelMetadataKeys.CONTINUOUS_LOW not in speed_action_dict
or steering_action_dict[constants.ModelMetadataKeys.CONTINUOUS_HIGH]
<= steering_action_dict[constants.ModelMetadataKeys.CONTINUOUS_LOW]
or speed_action_dict[constants.ModelMetadataKeys.CONTINUOUS_HIGH]
<= speed_action_dict[constants.ModelMetadataKeys.CONTINUOUS_LOW]):
valid_action_space = False
return valid_action_space