예제 #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
예제 #2
0
    def test_generatePython_netcdf(self):

        with self.app.app_context():

            plotQuery = '{"dataset_name":"giops_day","max_range":"47.59676544537632,-62.7459688212614","min_range":"46.71147616396766,-63.848111528746855","output_format":"NETCDF4","should_zip":0,"time":"712,716","user_grid":0,"variables":"vice,votemper,vozocrtx,vomecrty"}'
            data = generatePython(plotQuery, "SUBSET").read()

            ast.parse(data)
예제 #3
0
    def test_generatePython_csv(self):

        with self.app.app_context():

            plotQuery = '{"area":[{"innerrings":[],"name":"","polygons":[[[47.59676544537632,-63.322752995466445],[47.48923059927762,-62.7459688212614],[46.71147616396766,-62.92175066482866],[47.07117494555064,-63.848111528746855],[47.59676544537632,-63.322752995466445]]]}],"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":"10.672692871093773,21.980279541015648,auto","showarea":true,"time":712,"type":"map","variable":"votemper"}'
            data = generatePython(plotQuery, "CSV").read()

            ast.parse(data)
예제 #4
0
    def test_generatePython_plot(self):

        with self.app.app_context():

            plotQuery = '{"area":[{"innerrings":[],"name":"","polygons":[[[50.32977916630952,-54.02923583984376],[49.99194654491231,-41.90032958984374],[43.11512912870705,-41.90032958984374],[43.8801861709303,-54.20501708984374],[50.32977916630952,-54.02923583984376]]]}],"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":860,"type":"map","variable":"votemper"}'
            data = generatePython(plotQuery, "PLOT").read()

            ast.parse(data)
예제 #5
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
    def test_generatePython_netcdf(self):

        with self.app.app_context():

            plotQuery = '{"dataset_name":"giops_day","max_range":"47.59676544537632,-62.7459688212614","min_range":"46.71147616396766,-63.848111528746855","output_format":"NETCDF4","should_zip":0,"time":"712,716","user_grid":0,"variables":"vice,votemper,vozocrtx,vomecrty"}'

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

            expectedHash = '75abf8a73a79e859ad3a836c85b4c51a'

            self.assertEqual(m.hexdigest(), expectedHash)
    def test_generatePython_csv(self):

        with self.app.app_context():

            plotQuery = '{"area":[{"innerrings":[],"name":"","polygons":[[[47.59676544537632,-63.322752995466445],[47.48923059927762,-62.7459688212614],[46.71147616396766,-62.92175066482866],[47.07117494555064,-63.848111528746855],[47.59676544537632,-63.322752995466445]]]}],"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":"10.672692871093773,21.980279541015648,auto","showarea":true,"time":712,"type":"map","variable":"votemper"}&save&format=csv&size=10x7&dpi=144'

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

            expectedHash = 'f10133b376d8741891edec5a508e47c9'

            self.assertEqual(m.hexdigest(), expectedHash)
    def test_generatePython_plot(self):

        #TEST PLOT ~~~~~~~~~~~~~~~~~~~
        with self.app.app_context():

            plotQuery = '{"area":[{"innerrings":[],"name":"","polygons":[[[50.32977916630952,-54.02923583984376],[49.99194654491231,-41.90032958984374],[43.11512912870705,-41.90032958984374],[43.8801861709303,-54.20501708984374],[50.32977916630952,-54.02923583984376]]]}],"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":860,"type":"map","variable":"votemper"}'

            #Find Hash
            data = generatePython(plotQuery)
            newData = data.read()
            m = hashlib.md5()
            m.update(newData)
            expectedHash = '8b123e00bc2cd955156666b63b91d3b1'

            self.assertEqual(m.hexdigest(), expectedHash)
예제 #9
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