Skip to content

estimator_routes

routes.estimator_routes

EstimatorResource

Bases: Resource

Class responsible for retreving estimator names

Source code in yaptide/routes/estimator_routes.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class EstimatorResource(Resource):
    """Class responsible for retreving estimator names"""

    class APIParametersSchema(Schema):
        """Class specifies API parameters"""

        job_id = fields.String()

    @staticmethod
    @requires_auth()
    def get(user: UserModel):
        """Method returning estimator names for specific simulation"""
        schema = EstimatorResource.APIParametersSchema()
        errors: dict[str, list[str]] = schema.validate(request.args)
        if errors:
            return yaptide_response(message="Wrong parameters", code=400, content=errors)
        param_dict: dict = schema.load(request.args)

        job_id = param_dict['job_id']

        is_owned, error_message, res_code = check_if_job_is_owned_and_exist(job_id=job_id, user=user)
        if not is_owned:
            return yaptide_response(message=error_message, code=res_code)

        estimator_names = fetch_estimator_names_by_job_id(job_id=job_id)

        if not estimator_names:
            return yaptide_response(message="Estimators not found", code=404)

        return yaptide_response(message="List of estimator names for specific simulation",
                                code=200,
                                content={"estimator_names": estimator_names})

APIParametersSchema

Bases: Schema

Class specifies API parameters

Source code in yaptide/routes/estimator_routes.py
15
16
17
18
class APIParametersSchema(Schema):
    """Class specifies API parameters"""

    job_id = fields.String()
job_id class-attribute instance-attribute
job_id = String()

get staticmethod

get(user)

Method returning estimator names for specific simulation

Source code in yaptide/routes/estimator_routes.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@staticmethod
@requires_auth()
def get(user: UserModel):
    """Method returning estimator names for specific simulation"""
    schema = EstimatorResource.APIParametersSchema()
    errors: dict[str, list[str]] = schema.validate(request.args)
    if errors:
        return yaptide_response(message="Wrong parameters", code=400, content=errors)
    param_dict: dict = schema.load(request.args)

    job_id = param_dict['job_id']

    is_owned, error_message, res_code = check_if_job_is_owned_and_exist(job_id=job_id, user=user)
    if not is_owned:
        return yaptide_response(message=error_message, code=res_code)

    estimator_names = fetch_estimator_names_by_job_id(job_id=job_id)

    if not estimator_names:
        return yaptide_response(message="Estimators not found", code=404)

    return yaptide_response(message="List of estimator names for specific simulation",
                            code=200,
                            content={"estimator_names": estimator_names})