def post(self): token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) simulation = request.json simulation['userId'] = userid simId = randomString(14) simulation['_id'] = simId task = {} task['_id'] = randomString(14) task['simulationId'] = simId task['userId'] = userid task['messages'] = ['Starting simulation'] task['simulationKeys'] = [] task['percentage'] = 0.05 mongoClient['task'].insert_one(task) # _emission = mongoClient['prediction'].insert_one(prediction).inserted_id mongoClient['simulation'].insert_one(simulation) p = Process(target=run_simulation.run_simulation, args=(simulation, task, userid)) p.start() resp = Response(json.dumps(task)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp
def delete(self): token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) resp = Response({"deleted": 1}) resp.headers["Access-Control-Expose-Headers"] = '*' return resp
def get(self, ): args = parser.parse_args() id = args.get('id') skip = args.get('skip') maximum = args.get('maximum') if skip is None: skip = 0 if maximum is None: maximum = 20 token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) if id is None: query = {"userId": userid} tasks_c = mongoClient['scenario'].find(query).sort([ ("properties.date", -1) ]).skip(skip).limit(maximum) total = mongoClient['scenario'].count(query) emmisions = [] for t in tasks_c: emmisions.append(json_util.dumps(t)) resp = Response(json.dumps(emmisions)) resp.headers["Access-Control-Expose-Headers"] = '*' resp.headers["total"] = total return resp else: query = {"_id": id} task = mongoClient['scenario'].find_one(query) resp = Response(json_util.dumps(task)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp
def delete(self, scenario_id): token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) myquery = {"$and": [{"userId": userid}, {"_id": scenario_id}]} mongoClient['scenario'].delete_one(myquery) resp = Response(json.dumps({"deleted": 1})) resp.headers["Access-Control-Expose-Headers"] = '*' return resp
def post(self): token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) scenario = request.json scenario['userId'] = userid scenario['_id'] = randomString(14) # _emission = mongoClient['prediction'].insert_one(prediction).inserted_id mongoClient['scenario'].insert_one(scenario) resp = Response(json.dumps(scenario)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp
def post(self): token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) emission = request.json emission['userId'] = userid emission['_id'] = emission['id'] emission['properties']['saved'] = True # _emission = mongoClient['prediction'].insert_one(prediction).inserted_id mongoClient['emission'].insert_one(emission) resp = Response(json.dumps(emission)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp
def put(self): token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) simulation = request.json myquery = {"$and": [{"userId": userid}, {"_id": simulation['id']}]} update = { "$set": { "title": simulation["title"], "description": simulation["description"] } } mongoClient['simulation'].update_one(myquery, update) resp = Response(json.dumps(simulation)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp
def put(self): token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) emission = request.json myquery = {"$and": [{"userId": userid}, {"_id": emission['id']}]} update = { "$set": { "geometry": emission['geometry'], "properties": emission["properties"] } } mongoClient['emission'].update_one(myquery, update) resp = Response(json.dumps(emission)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp
def delete(self, simulation_id): token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) myquery = {"$and": [{"userId": userid}, {"_id": simulation_id}]} mongoClient['simulation'].delete_one(myquery) myquery = { "$and": [{ "userId": userid }, { "simulationId": simulation_id }] } mongoClient['output_sediment'].delete_many(myquery) mongoClient['output_water'].delete_many(myquery) mongoClient['output_soil'].delete_many(myquery) resp = Response(json.dumps({"deleted": 1})) resp.headers["Access-Control-Expose-Headers"] = '*' return resp
def get(self, ): args = parser.parse_args() id = args.get('id') skip = args.get('skip') maximum = args.get('maximum') simulation_id = args.get('simulation_id') if skip is None: skip = 0 if maximum is None: maximum = 20 token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) if id is None and simulation_id is None: query = {"userId": userid} tasks_c = mongoClient['task'].find(query).skip(skip).limit(maximum) total = mongoClient['task'].count(query) tasks = [] for t in tasks_c: tasks.append(json_util.dumps(t)) resp = Response(tasks) resp.headers["Access-Control-Expose-Headers"] = '*' resp.headers["Access-Control-Expose-Headers"] = total return resp elif id is not None and simulation_id is None: query = {"_id": ObjectId(id)} task = mongoClient['task'].find_one(query) resp = Response(json_util.dumps(task)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp else: query = {"simulationId": simulation_id} task = mongoClient['task'].find_one(query) resp = Response(json_util.dumps(task)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp
def get(self, ): args = parser.parse_args() id = args.get('id') skip = args.get('skip') maximum = args.get('maximum') day = args.get('day') output_type = args.get('output_type') x = args.get('x') y = args.get('y') if skip is None: skip = 0 if maximum is None: maximum = 20 token = request.headers['Authorization'] token = token.split(" ")[1] userid = oidc.user_getfield('sub', token) if id is None: query = {"userId": userid} tasks_c = mongoClient['simulation'].find(query).sort([ ("properties.date", -1) ]).skip(skip).limit(maximum) total = mongoClient['simulation'].count(query) simulations = [] for t in tasks_c: simulations.append(json_util.dumps(t)) resp = Response(json.dumps(simulations)) resp.headers["Access-Control-Expose-Headers"] = '*' resp.headers["total"] = total return resp elif id is not None and day is None and x is None and y is None: query = {"_id": id} task = mongoClient['simulation'].find_one(query) resp = Response(json_util.dumps(task)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp elif id is not None and x is not None and y is not None: query = {"simulationId": id} out_all = [] if output_type == 'water': output = mongoClient['output_water'].find(query) for o in output: for p in o['features']: if p['properties']['x'] == x and p['properties'][ 'y'] == y: out_all.append(p['properties']) resp = Response(json_util.dumps(out_all)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp if output_type == 'soil': output = mongoClient['output_soil'].find(query) for o in output: for p in o['features']: if p['properties']['x'] == x and p['properties'][ 'y'] == y: out_all.append(p['properties']) resp = Response(json_util.dumps(out_all)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp if output_type == 'sediment': output = mongoClient['output_sediment'].find(query) for o in output: for p in o['features']: if p['properties']['x'] == x and p['properties'][ 'y'] == y: out_all.append(p['properties']) resp = Response(json_util.dumps(out_all)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp else: query = {"$and": [{"simulationId": id}, {"day": int(day)}]} if output_type == 'water': output = mongoClient['output_water'].find_one(query) resp = Response(json_util.dumps(output)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp if output_type == 'soil': output = mongoClient['output_soil'].find_one(query) resp = Response(json_util.dumps(output)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp if output_type == 'sediment': output = mongoClient['output_sediment'].find_one(query) resp = Response(json_util.dumps(output)) resp.headers["Access-Control-Expose-Headers"] = '*' return resp