Пример #1
0
def mmethods():
    response  = Response()

    schema    = addict.Dict(CONFIG.Pipeline.schema)
    methods   = schema.model

    response.set_data(methods)

    dict_     = response.to_dict()
    json_     = jsonify(dict_)
    code      = response.code

    return json_, code
Пример #2
0
def fmethods():
    response  = Response()

    schema    = addict.Dict(CONFIG.Pipeline.schema)
    methods   = schema.feature_selection

    response.set_data(methods)

    dict_     = response.to_dict()
    json_     = jsonify(dict_)
    code      = response.code

    return json_, code
Пример #3
0
def pmethods():
    response  = Response()

    path      = os.path.join(R.Path.DATA, 'preprocess-methods.json')
    methods   = JSON.read(path)

    response.set_data(methods)

    dict_     = response.to_dict()
    json_     = jsonify(dict_)
    code      = response.code

    return json_, code
Пример #4
0
def resource(
        path=None,
        level=None,  # provide an exhaustive search
        filter_=['CDATA', 'CEL']):
    response = Response()

    startdir = assign_if_none(path, CONFIG.App.STARTDIR)

    tree = discover_resource(path=startdir, level=level, filter_=filter_)

    response.set_data(tree)

    dict_ = response.to_dict()
    json_ = jsonify(dict_)
    code = response.code

    return json_, code
Пример #5
0
def write(output = { 'name': '', 'path': '', 'format': None }):
    response     = Response()

    parameters   = addict.Dict(request.get_json())

    if parameters.output:
        output   = addict.Dict(merge_dicts(output, parameters.output))

    output.path  = os.path.join(ABSPATH_STARTDIR, output.path)
    output.name  = output.name.strip() # remove padding spaces

    buffer_      = parameters.buffer

    if output.format:
        if   output.format == 'cdata':
             handler = cdata

             if output.name in ['', '.cdata', '.CDATA']:
                name = get_timestamp_str('CDAT%Y%m%d%H%M%S.cdata')
             else:
                name = output.name

             output.name = name
        elif output.format == 'pipeline':
             handler = pipeline

             if output.name in ['', '.cpipe', '.CPIPE']:
                name = get_timestamp_str('PIPE%Y%m%d%H%M%S.cpipe')
             else:
                name = output.name

             output.name = name

             if not buffer_:
                buffer_  = [ ]

    opath        = os.path.join(output.path, output.name)

    try:
        handler.write(opath, buffer_)

        data          = addict.Dict()
        data.output   = output
        
        # These anomalies are confusing moi. Kindly check the difference between readers, writers and loaders and make it uniform.
        if output.format == 'cdata':
            cdat      = handler.read(opath)
            data.data = cdat.to_dict()
        else:
            data.data = handler.read(opath)

        response.set_data(data)
    except TypeError as e:
        response.set_error(Response.Error.UNPROCESSABLE_ENTITY)

    dict_      = response.to_dict()
    json_      = jsonify(dict_)
    code       = response.code

    return json_, code
Пример #6
0
def resource(filter_ = ['cdata', 'csv', 'cel', 'pipeline', 'gist'], level = None):
    response   = Response()

    parameters = addict.Dict(request.get_json())

    path       = CONFIG.App.STARTDIR if not parameters.path else os.path.join(CONFIG.App.STARTDIR, parameters.path)

    tree       = discover_resource(
      path     = path,
      level    = level,
      filter_  = filter_
    )

    response.set_data(tree)

    dict_      = response.to_dict()
    json_      = jsonify(dict_)
    code       = response.code

    return json_, code
Пример #7
0
def read():
    response = Response()

    parameters = request.get_json()

    # TODO: check if valid parameters
    path, name = parameters['path'], parameters['name']

    relpath = os.path.join(path, name)
    format_ = get_file_format(name)

    if format_ == 'CDATA':
        dataset = cdata.read(relpath)

        response.set_data(dataset)

    dict_ = response.to_dict()
    json_ = jsonify(dict_)
    code = response.code

    return json_, code
Пример #8
0
def run(delay = 5):
    response         = Response()

    parameters       = addict.Dict(request.get_json())

    if parameters.path and parameters.name and parameters.format:
        relpath      = os.path.join(parameters.path, parameters.name)

        # TODO: Check if file exists, else respond error.
        if parameters.format == 'pipeline':
            try:
                cdat, pipe  = Pipeline.load(relpath)
                pipe.run(cdat, verbose = CONFIG.DEBUG)

                while pipe.status == Pipeline.RUNNING:
                    status        = addict.Dict()
                    status.stages = pipe.stages
                    status.logs   = pipe.logs

                    socketio.emit('status', status)

                    time.sleep(delay)

                JSON.write(relpath, pipe.stages)

            except (IOError, ValueError) as e:
                response.set_error(Response.Error.UNPROCESSABLE_ENTITY, str(e))
        else:
            response.set_error(Response.Error.UNPROCESSABLE_ENTITY)
    else:
        response.set_error(Response.Error.UNPROCESSABLE_ENTITY)

    dict_       = response.to_dict()
    json_       = jsonify(dict_)
    code        = response.code

    return json_, code
Пример #9
0
def read():
    response        = Response()

    parameters      = addict.Dict(request.get_json())
    parameters.path = os.path.abspath(parameters.path) if parameters.path else ABSPATH_STARTDIR

    if parameters.name and parameters.format:
        path        = os.path.join(parameters.path, parameters.name)

        if os.path.exists(path):
            if parameters.format == 'cdata':
                cdat = cdata.read(path)
                data = cdat.to_dict()

                response.set_data(data)
            elif parameters.format in ['pipeline', 'gist']:
                try:
                    data = JSON.read(path)
                except json.decoder.JSONDecodeError as e:
                    data = [ ]
                    
                response.set_data(data)
            else:
                response.set_error(Response.Error.UNPROCESSABLE_ENTITY, 'Here')
        else:
            response.set_error(Response.Error.NOT_FOUND, 'File does not exist.')
    else:
        response.set_error(Response.Error.UNPROCESSABLE_ENTITY, 'There')

    dict_       = response.to_dict()
    json_       = jsonify(dict_)
    code        = response.code

    return json_, code