def perturb_light_post(Parameters):
    """
    perturb_light_post
    change the state of a light in the environment
    :param Parameters:
    :type Parameters: dict | bytes

    :rtype: InlineResponse200
    """
    if connexion.request.is_json:
        Parameters = Parameters0.from_dict(connexion.request.get_json())

    if not swagger_server.config.cp.map_server.is_light(Parameters.id):
        ret = InlineResponse4001(rospy.Time.now().secs, "invalid light name")
        return ret, 400

    if swagger_server.config.cp.gazebo.enable_light(Parameters.id,
                                                    Parameters.state):
        ret = InlineResponse200()
        ret.sim_time = rospy.Time.now().secs
        return ret
    else:
        ret = InlineResponse4001(rospy.Time.now().secs,
                                 "light setting failed on: %s" % Parameters)
        return ret, 400
Example #2
0
def filters_group_get(token_info):  # noqa: E501
    """returns information related to the possible filters that can be apply to the groups. Each field contains the name, the type (numeric, textual) and all the values associated to that field (without repetition).

     # noqa: E501

    :rtype: InlineResponse200
    """
    def _make_filter(row):
        return Filter(id=row['field'],
                      type=row['type'],
                      values=dbq.get_group_filter_values(
                          all_groups, row['field']))

    def _make_group(row):
        return Group(group_id=row['groupCode'], description=row['description'])

    try:
        username = token_info['user']

        permissions = dbq.get_user_credentials(username)
        all_groups = permissions['groups']
        group_ids = [_make_group(row) for row in dbq.get_groups(all_groups)]
        filters = [
            _make_filter(row)
            for row in dbq.get_filters(permissions['filters'], 'groups')
        ]

        return InlineResponse200(filters=filters, group_ids=group_ids)
    except Exception as e:
        print(f'{e}', file=sys.stderr)
        raise InternalServerError
Example #3
0
def user_username_get(username):
    """
    Get username
    
    param username: The format to return the response in json.
    :type username: str

    :rtype: InlineResponse200
    """
    cnxn = start_connection()
    cursor = cnxn.cursor()

    tsql = "SELECT \
                CustomerID, \
                FirstName, \
                LastName, \
                EmailAddress \
            FROM SalesLT.Customer \
            WHERE FirstName = '" + username + "';"

    api_response = []
    with cursor.execute(tsql):
        row = cursor.fetchone()
        while row is not None:
            data = InlineResponse200(row.CustomerID, row.FirstName,
                                     row.LastName, row.EmailAddress)
            api_response.append(data)
            row = cursor.fetchone()

    return api_response
Example #4
0
def saved_variables_get(student_code, game_code, version,
                        variable_name):  # noqa: E501
    """Returns the value stored on a game variable named variableName if possible

     # noqa: E501

    :param student_code: code to identify a student
    :type student_code: str
    :param game_code: code to identify a game
    :type game_code: str
    :param version: code to identify the version of a game
    :type version: str
    :param variable_name: code to identify the variable stored on save state
    :type variable_name: str

    :rtype: InlineResponse200
    """
    try:
        queryResult = dbq.get_saved_state(student_code, game_code, version,
                                          variable_name)
    except Exception as e:
        print(f'{e}', file=sys.stderr)
        raise InternalServerError

    if queryResult is not None:
        return InlineResponse200(queryResult)
    else:
        raise NotFound
Example #5
0
def get_auth(UUID=None):
    """
    Provide new UUID
    Provide new ApiKey
    hash api key and store
    :return:
    """
    new_id = False
    if (UUID is None):
        UUID = str(uuid.uuid4())
        new_id = True

    apiKey = str(uuid.uuid4())
    hashed = hashlib.sha256(apiKey.encode()).hexdigest()
    if new_id:
        store_dict = {"UUID": UUID, "apiKey": hashed}
        auth_id = auth_collection.insert_one(store_dict).inserted_id
    else:
        auth_id = auth_collection.find_one_and_update(
            {"UUID": UUID}, {"$set": {
                "apiKey": hashed
            }}, upsert=True)
    app.logger.info("auth id = " + str(auth_id))

    return InlineResponse200(UUID, apiKey)
Example #6
0
def service_regions_get():  # noqa: E501
    """Retrieve a list of all covered regions.

    Retrieve a list of MEC regions, reporting their identifiers and location information. # noqa: E501


    :rtype: InlineResponse200
    """

    regions = md.get_regions()
    ret = []
    for r in regions:
        li = LocationInfo(r.location.latitude, r.location.longitude,
                          r.location.altitude, r.location.range)
        mri = MECRegionInfo(MRI(r.id, li.serialize()))
        ret.append(mri)
    return make_response(jsonify(InlineResponse200(ret)), 200)
def perturbations_get(perturbation_params):  # noqa: E501
    """perturbations_get

    Returns a list of possible perturbations of an (optionally) specified shape and complexity that can be performed at a given line in the program. This endpoint should be used to select a suitable (set of) perturbation(s) for a test scenario. # noqa: E501

    :param perturbation_params:
    :type perturbation_params: dict | bytes

    :rtype: InlineResponse200
    """
    if connexion.request.is_json:
        pp = PerturbationParams.from_dict(
            connexion.request.get_json())  # noqa: E501

    mutations = config.orc.perturbations(filename=pp.file,
                                         line_num=pp.line,
                                         op_name=pp.shape)

    return InlineResponse200([mutation2perturb(m) for m in mutations])
def perturb_place_obstacle_post(Parameters=None):
    """
    perturb_place_obstacle_post
    if the test is running, then place an instance of the obstacle on the map
    :param Parameters:
    :type Parameters: dict | bytes

    :rtype: InlineResponse200
    """
    if connexion.request.is_json:
        PlaceParams = PlaceParams.from_dict(connexion.request.get_json())  # noqa: E501

    result = config.bot_cont.gazebo.place_obstacle(PlaceParams.x, PlaceParams.y)
    if result:
        return InlineResponse200(obstacleid = result, sim_time = rospy.Time.now().secs)
    else:
        ## todo: we can't really distinguish between reasons for
        ## failure here so the API is a little bit too big
        return InlineResponse4001(cause = "other-error", message="obstacle placement failed")
def configuration_get():
    """
    Get Resource Manager Configuration.
    Returns high-level information about the configuration of this Resource Manager.

    :rtype: InlineResponse200
    """

    try:
        cfg = ConfigReader()
        drvName, drvVer = cfg.getDriverNameVersion()
        supportedFeatures = cfg.getSupportedFeatures()
        supportedApiVersions = cfg.getSupportedApiVersions()
        supportedProperties = cfg.getDriverProperties(None)
    except FileNotFoundError:
        abort(404, 'configuration not found')

    resp200 = InlineResponse200(drvName, drvVer, supportedApiVersions,
                                supportedFeatures, supportedProperties)
    return resp200
Example #10
0
def start_post(StartConfiguration):  # noqa: E501
    """start_post

     # noqa: E501

    :param StartConfiguration: 
    :type StartConfiguration: dict | bytes

    :rtype: InlineResponse2001
    """
    global ready
    if connexion.request.is_json:
        sc = SC.from_dict(connexion.request.get_json())  # noqa: E501
    ready = InlineResponse200(sc.start_loc, sc.target_loc, True,
                              sc.configuration, sc.utility)
    global info
    info.robot_configuration = sc.configuration
    # launch docker-compose -f ui-th.yml
    s = subprocess.Popen(["./launch.sh"])
    info.status = "starting"
    return 'Starting th'
Example #11
0
def login(email, password):
    """
    User authentication
    
    :param email: Account email
    :type email: str
    :param password: Account password
    :type password: str

    :rtype: InlineResponse200
    """

    account = db_session.query(Account).filter(
        Account._account_email == email).first()

    if account is None:
        return None, 401

    tokens[account.account_id] = uuid.uuid4().hex
    object = InlineResponse200(account_id=account.account_id,
                               token=tokens[account.account_id])

    return object, 200
    calc_urls: List[str] = []

    for i, url in enumerate(body.urls):
        if rslt := redis.get(url):  # type: ignore
            cached_rslt.append((i, float(rslt.decode())))
            continue

        calc_urls.append(url)
        try:
            text = oneURL2text.oneURL2text(url)
            texts.append(text)
        except Exception as e:
            with open(f"{__main__.DATA_PATH}/error.csv", mode="a") as f:
                f.writelines([str(e), ", ", url, "\n"])
            raise e

    results: List[float] = []
    if len(texts) != 0:
        predictor = util.Predictor()
        results = predictor.predict(texts)

        for i, r in enumerate(results):
            redis.set(calc_urls[i], r)  # type: ignore

    for i, r in cached_rslt:
        results.insert(i, r)

    response = InlineResponse200.from_dict({"results": results})

    return response