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
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 estimators metadata 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)

        simulation_id = fetch_simulation_id_by_job_id(job_id=job_id)
        if not simulation_id:
            return yaptide_response(message="Simulation does not exist", code=404)

        estimators = fetch_estimators_by_sim_id(sim_id=simulation_id)
        results = []

        for estimator in estimators:
            pages_metadata = fetch_pages_metadata_by_est_id(est_id=estimator.id)
            estimator_dict = {
                "name":
                estimator.name,
                "pages_metadata": [{
                    "page_number": page[0],
                    "page_name": page[1],
                    "page_dimension": page[2]
                } for page in pages_metadata]
            }
            results.append(estimator_dict)

        if len(results) == 0:
            return yaptide_response(message="Pages metadata not found", code=404)

        return yaptide_response(message="Estimators metadata", code=200, content={"estimators_metadata": results})

APIParametersSchema

Bases: Schema

Class specifies API parameters

Source code in yaptide/routes/estimator_routes.py
16
17
18
19
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 estimators metadata for specific simulation

Source code in yaptide/routes/estimator_routes.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@staticmethod
@requires_auth()
def get(user: UserModel):
    """Method returning estimators metadata 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)

    simulation_id = fetch_simulation_id_by_job_id(job_id=job_id)
    if not simulation_id:
        return yaptide_response(message="Simulation does not exist", code=404)

    estimators = fetch_estimators_by_sim_id(sim_id=simulation_id)
    results = []

    for estimator in estimators:
        pages_metadata = fetch_pages_metadata_by_est_id(est_id=estimator.id)
        estimator_dict = {
            "name":
            estimator.name,
            "pages_metadata": [{
                "page_number": page[0],
                "page_name": page[1],
                "page_dimension": page[2]
            } for page in pages_metadata]
        }
        results.append(estimator_dict)

    if len(results) == 0:
        return yaptide_response(message="Pages metadata not found", code=404)

    return yaptide_response(message="Estimators metadata", code=200, content={"estimators_metadata": results})