Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d79a368
commit f75a62b
Showing
5 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+705 Bytes
(100%)
istsos/plugins/unit_con_post/retrievers/aiopg/__pycache__/observations.cpython-36.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions
19
istsos/plugins/unit_con_post/retrievers/aiopg/lookUpTable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
istsos/plugins/unit_con_post/retrievers/aiopg/unitConversionPo_sql_unit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |