Skip to content

Commit

Permalink
added
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulworld committed Jul 22, 2018
1 parent d79a368 commit f75a62b
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 10 deletions.
12 changes: 5 additions & 7 deletions istsos/plugins/unit_con_post/lookUpTable.py
Expand Up @@ -9,13 +9,11 @@
class LookUpTable(object):
def findLookUp(self, unit):
for key, value in lookups.items():
if str(unit).lower() in value:
if str(unit).lower() in (n.lower() for n in value):
return key

def findLookUp1(unit="celcius"):
for key, value in lookups.items():
if unit in value:
return key.encode('utf-8')
# a=LookUpTable()

a=LookUpTable()
print('hello world')
print(findLookUp1("degF"))
print(a.findLookUp("degF"))
# print(findLookUp1("degF"))
Binary file not shown.
19 changes: 19 additions & 0 deletions istsos/plugins/unit_con_post/retrievers/aiopg/lookUpTable.py
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
lookups = {
"°C":["°C", "celcius", "degree Celsius", "degree-celsius", "degree-celsius", "degree", "degree centigrade", "degcelsius", "degC"],
"°F":["°F", "fahrenheit", "degfahrenheit", "degF", "degfahrenheit", "degree-fahrenheit", "degree fahrenheit"],
"°K":["°K", "kelvin", "degK", "tempK"],
}


class LookUpTable(object):
def findLookUp(self, unit):
for key, value in lookups.items():
if str(unit).lower() in (n.lower() for n in value):
return key


a=LookUpTable()
print('hello world')
print(a.findLookUp("degF"))
# print(findLookUp1("degF"))
17 changes: 14 additions & 3 deletions istsos/plugins/unit_con_post/retrievers/aiopg/observations.py
Expand Up @@ -2,6 +2,11 @@
# istSOS. See https://istsos.org/
# License: https://github.com/istSOS/istsos3/master/LICENSE.md
# Version: v3.0.0
lookups = {
"°C":["°C", "celcius", "degree Celsius", "degree-celsius", "degree-celsius", "degree", "degree centigrade", "degcelsius", "degC"],
"°F":["°F", "fahrenheit", "degfahrenheit", "degF", "degfahrenheit", "degree-fahrenheit", "degree fahrenheit"],
"°K":["°K", "kelvin", "degK", "tempK"],
}

import asyncio
import istsos
Expand All @@ -13,6 +18,7 @@
ObservedProperty, ObservedPropertyComplex)



class Observations(Observations):
"""Query an SOS to retrieve observation data structured according to the
O&M specification.
Expand Down Expand Up @@ -67,6 +73,11 @@ def process(self, request):
yield from self.__get_data(offering, request)

# istsos.debug(request['observations'])
@asyncio.coroutine
def findLookUp(self, unit):
for key, value in lookups.items():
if str(unit).lower() in (n.lower() for n in value):
return key

@asyncio.coroutine
def __get_array_2(self, offerings, request):
Expand Down Expand Up @@ -122,7 +133,7 @@ def __get_array_2(self, offerings, request):
columns.append(op['column'])
# columns_qi.append('%s_qi' % op['column'])
tables[tName].append(op['column'])
ConvertUnit=op['uom']
ConvertUnit=findLookUp(op['uom'])
headers.append({
"type": "number",
"name": op['name'],
Expand Down Expand Up @@ -292,7 +303,7 @@ def __get_array(self, offerings, request):
columns.append(op['column'])
# columns_qi.append('%s_qi' % op['column'])
tables[tName].append(op['column'])
ConvertUnit=op['uom']
ConvertUnit=yield from self.findLookUp(op['uom'])
headers.append({
"type": "number",
"name": op['name'],
Expand Down Expand Up @@ -440,7 +451,7 @@ def __get_array(self, offerings, request):
# col+"*'m'::unit@@'mm' "
# )
if 'in_unit' in request['json']:
To_unit=request['json']['in_unit']
To_unit=yield from self.findLookUp(request['json']['in_unit'])
convert_unit="""(%s::text||'%s')::unit@@'%s' """%(col,ConvertUnit,To_unit)
cols[
columns.index(col)
Expand Down
@@ -0,0 +1,115 @@
# -*- coding: utf-8 -*-
# istSOS. See https://istsos.org/
# License: https://github.com/istSOS/istsos3/master/LICENSE.md
# Version: v3.0.0

import asyncio
import istsos
from istsos.entity.rest.response import Response
from istsos.actions.action import CompositeAction


class UnitConversionPo_sql_unit(CompositeAction):

@asyncio.coroutine
def process(self, request):
"""
Request example: {
"action": "UNIT_CON_POST",
"data": {
"offerings": ["belin","belin"],
"observedProperties": [
"urn:ogc:def:parameter:x-istsos:1.0:temperature"
],
"temporal": {
"reference": "om:phenomenonTime",
"fes": "during",
"period": [
"2015-05-03T16:30:00.000000+0200",
"2015-06-03T16:30:00.000000+0200"
]
},
"responseFormat": "application/json;subtype='array'"
},
"in_unit":"°F"
}
"""
# Add filters
print('Unit Conversion PostgreSQL unit called')
print(request.get_rest_data())
request.set_filter(request.get_rest_data())
# Adding action Offering retriever
yield from self.add_retriever_unit_conversion('Offerings')
# yield from self.add_retriever('Offerings')
yield from self.add_retriever_unit_conversion('Observations')

@asyncio.coroutine
def after(self, request):
pass

@asyncio.coroutine
def add_retriever_unit_conversion(self, action, filter=None):
self.add((yield from get_retrievers_unit_conversion(action, filter=filter)))



@asyncio.coroutine
def get_retrievers_unit_conversion(name, **kwargs):
action = yield from __get_plugin_proxy(
'plugins.unit_con_post.retrievers', name, **kwargs)
return action


@asyncio.coroutine
def __get_plugin_proxy(istsos_package, action_module, **kwargs):
from istsos import setting
import importlib
state = yield from setting.get_state()
fileName = action_module[0].lower() + action_module[1:]
module = 'istsos.%s.%s.%s' % (
istsos_package,
state.config["loader"]["type"],
fileName
)

istsos.debug("Importing %s.%s" % (module, action_module))
try:
m = importlib.import_module(module)
except Exception:
module = 'istsos.%s.%s' % (
istsos_package,
fileName
)
m = importlib.import_module(module)

m = getattr(m, action_module)
if kwargs is not None:
return m(**kwargs)
return m()

# @asyncio.coroutine
# def __get_plugin_proxy(istsos_package, action_module, **kwargs):
# from istsos import setting
# import importlib
# state = yield from setting.get_state()
# fileName = action_module[0].lower() + action_module[1:]
# module = 'istsos.%s.%s.%s' % (
# istsos_package,
# state.config["loader"]["type"],
# fileName
# )

# istsos.debug("Importing %s.%s" % (module, action_module))
# try:
# m = importlib.import_module(module)
# except Exception:
# module = 'istsos.%s.%s' % (
# istsos_package,
# fileName
# )
# m = importlib.import_module(module)

# m = getattr(m, action_module)
# if kwargs is not None:
# return m(**kwargs)
# return m()

0 comments on commit f75a62b

Please sign in to comment.