def after(self, request): request['response'] = Response( Response.get_template({ "data": request['unit_conversion_pint'] # "data" : data1 # "data": request['uoms'] }))
def after(self, request): """Render the result of the request following the OGC:SOS 2.0.0 standard. """ request['response'] = Response(json_source=Response.get_template( {"data": { "exists": request['exists'] }}))
def after(self, request): request['response'] = Response( json_source=Response.get_template({ "data": request['observations'], "headers": request['headers'] }) )
def after(self, request): """Render the result of the request in json. """ request['response'] = Response( json_source=Response.get_template({ "data": setting._samplingTypes }) )
def after(self, request): request['response'] = Response( json_source=Response.get_template({ "data": { "exists": request['exists'] } }) )
def after(self, request): """Render the result of the request following the OGC:SOS 2.0.0 standard. """ response = Response.get_template() if request['body']['action'] == 'retrieve': response['data'] = request['provider'] request['response'] = Response(json_source=response)
def after(self, request): """Render the result of the request following the OGC:SOS 2.0.0 standard. """ response = Response.get_template() if request.get_action() == 'retrieve': response['data'] = setting._sensor_type request['response'] = Response(response)
def after(self, request): connect() print(get_parts()) request['response'] = Response( Response.get_template({ # "data": request['uoms'] # data1 = jsonify(result = json_data) "data": request['uoms'] }) )
def after(self, request): """Render the result of the request following the OGC:SOS 2.0.0 standard. """ response = Response.get_template() if request['body']['action'] == 'retrieve': response['data'] = request['specimen'] elif request['body']['action'] == 'create': link = 'http://istsos.org/istsos3/specimen/{}'.format( request['specimen']['identifier']) response['message'] = 'new specimen link: {}'.format(link) request['response'] = Response(json_source=response)
def after(self, request): """Render the result of the request following the OGC:SOS 2.0.0 standard. """ response = Response.get_template() if request['body']['action'] == 'retrieve': response['data'] = request['observedProperties'] elif request['body']['action'] == 'create': response['message'] = "new observed property id: {}".format( request['observedProperty']['id']) else: response['message'] = "Observed property updated" request['response'] = Response(json_source=response)
def after(self, request): """Render the result of the request following the OGC:SOS 2.0.0 standard. """ response = Response.get_template() if request['body']['action'] == 'retrieve': response['data'] = request['materials'] elif request['body']['action'] == 'create': link = 'http://istsos.org/istsos3/material/{}'.format( request['material']['name']) response['message'] = "{}".format(link) request['response'] = Response(json_source=response)
def after(self, request): """Render the result of the request in json. """ request['response'] = Response(json_source=Response.get_template( {"data": request['processingDetails']}))
def after(self, request): request['response'] = Response( json_source=Response.get_template({"message": request["message"]}))
def after(self, request): """Render the result of the request in json. """ request['response'] = Response(json_source=Response.get_template( {"data": request['featureOfInterestList']}))
def after(self, request): offering = request['offerings'][0] if len(request['offerings'])==0: raise Exception( "Offering \"%s\" not registered" % self.data['offering']) if offering['foi_type'] == setting._SAMPLING_SPECIMEN: raise Exception( "Offering type \"speciment\" not yet supported") if not offering['fixed']: raise Exception( "Not fixed Offering not yet supported") columns = [] for op in offering['observable_properties']: if not op['type'] == setting._COMPLEX_OBSERVATION: columns.extend([ op['column'], "%s_qi" % op['column'] ]) bp = ep = None if offering['phenomenon_time'] is not None: bp = istsos.str2date( offering['phenomenon_time']['timePeriod']['begin'] ) ep = istsos.str2date( offering['phenomenon_time']['timePeriod']['end'] ) obsCnt = 1 if setting._COMPLEX_OBSERVATION in offering['observation_types']: obsCnt = len(offering['observable_properties']) - 1 dbmanager = yield from self.init_connection() cur = dbmanager.cur rows = self.data['observations'] values = [] for row in rows: try: sampling_time = row.pop(0) sampling_time_dt = istsos.str2date(sampling_time) except Exception as dtex: raise Exception( "Procedure %s, Sampling time (%s) " "wrong format" % ( offering['name'], sampling_time ) ) params = [ str(uuid.uuid1()).replace('-', ''), sampling_time, sampling_time, sampling_time ] # Check time consistency if offering['phenomenon_time'] is not None: # If the end position exists the new measures # must be after if sampling_time_dt < ep: # non blocking exception: skip row istsos.debug("Skipping observation: %s" % row) continue if len(row) != obsCnt: istsos.debug( "Observations count missmatch (%s!=%s)" % ( len(row), obsCnt ) ) continue params = params + row values.append( ( yield from cur.mogrify( ( '(%s, %s, %s, %s, ' + ', '.join( ["%s, 100"] * obsCnt ) + ')' ), tuple(params) ) ).decode("utf-8") ) if len(values)>0: yield from self.begin() print( ( yield from cur.mogrify( (""" INSERT INTO data._%s( obs_id, begin_time, end_time, result_time, %s ) """ % ( offering['name'].lower(), ", ".join(columns) )) + ( " VALUES %s" % ", ".join(values) ) ) ).decode("utf-8") ) yield from cur.execute( (""" INSERT INTO data._%s( obs_id, begin_time, end_time, result_time, %s ) """ % ( offering['name'].lower(), ", ".join(columns) )) + ( " VALUES %s" % ", ".join(values) ) ) if offering['phenomenon_time'] is not None: yield from cur.execute(""" UPDATE public.offerings SET pt_end=%s::TIMESTAMPTZ WHERE id = %s; """, (sampling_time, offering['id'])) else: yield from cur.execute(""" UPDATE public.offerings SET pt_end=%s::TIMESTAMPTZ, pt_begin=%s::TIMESTAMPTZ WHERE id = %s; """, (sampling_time, sampling_time, offering['id'])) yield from self.commit() request['response'] = Response( json_source=Response.get_template() )
def after(self, request): request['response'] = Response( Response.get_template({"data": request['processingDetail']}))
def after(self, request): request['response'] = Response( json_source=Response.get_template({ "data": request['observableProperties'] }) )
def after(self, request): request['response'] = Response( Response.get_template({ "data": request['samplingMethod'] }) )
def after(self, request): request['response'] = Response( Response.get_template({ "data": request['uom'] }) )
def after(self, request): request['response'] = Response( Response.get_template({ "data": request['uoms'] # "data": "Hello World" }))
def after(self, request): headers = [{ "type": "datetime", "name": "Phenomenon Time", "column": "e" }] from_unit = request['offerings'][0]['observable_properties'][0]['uom'] from_unit = yield from self.findLookUp(from_unit) converted_data = [] to_unit = '' if request.get_filter("responseFormat") in setting._responseFormat['array']: recs = request['observations'].copy() if request.get_filter("in_unit") is not None: to_unit = request.get_filter("in_unit") to_unit = yield from self.findLookUp(to_unit) if request.get_filter("operation") is not None: if 'unit' in request.get_filter("operation"): unit = yield from self.findLookUp(request.get_filter("operation")['unit']) if 'qty' in request.get_filter("operation"): qty = request.get_filter("operation")['qty'] if 'type' in request.get_filter("operation"): if request.get_filter("operation")['type'] == 'add': if qty == '': qty = 0 for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, unit) src, dst = operation.split('opr') if(from_unit == 'degC' and unit == 'degC'): conversion = Q_(src)+Q_(dst).to('delta_degC') elif(from_unit == 'degC'): conversion = Q_(src)+Q_(dst).to('delta_degC') elif(unit == 'degC'): conversion = Q_(src)+Q_(dst).to('delta_degC') else: conversion = Q_(src)+Q_(dst) conversion = Q_(conversion).to(to_unit) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) conversion_uom = to_unit elif request.get_filter("operation")['type'] == 'sub': if qty == '': qty = 0 for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, unit) src, dst = operation.split('opr') conversion = Q_(src)-Q_(dst) conversion = Q_(conversion).to(to_unit) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) conversion_uom = to_unit elif request.get_filter("operation")['type'] == 'mul': if qty == '': qty = 1 conversion_uom = """%s*%s"""%(to_unit, unit) for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, unit) src, dst = operation.split('opr') conversion = Q_(src)*Q_(dst) conversion = Q_(conversion).to(conversion_uom) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) elif request.get_filter("operation")['type'] == 'div': if qty == '': qty = 1 conversion_uom = """%s/%s"""%(to_unit,unit) for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, unit) src, dst = operation.split('opr') conversion = Q_(src)/Q_(dst) conversion = Q_(conversion).to(conversion_uom) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) else: if 'qty' in request.get_filter("operation"): qty = request.get_filter("operation")['qty'] if 'type' in request.get_filter("operation"): if request.get_filter("operation")['type'] == 'add': if qty == '': qty = 0 for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, from_unit) src, dst = operation.split('opr') if(from_unit == 'degC'): conversion = Q_(src)+Q_(dst).to('delta_degC') else: conversion = Q_(src)+Q_(dst) conversion = Q_(conversion).to(to_unit) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) conversion_uom = to_unit elif request.get_filter("operation")['type'] == 'sub': if qty == '': qty = 0 for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, from_unit) src, dst = operation.split('opr') conversion = Q_(src)-Q_(dst) conversion = Q_(conversion).to(to_unit) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) conversion_uom = to_unit elif request.get_filter("operation")['type'] == 'mul': if qty == '': qty = 1 conversion_uom = """%s*%s"""%(to_unit,from_unit) for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, from_unit) src, dst = operation.split('opr') conversion = Q_(src)*Q_(dst) conversion = Q_(conversion).to(conversion_uom) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) elif request.get_filter("operation")['type'] == 'div': if qty == '': qty = 1 conversion_uom = """%s/%s"""%(to_unit,from_unit) for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, from_unit) src, dst = operation.split('opr') conversion = Q_(src)/Q_(dst) conversion = Q_(conversion).to(conversion_uom) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) else: for rec in recs: operation = """%s*%sopr%s"""%(rec[1], from_unit, to_unit) src, dst = operation.split('opr') conversion = Q_(src).to(dst) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) conversion_uom = to_unit else: if request.get_filter("operation") is not None: if 'unit' in request.get_filter("operation"): unit = yield from self.findLookUp(request.get_filter("operation")['unit']) if 'qty' in request.get_filter("operation"): qty = request.get_filter("operation")['qty'] if 'type' in request.get_filter("operation"): if request.get_filter("operation")['type'] == 'add': if qty == '': qty = 0 for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, unit) src, dst = operation.split('opr') if(from_unit == 'degC' and unit == 'degC'): conversion = Q_(src)+Q_(dst).to('delta_degC') elif(from_unit == 'degC'): conversion = Q_(src)+Q_(dst).to('delta_degC') elif(unit == 'degC'): conversion = Q_(src)+Q_(dst).to('delta_degC') else: conversion = Q_(src)+Q_(dst) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) conversion_uom = from_unit elif request.get_filter("operation")['type'] == 'sub': if qty == '': qty = 0 for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, unit) src, dst = operation.split('opr') conversion = Q_(src)-Q_(dst) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) conversion_uom = from_unit elif request.get_filter("operation")['type'] == 'mul': if qty == '': qty = 1 conversion_uom = """%s*%s"""%(from_unit,unit) for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, unit) src, dst = operation.split('opr') conversion = Q_(src)*Q_(dst) change2 = conversion.magnitude converted_data.append([rec[0],str(change2)]) elif request.get_filter("operation")['type'] == 'div': if qty == '': qty = 1 conversion_uom = """%s/%s"""%(from_unit, unit) for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, unit) src, dst = operation.split('opr') conversion = Q_(src)/Q_(dst) change2 = conversion.magnitude converted_data.append([rec[0], str(change2)]) else: if 'qty' in request.get_filter("operation"): qty = request.get_filter("operation")['qty'] if 'type' in request.get_filter("operation"): if request.get_filter("operation")['type'] == 'add': if qty == '': qty = 0 for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, from_unit) src, dst = operation.split('opr') if(from_unit == 'degC'): conversion = Q_(src)+Q_(dst).to('delta_degC') else: conversion = Q_(src)+Q_(dst) change2 = conversion.magnitude converted_data.append([rec[0], str(change2)]) conversion_uom = from_unit elif request.get_filter("operation")['type'] == 'sub': if qty == '': qty = 0 for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, from_unit) src, dst = operation.split('opr') conversion = Q_(src)-Q_(dst) change2 = conversion.magnitude converted_data.append([rec[0], str(change2)]) conversion_uom = from_unit elif request.get_filter("operation")['type'] == 'mul': if qty == '': qty = 1 conversion_uom = """%s*%s"""%(from_unit,from_unit) for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, from_unit) src, dst = operation.split('opr') conversion = Q_(src)*Q_(dst) change2 = conversion.magnitude converted_data.append([rec[0], str(change2)]) elif request.get_filter("operation")['type'] == 'div': if qty == '': qty = 1 conversion_uom = """%s/%s"""%(from_unit, from_unit) for rec in recs: operation = """%s*%sopr%s*%s"""%(rec[1], from_unit, qty, from_unit) src, dst = operation.split('opr') conversion = Q_(src)/Q_(dst) change2 = conversion.magnitude converted_data.append([rec[0], str(change2)]) # for rec in recs: # # change=rec[1]*ureg.kilometers # # conversion=change.to(ureg.meter) # # change2=conversion.magnitude # change=str(rec[1])+"*"+from_unit+"to"+to_unit # # change=Q_(str(rec[1]), ureg.degC).to(ureg.kelvin) # # change=str(rec[1])+"*degC"+"to"+"degF" # # change=str(rec[1])+"*ureg.degC"+"to"+"ureg.degF" # # change=rec[1]*ureg.degC # # change=str(rec[1])+"* kelvin to degF" # src, dst = change.split('to') # conversion=Q_(src).to(dst) # # home = Q_(rec[1], ureg.degC) # # conversion=home.to('degF') # # conversion=Q_(rec[1], ureg.degC).to(ureg.kelvin).magnitude # change2=conversion.magnitude # # print(change2) # # print(conversion) # converted_data.append([rec[0],str(change2)]) else: converted_data = request['observations'] conversion_uom = to_unit headers.append({ "type": request["headers"][1]["type"], "name": request["headers"][1]["name"], "definition": request["headers"][1]["definition"], "offering": request["headers"][1]["offering"], "uom": conversion_uom }) request['response'] = Response( json_source=Response.get_template({ "data": converted_data, "headers": headers }) ) yield from self.__download_file(request, converted_data, headers) else: request['response'] = Response( json_source=Response.get_template({ "message": "In Pint Unit Conversion Valid only for array responseFormat", }) )
def after(self, request): request['response'] = Response( Response.get_template({"data": request['observedProperty']}))
def after(self, request): request['response'] = Response( Response.get_template({ 'id': request['featureOfInterest']['id'] }) )
def after(self, request): request['response'] = Response( json_source=Response.get_template({"data": request['categories']}))
def after(self, request): request['response'] = Response( Response.get_template() )