frost-sta-client 1.1.48__py2.py3-none-any.whl → 1.1.49__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- frost_sta_client/__version__.py +1 -1
- frost_sta_client/utils.py +122 -119
- {frost_sta_client-1.1.48.dist-info → frost_sta_client-1.1.49.dist-info}/METADATA +1 -1
- {frost_sta_client-1.1.48.dist-info → frost_sta_client-1.1.49.dist-info}/RECORD +7 -7
- {frost_sta_client-1.1.48.dist-info → frost_sta_client-1.1.49.dist-info}/WHEEL +1 -1
- {frost_sta_client-1.1.48.dist-info → frost_sta_client-1.1.49.dist-info}/licenses/LICENSE +0 -0
- {frost_sta_client-1.1.48.dist-info → frost_sta_client-1.1.49.dist-info}/top_level.txt +0 -0
frost_sta_client/__version__.py
CHANGED
frost_sta_client/utils.py
CHANGED
@@ -1,119 +1,122 @@
|
|
1
|
-
# Copyright (C) 2021 Fraunhofer Institut IOSB, Fraunhoferstr. 1, D 76131
|
2
|
-
# Karlsruhe, Germany.
|
3
|
-
#
|
4
|
-
# This program is free software: you can redistribute it and/or modify
|
5
|
-
# it under the terms of the GNU Lesser General Public License as published by
|
6
|
-
# the Free Software Foundation, either version 3 of the License, or
|
7
|
-
# (at your option) any later version.
|
8
|
-
#
|
9
|
-
# This program is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
-
# GNU Lesser General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU Lesser General Public License
|
15
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
-
|
17
|
-
import jsonpickle
|
18
|
-
import datetime
|
19
|
-
from dateutil.parser import isoparse
|
20
|
-
import geojson
|
21
|
-
import logging
|
22
|
-
import sys
|
23
|
-
import frost_sta_client.model.ext.entity_list
|
24
|
-
|
25
|
-
|
26
|
-
def extract_value(location):
|
27
|
-
try:
|
28
|
-
value = int(location[location.find('(')+1: location.find(')')])
|
29
|
-
except ValueError:
|
30
|
-
value = str(location[location.find('(')+2: location.find(')')-1])
|
31
|
-
return value
|
32
|
-
|
33
|
-
def transform_entity_to_json_dict(entity):
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
1
|
+
# Copyright (C) 2021 Fraunhofer Institut IOSB, Fraunhoferstr. 1, D 76131
|
2
|
+
# Karlsruhe, Germany.
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
import jsonpickle
|
18
|
+
import datetime
|
19
|
+
from dateutil.parser import isoparse
|
20
|
+
import geojson
|
21
|
+
import logging
|
22
|
+
import sys
|
23
|
+
import frost_sta_client.model.ext.entity_list
|
24
|
+
|
25
|
+
|
26
|
+
def extract_value(location):
|
27
|
+
try:
|
28
|
+
value = int(location[location.find('(')+1: location.find(')')])
|
29
|
+
except ValueError:
|
30
|
+
value = str(location[location.find('(')+2: location.find(')')-1])
|
31
|
+
return value
|
32
|
+
|
33
|
+
def transform_entity_to_json_dict(entity):
|
34
|
+
try:
|
35
|
+
data = entity.__getstate__()
|
36
|
+
except AttributeError:
|
37
|
+
data = entity.__dict__
|
38
|
+
return data
|
39
|
+
|
40
|
+
def class_from_string(string):
|
41
|
+
module_name, class_name = string.rsplit(".", 1)
|
42
|
+
return getattr(sys.modules[module_name], class_name)
|
43
|
+
|
44
|
+
def transform_json_to_entity(json_response, entity_class):
|
45
|
+
cl = class_from_string(entity_class)
|
46
|
+
obj = cl()
|
47
|
+
obj.__setstate__(json_response)
|
48
|
+
return obj
|
49
|
+
|
50
|
+
def transform_json_to_entity_list(json_response, entity_class):
|
51
|
+
entity_list = frost_sta_client.model.ext.entity_list.EntityList(entity_class)
|
52
|
+
result_list = []
|
53
|
+
if isinstance(json_response, dict):
|
54
|
+
try:
|
55
|
+
response_list = json_response['value']
|
56
|
+
entity_list.next_link = json_response.get("@iot.nextLink", None)
|
57
|
+
entity_list.count = json_response.get("@iot.count", None)
|
58
|
+
except AttributeError as e:
|
59
|
+
raise e
|
60
|
+
elif isinstance(json_response, list):
|
61
|
+
response_list = json_response
|
62
|
+
else:
|
63
|
+
raise ValueError("expected json as a dict or list to transform into entity list")
|
64
|
+
entity_list.entities = [transform_json_to_entity(item, entity_list.entity_class) for item in response_list]
|
65
|
+
return entity_list
|
66
|
+
|
67
|
+
|
68
|
+
def check_datetime(value, time_entity):
|
69
|
+
try:
|
70
|
+
parse_datetime(value)
|
71
|
+
except ValueError as e:
|
72
|
+
logging.error(f"error during {time_entity} check")
|
73
|
+
raise e
|
74
|
+
return value
|
75
|
+
|
76
|
+
|
77
|
+
def parse_datetime(value) -> str:
|
78
|
+
if value is None:
|
79
|
+
return value
|
80
|
+
if isinstance(value, str):
|
81
|
+
if '/' in value:
|
82
|
+
try:
|
83
|
+
times = value.split('/')
|
84
|
+
if len(times) != 2:
|
85
|
+
raise ValueError("If the time interval is provided as a string,"
|
86
|
+
" it should be in isoformat")
|
87
|
+
result = [isoparse(times[0]),
|
88
|
+
isoparse(times[1])]
|
89
|
+
except ValueError:
|
90
|
+
raise ValueError("If the time entity interval is provided as a string,"
|
91
|
+
" it should be in isoformat")
|
92
|
+
result = result[0].isoformat() + '/' + result[1].isoformat()
|
93
|
+
return result
|
94
|
+
else:
|
95
|
+
try:
|
96
|
+
result = isoparse(value)
|
97
|
+
except ValueError:
|
98
|
+
raise ValueError("If the phenomenon time is provided as string, it should be in isoformat")
|
99
|
+
result = result.isoformat()
|
100
|
+
return result
|
101
|
+
if isinstance(value, datetime.datetime):
|
102
|
+
return value.isoformat()
|
103
|
+
if isinstance(value, list) and all(isinstance(v, datetime.datetime) for v in value):
|
104
|
+
return value[0].isoformat() + value[1].isoformat()
|
105
|
+
else:
|
106
|
+
raise ValueError('time entities should consist of one or two datetimes')
|
107
|
+
|
108
|
+
|
109
|
+
def process_area(value):
|
110
|
+
if not isinstance(value, dict):
|
111
|
+
raise ValueError("geojsons can only be handled as dictionaries!")
|
112
|
+
if value.get("type", None) is None or value.get("coordinates", None) is None:
|
113
|
+
raise ValueError("Both type and coordinates need to be specified in the dictionary")
|
114
|
+
if value["type"] == "Point":
|
115
|
+
return geojson.geometry.Point(value["coordinates"])
|
116
|
+
if value["type"] == "Polygon":
|
117
|
+
return geojson.geometry.Polygon(value["coordinates"])
|
118
|
+
if value["type"] == "Geometry":
|
119
|
+
return geojson.geometry.Geometry(value["coordinates"])
|
120
|
+
if value["type"] == "LineString":
|
121
|
+
return geojson.geometry.LineString(value["coordinates"])
|
122
|
+
raise ValueError("can only handle geojson of type Point, Polygon, Geometry or LineString")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
frost_sta_client/__init__.py,sha256=N0Rs6kwdPcpyz0p-Tfq2PYIAIIZsMmnSC0QXus_AmP0,1789
|
2
|
-
frost_sta_client/__version__.py,sha256=
|
3
|
-
frost_sta_client/utils.py,sha256=
|
2
|
+
frost_sta_client/__version__.py,sha256=ivlB8oJyiH--NyghDqejsdHw4ZWEylIr37Lk9oOIbh8,355
|
3
|
+
frost_sta_client/utils.py,sha256=YA8B3SkG0RFFumSPPH65rJ2BHrADzKtcCKXVKAUVG54,4747
|
4
4
|
frost_sta_client/dao/__init__.py,sha256=RKxbQ3WLVygWyz_Kb-SzO7CfUdffq7LqtJHcHSOHmgo,221
|
5
5
|
frost_sta_client/dao/actuator.py,sha256=WxRjeetR50Pb9AbhCdtc1VRSl09pgzfA2DsPBBZy-3E,1099
|
6
6
|
frost_sta_client/dao/base.py,sha256=uAx1qSnXX2jwoZrjXjPW47bp-c-jMUyX8SpmY0eXM84,9209
|
@@ -40,8 +40,8 @@ frost_sta_client/query/query.py,sha256=hXd-ffYf2HDZ5aqVA5lW5XtoijIr4-4mTfevdRDz2
|
|
40
40
|
frost_sta_client/service/__init__.py,sha256=au1GqHe1OB7Iq-i90plqmIrH-7wBE7ogDoQ2uX03Fj0,109
|
41
41
|
frost_sta_client/service/auth_handler.py,sha256=qahYUK7Z0kGvbUcdtpodIA9sngYCfJz2jqKpLVGA8Z4,1117
|
42
42
|
frost_sta_client/service/sensorthingsservice.py,sha256=H2wM4v5oPvJ6eBfvdkbYyLI4V1vaWpbAuq-Q_fGo3-A,4621
|
43
|
-
frost_sta_client-1.1.
|
44
|
-
frost_sta_client-1.1.
|
45
|
-
frost_sta_client-1.1.
|
46
|
-
frost_sta_client-1.1.
|
47
|
-
frost_sta_client-1.1.
|
43
|
+
frost_sta_client-1.1.49.dist-info/licenses/LICENSE,sha256=LPNKwDiu5awG-TPd0dqYJuC7k4PBPY4LCI_O0LSpW1s,7814
|
44
|
+
frost_sta_client-1.1.49.dist-info/METADATA,sha256=5-EuYzZh_RwqShdQaV5Bmsm9nCsb-Z0cUO3GjBUiKWk,5905
|
45
|
+
frost_sta_client-1.1.49.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
|
46
|
+
frost_sta_client-1.1.49.dist-info/top_level.txt,sha256=c35-3D_K1E_y8fcadqI3j6kGQ7HBrkOqCNie5Rv64KI,17
|
47
|
+
frost_sta_client-1.1.49.dist-info/RECORD,,
|
File without changes
|
File without changes
|