Ejemplo n.º 1
0
def generateScript():
    """
    API Format: /api/v1.0/generatescript/?query='...'&lang='...'&scriptType='...'

    query(JSON): Will contain the URI encoded JSON query object for the api script
    lang (string) : Language of the requested API script (python/r)
    scriptType (string): Type of requested script (PLOT/CSV)
    **Query must be written in JSON and converted to encodedURI**
    """

    try:
        result = GenerateScriptSchema().load(request.args)
    except ValidationError as e:
        abort(400, str(e))

    lang = result['lang']
    query = result['query']
    script_type = result['scriptType']

    if lang == "python":
        b = generatePython(query, script_type)
        resp = send_file(b,
                         as_attachment=True,
                         attachment_filename=f"API_script_{script_type}.py",
                         mimetype='application/x-python')

    elif lang == "r":
        b = generateR(query, script_type)
        resp = send_file(b,
                         as_attachment=True,
                         attachment_filename=f"API_script_{script_type}.r",
                         mimetype='text/plain')

    return resp
Ejemplo n.º 2
0
def generateScript(query: str, lang: str, scriptType: str):

    if lang == "python":
        b = generatePython(query, scriptType)
        resp = send_file(b, as_attachment=True,
                         attachment_filename='script_template.py', mimetype='application/x-python')

    elif lang == "r":
        b = generateR(query, scriptType)
        resp = send_file(b, as_attachment=True,
                         attachment_filename='script_template.r', mimetype='application/x-python')

    return resp
Ejemplo n.º 3
0
    def test_generateR_netcdf(self):

        with self.app.app_context():

            plotQuery = '{"dataset_name":"giops_day","max_range":"57.45537472457255,-35.91699909988563","min_range":"37.492919230762624,-60.08692097488562","output_format":"NETCDF4","should_zip":0,"time":"857,862","user_grid":0,"variables":"vice,votemper,vozocrtx,vomecrty"}'

            data = generateR(plotQuery)
            newData = data.read()
            m = hashlib.md5()
            m.update(newData)

            expectedHash = "9c4552b8e34e8856bd8bde64125e7f2d"

            self.assertEqual(m.hexdigest(), expectedHash)
Ejemplo n.º 4
0
    def test_generateR_csv(self):

        with self.app.app_context():

            plotQuery = '{"area":[{"innerrings":[],"name":"","polygons":[[[57.45537472457255,-53.32611083984376],[54.96545403664038,-35.91699909988563],[37.492919230762624,-40.57520222488561],[39.21584183791197,-60.08692097488562],[57.45537472457255,-53.32611083984376]]]}],"bathymetry":true,"colormap":"default","contour":{"colormap":"default","hatch":false,"legend":true,"levels":"auto","variable":"none"},"dataset":"giops_day","depth":0,"interp":"gaussian","neighbours":10,"projection":"EPSG:3857","quiver":{"colormap":"default","magnitude":"length","variable":"none"},"radius":25,"scale":"-5,30,auto","showarea":true,"time":862,"type":"map","variable":"votemper"}&save&format=csv&size=10x7&dpi=144'

            data = generateR(plotQuery)
            newData = data.read()
            m = hashlib.md5()
            m.update(newData)

            expectedHash = "4afa74cd7db4226c78fb7f5e2ae0a22f"

            self.assertEqual(m.hexdigest(), expectedHash)
Ejemplo n.º 5
0
def generateScript(url: str, type: str):

    if type == "python":
        b = generatePython(url)
        resp = send_file(b,
                         as_attachment=True,
                         attachment_filename='script_template.py',
                         mimetype='application/x-python')

    elif type == "r":
        b = generateR(url)
        resp = send_file(b,
                         as_attachment=True,
                         attachment_filename='script_template.r',
                         mimetype='application/x-python')

    return resp