def stats_impl(args, query=None): """ API Format: /stats/?query='...' query = { dataset : Dataset to extract data variable : Type of data to plot - Options found using /api/variables/?dataset='...' time : Time retrieved data was gathered/modeled depth : Water Depth - found using /api/depth/?dataset='...' area : Selected Area } **Query must be written in JSON and converted to encodedURI** **Not all components of query are required """ if query == None: #Invalid API Check if 'query' not in args: #Invalid API Check raise APIError( "A Query must be specified in the form /stats/?query='...' ") #Retrieves Query as JSON based on Request Method query = json.loads(args.get('query')) dataset = query.get('dataset') #Retrieves dataset from query data = areastats(dataset, query) return Response(data, status=200, mimetype='application/json')
def stats(): if request.method == "GET": if 'query' not in request.args: raise FAILURE query = json.loads(request.args.get('query')) else: if 'query' not in request.form: raise FAILURE query = json.loads(request.form.get('query')) dataset = query.get('dataset') data = areastats(dataset, query) return Response(data, status=200, mimetype='application/json')
def stats_v1_0(): """ API Format: /api/v1.0/stats/?query='...' query = { dataset : Dataset to extract data variable : Type of data to plot - Options found using /api/variables/?dataset='...' time : Time retrieved data was gathered/modeled depth : Water Depth - found using /api/depth/?dataset='...' area : Selected Area } **Query must be written in JSON and converted to encodedURI** **Not all components of query are required """ if request.method == 'GET': args = request.args else: args = request.form query = json.loads(args.get('query')) config = DatasetConfig(query.get('dataset')) with open_dataset(config) as dataset: date = dataset.convert_to_timestamp(query.get('time')) date = {'time': date} query.update(date) if not query: # Invalid API Check if 'query' not in args: # Invalid API Check raise APIError( "A Query must be specified in the form /stats/?query='...' " ) # Retrieves Query as JSON based on Request Method query = json.loads(args.get('query')) dataset = query.get('dataset') # Retrieves dataset from query data = areastats(dataset, query) return Response(data, status=200, mimetype='application/json')