Exemplo n.º 1
0
class TaskStructureCreateFields:
    common_fields = dict(temperature=Float(298), pressure=Float(1),
                         description=ListDefault(Nested(DescriptionFields.resource_fields), default=[]))
    additives_field = dict(additives=ListDefault(Nested(AdditiveFields.resource_fields), default=[]))
    data_field = dict(data=String)

    resource_fields = dict(**common_fields, **additives_field, **data_field)
Exemplo n.º 2
0
class TaskStructureResponseFields:
    """
    data structure which returned as response
    """
    resource_fields = dict(models=ListDefault(Nested(ModelResponseFields.resource_fields), default=[]),
                           additives=ListDefault(Nested(AdditiveResponseFields.resource_fields), default=[]),
                           status=TypeResponseField, type=TypeResponseField, **TaskStructureFields.common_fields)
Exemplo n.º 3
0
class RecordStructureResponseFields:
    """
    full structure-metadata record
    """
    resource_fields = dict(
        data=MRV(attribute='structure.structure'),
        temperature=Float(298, attribute='data.temperature'),
        pressure=Float(1, attribute='data.pressure'),
        description=ListDefault(Nested(DescriptionFields.resource_fields),
                                default=[],
                                attribute='data.description'),
        additives=ListDefault(Nested(AdditiveRecordFields.resource_fields),
                              default=[],
                              attribute='data.additives'),
        **RecordResponseFields.resource_fields)
Exemplo n.º 4
0
class TaskStructureModelFields:
    structure_field = dict(structure=Integer)
    to_delete_fields = dict(todelete=Boolean(False))
    models_field = dict(models=ListDefault(Nested(ModelFields.resource_fields), default=[]))

    resource_fields = dict(**structure_field, **to_delete_fields, **models_field,
                           **TaskStructureCreateFields.common_fields, **TaskStructureCreateFields.additives_field)
Exemplo n.º 5
0
class RecordStructureFields:
    """
    data structure which got from jobs task. used for converting data from tasks format to CGRdb records.
    """
    common_fields = dict(additives=ListDefault(Nested(
        AdditiveResponseFields.resource_fields),
                                               default=[]),
                         **TaskStructureCreateFields.common_fields)
    resource_fields = dict(data=Structure, **common_fields)
Exemplo n.º 6
0
class ModelResponseFields:
    common_fields = dict(type=TypeResponseField, description=String, **ModelFields.resource_fields)
    resource_fields = dict(results=ListDefault(Nested(ModelResultResponseFields.resource_fields), default=[]),
                           **common_fields)
Exemplo n.º 7
0
class ModelRegisterFields:
    resource_fields = dict(name=String, type=type_field_factory(ModelType),
                           destinations=List(Nested(DestinationFields.resource_fields)),
                           example=Nested(TaskStructureCreateFields.resource_fields))
Exemplo n.º 8
0
class ModelMagicResponseFields:
    """
    response about available models
    """
    resource_fields = dict(example=Nested(TaskStructureMagicResponseFields.resource_fields),
                           **ModelResponseFields.common_fields)
Exemplo n.º 9
0
class TaskGetResponseFields:
    """
    response for get query with preparation or modeling results
    """
    resource_fields = dict(structures=ListDefault(Nested(TaskStructureResponseFields.resource_fields), default=[]),
                           **TaskPostResponseFields.resource_fields)
Exemplo n.º 10
0
 def __init__(self, data_field=None, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self["code"] = Integer(default=0)
     self["message"] = String(default="success")
     self["data"] = Nested(data_field, default={})
Exemplo n.º 11
0

auth_field = {'access_token': String, 'refresh_token': String}

user_field = {
    "uid": Integer,
    "email": String,
    "sex": Integer,
    "introduction": String,
    "lock": Boolean,
    "pageBgc": String,
    "avatar": String,
    "username": String
}
user_register_field = {"email": String, "uid": Integer}
email_field = {'email': String}

friends = {"friends": List(Integer), "current": Integer, "pages": Integer}
UserList = {
    "users": List(Nested(user_field)),
    "current": Integer,
    "pages": Integer
}
auth_response = ResponseField(auth_field)
user_response = ResponseField(user_field)
email_response = ResponseField(email_field)
user_register_response = ResponseField(user_register_field)
friendsRes = ResponseField(friends)
userListRes = ResponseField(UserList)
randomUserRes = ResponseField({"users": List(Nested(user_field))})
Exemplo n.º 12
0
from flask_restful import fields
from flask_restful.fields import Nested

room_structure = {'number': fields.Integer}

staff_structure = {'name': fields.String, 'rooms': Nested(room_structure)}
Exemplo n.º 13
0
log_fields_running = {
    "jobName": String(attribute="job_name"),
    "jobCmd": String(attribute="job_cmd"),
    "startDate": DateTime(attribute="start_date", dt_format="iso8601"),
    "endDate": DateTime(attribute="end_date", dt_format="iso8601"),
    "returnCode": Integer(attribute="return_code"),
    "stdout": String,
    "stderr": String
}

logs_fields_running = {
    "status": Integer,
    "msg": String,
    "total": Integer,
    "data": List(Nested(log_fields_running))
}


class LogResource(Resource):
    def get(self, job_name):
        args = parser_logs.parse_args()
        total = args.total

        error, data, len_data = "", "", 0
        try:
            if total <= 1:
                # 查询单个job_name最新的运行日志
                data = RunningLog.query.filter(
                    RunningLog.job_name == job_name).order_by(
                        -RunningLog.id).first()
Exemplo n.º 14
0
from App.apis.admin.utils import login_check
from App.apis.api_constant import HTTP_OK
from App.models.ciname_admin import CinemaUser
parse = reqparse.RequestParser()
parse.add_argument('is_verify', type=bool, required=True, help="请提供操作")
ciname_user_fileds = {
    'id': fields.Integer,
    'name': fields.String,
    '_password': fields.String,
    'phone': fields.String,
    'is_verify': fields.Boolean,
}
list_cinema_user_fileds = {
    'msg': fields.String,
    'status': fields.Integer,
    'data': fields.List(Nested(ciname_user_fileds))
}
single_cinema_user_fileds = {
    'msg': fields.String,
    'status': fields.Integer,
    'data': fields.Nested(ciname_user_fileds)
}


class AdminCinemaUsersResource(Resource):
    @login_check
    def get(self):
        ciname_user = CinemaUser.query.all()
        data = {
            'status': HTTP_OK,
            'msg': 'ok',
Exemplo n.º 15
0
from ..fields import ResponseField
from flask_restful.fields import Integer, Raw, List, Boolean, Nested

Lock_fields = {'uid': Integer, 'lock': Boolean()}

Locks_fields = {'users': List(Nested(Lock_fields))}
LockRes = ResponseField(Locks_fields)
Exemplo n.º 16
0
class MeasurementResource(ResourceBase):

    db_table = Measurement

    measurement_file = {
        "label": String,
        "path": String(
            attribute=lambda x: "files/measurement/{}/{}".format(
                x.measurement_id, x.path
            )
        ),
    }

    fields = {
        "id": Integer,
        "label": String,
        "start_date": String,
        "end_date": String,
        "meta_data": Raw,
        "files": List(Nested(measurement_file)),
        "jobs": List(IDField),
    }

    def get(self, id_):
        """
        Receive a measurement
        ---
        summary: Find a measurement by ID
        tags:
            - measurements
        parameters:
            -   name: id
                in: path
                description: ID of measurement to return
                required: true
                schema:
                    type: integer
        responses:
            200:
                description: successful operation
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Measurement"
            400:
                description: Invalid ID supplied
            404:
                description: Measurement not found
        """
        try:
            resource = self.get_resource(id_)
        except (ResourceInvalidInputException, ResourceNotFoundException) as e:
            return {"status": str(e)}, e.response_code
        return self.dump_resource(resource), 200

    def delete(self, id_):
        """
        Delete a measurement
        ---
        summary: Deletes a measurement
        tags:
            - measurements
        parameters:
            -   name: id
                in: path
                description: ID of measurement to return
                required: true
                schema:
                    type: integer
        responses:
            200:
                description: Measurement deleted and returned
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Measurement"
            400:
                description: Invalid ID supplied
            404:
                description: Measurement not found
            405:
                description: Cannot delete measurement associated with a job
        """
        try:
            resource = self.get_resource(id_)
        except (ResourceInvalidInputException, ResourceNotFoundException) as e:
            return {"status": str(e)}, e.response_code

        try:
            return self.delete_resource(
                current_app.config["MEASUREMENT_FILES_FOLDER"], resource
            )
        except ResourceForbiddenActionException as e:
            return {"status": str(e)}, e.response_code

    def put(self, id_):
        """
        Update the basic information about a measurement
        ---
        summary: Updates a measurement with new data
        tags:
            - measurements
        parameters:
            -   name: id
                in: path
                description: ID of measurement to return
                required: true
                schema:
                    type: integer
        requestBody:
            content:
                multipart/form-data:
                    schema:
                        properties:
                            start_date:
                              type: string
                              format: date-time
                            end_date:
                                type: string
                                format: date-time
                            label:
                                type: string
                            meta_data:
                                type: string
        responses:
            200:
                description: Measurement updated and returned
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Measurement"
            400:
                description: Invalid ID supplied or invalid input
            404:
                description: Measurement not found
        """

        try:
            resource = self.get_resource(id_)
        except (ResourceInvalidInputException, ResourceNotFoundException) as e:
            return {"status": str(e)}, e.response_code

        try:
            self._update_measurement(resource)
        except ResourceInvalidInputException as e:
            return {"status": str(e)}, e.response_code
        return self.dump_resource(resource), 200

    def _update_measurement(self, resource):
        start_date, end_date = self.parse_dates(
            str(resource.start_date), str(resource.end_date)
        )
        resource.start_date = start_date
        resource.end_date = end_date
        resource.label = request.form.get("label", resource.label)
        self.load_metadata(request.form.get("meta_data", "{}"), resource)
        db.session.commit()

    @staticmethod
    def parse_dates(start=None, end=None):
        try:
            start_date = date_parser(request.form.get("start_date", start))
            end_date = date_parser(request.form.get("end_date", end))
        except ValueError as e:
            raise ResourceInvalidInputException(str(e))

        if end_date < start_date:
            raise ResourceInvalidInputException("end date < start date")
        return start_date, end_date
Exemplo n.º 17
0
class JobResource(ResourceBase):

    db_table = Job

    job_inputfile = {
        "label": String,
        "value": String(attribute=lambda x: make_input_value(x)),
    }

    job_outputfile = {
        "label":
        String,
        "path":
        String(attribute=lambda x: "files/job/{}/output/{}".format(
            x.job.id, x.path)),
    }

    fields = {
        "id":
        Integer,
        "label":
        String,
        "date":
        String(attribute=lambda x: x.date.strftime("%Y-%m-%d %H:%M")),
        "status":
        String,
        "log":
        String(attribute=lambda x: "files/job/{}/{}".format(x.id, x.log)
               if x.log else ""),
        "analysis":
        IDField,
        "measurement":
        IDField,
        "input":
        List(Nested(job_inputfile)),
        "table_output":
        List(Nested(job_outputfile)),
        "figure_output":
        List(Nested(job_outputfile)),
        "reports":
        List(JobReportFile),
    }

    def get(self, id_):
        """
        Receive a job
        ---
        summary: Find a job by ID
        tags:
            - jobs
        parameters:
            -   name: id
                in: path
                description: ID of job to return
                required: true
                schema:
                    type: integer
        responses:
            200:
                description: successful operation
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Job"
            400:
                description: Invalid ID supplied
            404:
                description: Job not found
        """
        try:
            resource = self.get_resource(id_)
        except (ResourceInvalidInputException, ResourceNotFoundException) as e:
            return {"status": str(e)}, e.response_code
        return self.dump_resource(resource), 200

    def delete(self, id_):
        """
        Delete a job
        ---
        summary: Deletes a job
        tags:
            - jobs
        parameters:
            -   name: id
                in: path
                description: ID of job to delete
                required: true
                schema:
                    type: integer
        responses:
            200:
                description: Job deleted and returned
                content:
                    application/json:
                        schema:
                            $ref: "#/components/schemas/Job"
            400:
                description: Invalid ID supplied
            404:
                description: Job not found
        """
        try:
            resource = self.get_resource(id_)
        except (ResourceInvalidInputException, ResourceNotFoundException) as e:
            return {"status": str(e)}, e.response_code

        try:
            return self.delete_resource(current_app.config["JOB_FILES_FOLDER"],
                                        resource)
        except ResourceForbiddenActionException as e:
            return {"status": str(e)}, e.response_code
Exemplo n.º 18
0
parser_put.add_argument("desc", dest="desc", type=str, help="请输入任务描述")

# ============================================== [ parser done ] ==============================================
post_fields = {
    "jobName": String(attribute="job_name"),
    "job_type": String(attribute="job_type"),
    "jobCmd": String(attribute="job_cmd"),
    "timeStyle": String(attribute="time_style"),
    "timeData": String(attribute="time_data")
}

posts_fields = {
    "status": Integer,
    "msg": String,
    "total": Integer,
    "data": List(Nested(post_fields))
}

job_fields = {
    "jobName": String(attribute="job_name"),
    "jobType": String(attribute="job_type"),
    "jobCmd": String(attribute="job_cmd"),
    "timeStyle": String(attribute="time_style"),
    "timeData": String(attribute="time_data"),
    "nextRunTime": DateTime(attribute="next_run_time", dt_format="iso8601"),
    "category": String(attribute="category"),
    "file": String(attribute="file_name", default=""),
    "comment": String(attribute="desc"),
}

jobs_fields = {
Exemplo n.º 19
0
    'uid': Integer,
    'tid': Integer,
    "cid": Integer,
    'liked': Boolean(default=False),
    'likes': Integer,
    'parent': Integer,
    "ancestor": Integer,
    "avatar": StaticUrl,
    "sex": Integer,
    "username": String
}
replycomments = commentsField.copy()
replycomments["parentUID"] = Integer
GroupField = {
    "gid": Integer,
    "ancestor": Nested(commentsField),
    "members": List(Nested(replycomments)),
    "pages": Integer,
    "current": Integer
}

replyField = GroupField
commentList = {
    "groups": List(Nested(GroupField))
}
replyListField = {
    'replies': List(Nested(replyField)),
    "current": Integer,
    "pages": Integer
}