Skip to content

Commit

Permalink
Simplified conversion of Numbers to the appropriate data-tye...
Browse files Browse the repository at this point in the history
some how Python 2.7/NGSIproxy/wirecloud is converting an unicode instead of having the correct type --> needs some further investigation
  • Loading branch information
ptrdtznr committed Dec 3, 2018
1 parent dc4ec60 commit 2a31ead
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions JsonToObject/reverseEntityAttribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,21 @@ def __init__(self, _dict, useMetadata=True):
return

if _dict['type'] == 'number' or _dict['type'] == 'Integer':
self.value = float(_dict['value'])
if self.value % 1 == 0.0:
if useMetadata and 'python' in _dict['metadata']:
metadata = _dict['metadata']
if metadata['python'] == dict(type="dataType", value="int"):
self.value = int(_dict['value'])
return
else:
self.value = long(_dict['value'])
return
else:
self.value = long(self.value)
return
else:
return

if(isinstance(_dict['value'], int)):
self.value = int(_dict['value'])
elif(isinstance(_dict['value'], float)):
self.value = float (_dict['value'])
elif(isinstance(_dict['value'], long)):
self.value = long(_dict['value'])
# some how Python 2.7/NGSIproxy/wirecloud is converting an Unicode instead of having the correct type
elif isinstance(_dict['value'], str) or isinstance(_dict['value'], unicode):
try:
self.value = int(_dict['value'])
except ValueError:
try:
self.value = float(_dict['value'])
except ValueError:
return

elif _dict['type'] == 'string':
# Case String or Unicode
Expand Down

0 comments on commit 2a31ead

Please sign in to comment.