PyGeoModel 1.0.0__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.
- ogmsServer2/__init__.py +33 -0
- ogmsServer2/base.py +38 -0
- ogmsServer2/constants.py +21 -0
- ogmsServer2/data/PGA.tif +0 -0
- ogmsServer2/data/baseclip.tif +0 -0
- ogmsServer2/data/intensity.tif +0 -0
- ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_67c32dc057e89375/LandSlide-outputIntensitypbtyTif.tif +0 -0
- ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_67c32dc057e89375/LandSlide-outputPGApbtyTif.tif +0 -0
- ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_7972c0716caa1213/LandSlide-outputIntensitypbtyTif.tif +0 -0
- ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_7972c0716caa1213/LandSlide-outputPGApbtyTif.tif +0 -0
- ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_a044c410df669372/LandSlide-outputIntensitypbtyTif.tif +0 -0
- ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_a044c410df669372/LandSlide-outputPGApbtyTif.tif +0 -0
- ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_b6ba56c07bf80c30/LandSlide-outputIntensitypbtyTif.tif +0 -0
- ogmsServer2/data//345/234/260/351/234/207/347/276/244/345/217/221/346/273/221/345/235/241/346/246/202/347/216/207/350/257/204/344/274/260/351/242/204/350/255/246/346/250/241/345/236/213_b6ba56c07bf80c30/LandSlide-outputPGApbtyTif.tif +0 -0
- ogmsServer2/openModel.py +393 -0
- ogmsServer2/openUtils/__init__.py +24 -0
- ogmsServer2/openUtils/exceptions.py +80 -0
- ogmsServer2/openUtils/http_client.py +247 -0
- ogmsServer2/openUtils/mdlUtils.py +116 -0
- ogmsServer2/openUtils/parameterValidator.py +55 -0
- ogmsServer2/openUtils/stateManager.py +69 -0
- pygeomodel-1.0.0.dist-info/METADATA +68 -0
- pygeomodel-1.0.0.dist-info/RECORD +28 -0
- pygeomodel-1.0.0.dist-info/WHEEL +5 -0
- pygeomodel-1.0.0.dist-info/licenses/LICENSE +21 -0
- pygeomodel-1.0.0.dist-info/top_level.txt +3 -0
- pygeomodel.py +2460 -0
- scripts.py +128 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import httpx
|
|
2
|
+
from typing import Optional, Dict, Any, Union, Tuple
|
|
3
|
+
import asyncio
|
|
4
|
+
|
|
5
|
+
# 类型别名
|
|
6
|
+
Headers = Dict[str, str]
|
|
7
|
+
Files = Dict[str, Tuple[str, Any]]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class HttpClient:
|
|
11
|
+
@staticmethod
|
|
12
|
+
def _make_sync_request(
|
|
13
|
+
method: str,
|
|
14
|
+
url: str,
|
|
15
|
+
timeout: int = 10,
|
|
16
|
+
data: Optional[Union[Dict[str, Any], str, bytes]] = None,
|
|
17
|
+
json: Optional[Dict[str, Any]] = None,
|
|
18
|
+
files: Optional[Files] = None,
|
|
19
|
+
params: Optional[Dict[str, Any]] = None,
|
|
20
|
+
headers: Optional[Headers] = None,
|
|
21
|
+
downloadFile: bool = False,
|
|
22
|
+
) -> Dict[str, Any]:
|
|
23
|
+
try:
|
|
24
|
+
with httpx.Client(timeout=httpx.Timeout(timeout)) as client:
|
|
25
|
+
response = client.request(
|
|
26
|
+
method,
|
|
27
|
+
url,
|
|
28
|
+
data=data,
|
|
29
|
+
json=json,
|
|
30
|
+
files=files,
|
|
31
|
+
params=params,
|
|
32
|
+
headers=headers,
|
|
33
|
+
)
|
|
34
|
+
print
|
|
35
|
+
response.raise_for_status() # 检查 HTTP 错误
|
|
36
|
+
if downloadFile:
|
|
37
|
+
return {
|
|
38
|
+
"status_code": response.status_code,
|
|
39
|
+
"headers": dict(response.headers),
|
|
40
|
+
"content": response.content,
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
"status_code": response.status_code,
|
|
44
|
+
"headers": dict(response.headers),
|
|
45
|
+
"json": response.json(),
|
|
46
|
+
}
|
|
47
|
+
except httpx.TimeoutException:
|
|
48
|
+
# 处理超时错误
|
|
49
|
+
return {"status_code": None, "headers": None, "error": "Request timed out"}
|
|
50
|
+
except httpx.HTTPStatusError as e:
|
|
51
|
+
return {
|
|
52
|
+
"status_code": e.response.status_code,
|
|
53
|
+
"headers": dict(e.response.headers),
|
|
54
|
+
"error": str(e),
|
|
55
|
+
}
|
|
56
|
+
except httpx.RequestError as e:
|
|
57
|
+
return {
|
|
58
|
+
"status_code": None,
|
|
59
|
+
"headers": None,
|
|
60
|
+
"error": f"Request error: {e}",
|
|
61
|
+
}
|
|
62
|
+
except Exception as e:
|
|
63
|
+
return {
|
|
64
|
+
"status_code": None,
|
|
65
|
+
"headers": None,
|
|
66
|
+
"error": f"Unexpected error: {e}",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@staticmethod
|
|
70
|
+
def hander_response(response):
|
|
71
|
+
if response["status_code"] == 200:
|
|
72
|
+
return response
|
|
73
|
+
else:
|
|
74
|
+
raise Exception(response["error"])
|
|
75
|
+
|
|
76
|
+
@staticmethod
|
|
77
|
+
def get_sync(
|
|
78
|
+
url: str,
|
|
79
|
+
timeout: int = 10,
|
|
80
|
+
params: Optional[Dict[str, Any]] = None,
|
|
81
|
+
headers: Optional[Headers] = None,
|
|
82
|
+
) -> Dict[str, Any]:
|
|
83
|
+
return HttpClient._make_sync_request(
|
|
84
|
+
"GET", url, timeout=timeout, params=params, headers=headers
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
@staticmethod
|
|
88
|
+
def get_file_sync(
|
|
89
|
+
url: str,
|
|
90
|
+
timeout: int = 10,
|
|
91
|
+
params: Optional[Dict[str, Any]] = None,
|
|
92
|
+
headers: Optional[Headers] = None,
|
|
93
|
+
):
|
|
94
|
+
response = HttpClient._make_sync_request(
|
|
95
|
+
"GET",
|
|
96
|
+
url,
|
|
97
|
+
timeout=timeout,
|
|
98
|
+
params=params,
|
|
99
|
+
headers=headers,
|
|
100
|
+
downloadFile=True,
|
|
101
|
+
)
|
|
102
|
+
return response
|
|
103
|
+
|
|
104
|
+
@staticmethod
|
|
105
|
+
def post_sync(
|
|
106
|
+
url: str,
|
|
107
|
+
timeout: int = 10,
|
|
108
|
+
data: Optional[Union[Dict[str, Any], str, bytes]] = None,
|
|
109
|
+
json: Optional[Dict[str, Any]] = None,
|
|
110
|
+
files: Optional[Files] = None,
|
|
111
|
+
headers: Optional[Headers] = None,
|
|
112
|
+
) -> Dict[str, Any]:
|
|
113
|
+
return HttpClient._make_sync_request(
|
|
114
|
+
"POST",
|
|
115
|
+
url,
|
|
116
|
+
timeout=timeout,
|
|
117
|
+
data=data,
|
|
118
|
+
json=json,
|
|
119
|
+
files=files,
|
|
120
|
+
headers=headers,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
@staticmethod
|
|
124
|
+
def put_sync(
|
|
125
|
+
url: str,
|
|
126
|
+
timeout: int = 10,
|
|
127
|
+
data: Optional[Union[Dict[str, Any], str, bytes]] = None,
|
|
128
|
+
json: Optional[Dict[str, Any]] = None,
|
|
129
|
+
headers: Optional[Headers] = None,
|
|
130
|
+
) -> Dict[str, Any]:
|
|
131
|
+
return HttpClient._make_sync_request(
|
|
132
|
+
"PUT", url, timeout=timeout, data=data, json=json, headers=headers
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
@staticmethod
|
|
136
|
+
def delete_sync(
|
|
137
|
+
url: str,
|
|
138
|
+
timeout: int = 10,
|
|
139
|
+
params: Optional[Dict[str, Any]] = None,
|
|
140
|
+
headers: Optional[Headers] = None,
|
|
141
|
+
) -> Dict[str, Any]:
|
|
142
|
+
return HttpClient._make_sync_request(
|
|
143
|
+
"DELETE", url, timeout=timeout, params=params, headers=headers
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
@staticmethod
|
|
147
|
+
async def _make_async_request(
|
|
148
|
+
method: str,
|
|
149
|
+
url: str,
|
|
150
|
+
timeout: int = 10,
|
|
151
|
+
data: Optional[Union[Dict[str, Any], str, bytes]] = None,
|
|
152
|
+
json: Optional[Dict[str, Any]] = None,
|
|
153
|
+
files: Optional[Files] = None,
|
|
154
|
+
params: Optional[Dict[str, Any]] = None,
|
|
155
|
+
headers: Optional[Headers] = None,
|
|
156
|
+
) -> Dict[str, Any]:
|
|
157
|
+
try:
|
|
158
|
+
async with httpx.AsyncClient(timeout=httpx.Timeout(timeout)) as client:
|
|
159
|
+
response = await client.request(
|
|
160
|
+
method,
|
|
161
|
+
url,
|
|
162
|
+
data=data,
|
|
163
|
+
json=json,
|
|
164
|
+
files=files,
|
|
165
|
+
params=params,
|
|
166
|
+
headers=headers,
|
|
167
|
+
)
|
|
168
|
+
response.raise_for_status() # 检查 HTTP 错误
|
|
169
|
+
return {
|
|
170
|
+
"status_code": response.status_code,
|
|
171
|
+
"headers": dict(response.headers),
|
|
172
|
+
"json": response.json(),
|
|
173
|
+
}
|
|
174
|
+
except httpx.TimeoutException:
|
|
175
|
+
# 处理超时错误
|
|
176
|
+
return {"status_code": None, "headers": None, "error": "Request timed out"}
|
|
177
|
+
except httpx.HTTPStatusError as e:
|
|
178
|
+
return {
|
|
179
|
+
"status_code": e.response.status_code,
|
|
180
|
+
"headers": dict(e.response.headers),
|
|
181
|
+
"error": str(e),
|
|
182
|
+
}
|
|
183
|
+
except httpx.RequestError as e:
|
|
184
|
+
return {
|
|
185
|
+
"status_code": None,
|
|
186
|
+
"headers": None,
|
|
187
|
+
"error": f"Request error: {e}",
|
|
188
|
+
}
|
|
189
|
+
except Exception as e:
|
|
190
|
+
return {
|
|
191
|
+
"status_code": None,
|
|
192
|
+
"headers": None,
|
|
193
|
+
"error": f"Unexpected error: {e}",
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
@staticmethod
|
|
197
|
+
async def get_async(
|
|
198
|
+
url: str,
|
|
199
|
+
timeout: int = 10,
|
|
200
|
+
params: Optional[Dict[str, Any]] = None,
|
|
201
|
+
headers: Optional[Headers] = None,
|
|
202
|
+
) -> Dict[str, Any]:
|
|
203
|
+
return await HttpClient._make_async_request(
|
|
204
|
+
"GET", url, timeout=timeout, params=params, headers=headers
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
@staticmethod
|
|
208
|
+
async def post_async(
|
|
209
|
+
url: str,
|
|
210
|
+
timeout: int = 10,
|
|
211
|
+
data: Optional[Union[Dict[str, Any], str, bytes]] = None,
|
|
212
|
+
json: Optional[Dict[str, Any]] = None,
|
|
213
|
+
files: Optional[Files] = None,
|
|
214
|
+
headers: Optional[Headers] = None,
|
|
215
|
+
) -> Dict[str, Any]:
|
|
216
|
+
return await HttpClient._make_async_request(
|
|
217
|
+
"POST",
|
|
218
|
+
url,
|
|
219
|
+
timeout=timeout,
|
|
220
|
+
data=data,
|
|
221
|
+
json=json,
|
|
222
|
+
files=files,
|
|
223
|
+
headers=headers,
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
@staticmethod
|
|
227
|
+
async def put_async(
|
|
228
|
+
url: str,
|
|
229
|
+
timeout: int = 10,
|
|
230
|
+
data: Optional[Union[Dict[str, Any], str, bytes]] = None,
|
|
231
|
+
json: Optional[Dict[str, Any]] = None,
|
|
232
|
+
headers: Optional[Headers] = None,
|
|
233
|
+
) -> Dict[str, Any]:
|
|
234
|
+
return await HttpClient._make_async_request(
|
|
235
|
+
"PUT", url, timeout=timeout, data=data, json=json, headers=headers
|
|
236
|
+
)
|
|
237
|
+
|
|
238
|
+
@staticmethod
|
|
239
|
+
async def delete_async(
|
|
240
|
+
url: str,
|
|
241
|
+
timeout: int = 10,
|
|
242
|
+
params: Optional[Dict[str, Any]] = None,
|
|
243
|
+
headers: Optional[Headers] = None,
|
|
244
|
+
) -> Dict[str, Any]:
|
|
245
|
+
return await HttpClient._make_async_request(
|
|
246
|
+
"DELETE", url, timeout=timeout, params=params, headers=headers
|
|
247
|
+
)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Author: DiChen
|
|
3
|
+
Date: 2024-09-09 21:19:00
|
|
4
|
+
LastEditors: DiChen
|
|
5
|
+
LastEditTime: 2024-09-09 21:25:48
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MDL:
|
|
10
|
+
# TODO:应该为动态IP
|
|
11
|
+
def __init__(self):
|
|
12
|
+
self.ip = "172.21.252.204"
|
|
13
|
+
self.port = 8061
|
|
14
|
+
self.origin_lists = {}
|
|
15
|
+
|
|
16
|
+
def resolvingMDL(self, mdlData: dict):
|
|
17
|
+
if mdlData:
|
|
18
|
+
self.origin_lists = self.parse_model_data(mdlData)
|
|
19
|
+
return self.origin_lists
|
|
20
|
+
else:
|
|
21
|
+
# TODO: 处理无mdl的情况
|
|
22
|
+
return None
|
|
23
|
+
|
|
24
|
+
####################### private#######################
|
|
25
|
+
|
|
26
|
+
def parse_model_data(self, mdl_data: dict):
|
|
27
|
+
def extract_children(udx_node):
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
"eventId": child["name"],
|
|
31
|
+
"eventName": child["name"],
|
|
32
|
+
"eventDesc": child["name"],
|
|
33
|
+
"eventType": child["type"]
|
|
34
|
+
.replace("DTKT_", "")
|
|
35
|
+
.replace("REAL", "FLOAT"),
|
|
36
|
+
"child": "true",
|
|
37
|
+
"value": "",
|
|
38
|
+
}
|
|
39
|
+
for child in udx_node.get("UdxNode", [])
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
def process_event(event, evt, dataset_item, data, is_input=True):
|
|
43
|
+
entry_type = "inputs" if is_input else "outputs"
|
|
44
|
+
entry = {
|
|
45
|
+
"statename": event.get("name"),
|
|
46
|
+
"event": evt.get("name"),
|
|
47
|
+
"optional": evt.get("optional"),
|
|
48
|
+
}
|
|
49
|
+
if is_input:
|
|
50
|
+
entry.update(
|
|
51
|
+
{
|
|
52
|
+
"url": "",
|
|
53
|
+
"tag": dataset_item.get("name"),
|
|
54
|
+
"suffix": "",
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
else:
|
|
58
|
+
entry["template"] = {
|
|
59
|
+
"type": "id" if "externalId" in dataset_item else "None",
|
|
60
|
+
"value": dataset_item.get("externalId", ""),
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if dataset_item["type"] == "internal" and dataset_item.get(
|
|
64
|
+
"UdxDeclaration"
|
|
65
|
+
):
|
|
66
|
+
udx_node = dataset_item["UdxDeclaration"][0].get("UdxNode")
|
|
67
|
+
if udx_node:
|
|
68
|
+
entry["children"] = extract_children(
|
|
69
|
+
dataset_item["UdxDeclaration"][0]["UdxNode"][0]
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
data[entry_type].append(entry)
|
|
73
|
+
|
|
74
|
+
data = {
|
|
75
|
+
"outputs": [],
|
|
76
|
+
"port": self.port, # Fill with actual port if available
|
|
77
|
+
"inputs": [],
|
|
78
|
+
"ip": self.ip, # Fill with actual IP if available
|
|
79
|
+
"pid": mdl_data.get("md5", ""),
|
|
80
|
+
"oid": mdl_data.get("id", ""),
|
|
81
|
+
"username": "", # Fill with actual username if available
|
|
82
|
+
}
|
|
83
|
+
related_datasets = mdl_data["mdlJson"]["ModelClass"][0]["Behavior"][0][
|
|
84
|
+
"RelatedDatasets"
|
|
85
|
+
][0]["DatasetItem"]
|
|
86
|
+
|
|
87
|
+
for model_class in mdl_data.get("mdlJson", {}).get("ModelClass", []):
|
|
88
|
+
for behavior in model_class.get("Behavior", []):
|
|
89
|
+
for state_group in behavior.get("StateGroup", []):
|
|
90
|
+
for state in state_group.get("States", []):
|
|
91
|
+
for event in state.get("State", []):
|
|
92
|
+
for evt in event.get("Event", []):
|
|
93
|
+
dataset_reference = evt.get(
|
|
94
|
+
"ResponseParameter",
|
|
95
|
+
evt.get("DispatchParameter", []),
|
|
96
|
+
)
|
|
97
|
+
for param in dataset_reference:
|
|
98
|
+
dataset_item = next(
|
|
99
|
+
(
|
|
100
|
+
item
|
|
101
|
+
for item in related_datasets
|
|
102
|
+
if item["name"] == param["datasetReference"]
|
|
103
|
+
),
|
|
104
|
+
None,
|
|
105
|
+
)
|
|
106
|
+
if dataset_item:
|
|
107
|
+
process_event(
|
|
108
|
+
event,
|
|
109
|
+
evt,
|
|
110
|
+
dataset_item,
|
|
111
|
+
data,
|
|
112
|
+
is_input=(evt.get("type")
|
|
113
|
+
== "response"),
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
return data
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Author: DiChen
|
|
3
|
+
Date: 2024-09-07 00:58:14
|
|
4
|
+
LastEditors: DiChen
|
|
5
|
+
LastEditTime: 2024-09-09 19:06:45
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .exceptions import NotValueError, modelStatusError
|
|
9
|
+
|
|
10
|
+
STATUS = ["Model sign"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ParameterValidator:
|
|
14
|
+
@staticmethod
|
|
15
|
+
def v_str(param):
|
|
16
|
+
if not isinstance(param, str):
|
|
17
|
+
raise ValueError("Parameter must be a string.")
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def v_int(param):
|
|
21
|
+
if not isinstance(param, int):
|
|
22
|
+
raise ValueError("Parameter must be an integer.")
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def v_float(param):
|
|
26
|
+
if not isinstance(param, float):
|
|
27
|
+
raise ValueError("Parameter must be a float.")
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def v_list(param):
|
|
31
|
+
if not isinstance(param, list):
|
|
32
|
+
raise ValueError("Parameter must be a list.")
|
|
33
|
+
|
|
34
|
+
@staticmethod
|
|
35
|
+
def v_dict(param):
|
|
36
|
+
if not isinstance(param, dict):
|
|
37
|
+
raise ValueError("Parameter must be a dictionary.")
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def v_empty(param, name: str):
|
|
41
|
+
if (
|
|
42
|
+
param is None
|
|
43
|
+
or param == {}
|
|
44
|
+
or param == []
|
|
45
|
+
or (param is str and not param.strip())
|
|
46
|
+
):
|
|
47
|
+
if name in STATUS:
|
|
48
|
+
raise NotValueError(f"{name} occurs error, please try again!")
|
|
49
|
+
raise NotValueError(f"{name} cannot be empty,plesae check!")
|
|
50
|
+
|
|
51
|
+
@staticmethod
|
|
52
|
+
def v_status(param):
|
|
53
|
+
if param == -1 or param == -2:
|
|
54
|
+
raise modelStatusError(f"model service calculate error!")
|
|
55
|
+
return param
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Author: DiChen
|
|
3
|
+
Date: 2024-09-06 17:21:20
|
|
4
|
+
LastEditors: DiChen
|
|
5
|
+
LastEditTime: 2024-09-13 21:54:57
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
Author: DiChen
|
|
10
|
+
Date: 2024-09-06 17:21:20
|
|
11
|
+
LastEditors: DiChen
|
|
12
|
+
LastEditTime: 2024-09-08 16:23:59
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
# 定义状态常量
|
|
16
|
+
STATE_INIT = 0b1 # 1: init
|
|
17
|
+
STATE_RUNNING = 0b10 # 2: running
|
|
18
|
+
STATE_COMPLETED = 0b100 # 4: completed
|
|
19
|
+
STATE_ERROR = 0b1000 # 8: error
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class StateManager:
|
|
23
|
+
def __init__(self):
|
|
24
|
+
# init state
|
|
25
|
+
self.state = STATE_INIT
|
|
26
|
+
print(f"StateManager initialized in state: {bin(self.state)}")
|
|
27
|
+
|
|
28
|
+
def addState(self, state):
|
|
29
|
+
"""add state"""
|
|
30
|
+
self.state |= state
|
|
31
|
+
|
|
32
|
+
def removeState(self, state):
|
|
33
|
+
"""remove state"""
|
|
34
|
+
self.state &= ~state
|
|
35
|
+
|
|
36
|
+
def hasStatus(self, state):
|
|
37
|
+
"""check state"""
|
|
38
|
+
return self.state & state != 0
|
|
39
|
+
|
|
40
|
+
def trans2Status(self, state):
|
|
41
|
+
"""transition to state"""
|
|
42
|
+
if state == STATE_RUNNING and not self.hasStatus(STATE_INIT):
|
|
43
|
+
print("Cannot run without initialization")
|
|
44
|
+
return
|
|
45
|
+
|
|
46
|
+
if state == STATE_COMPLETED and not self.hasStatus(STATE_RUNNING):
|
|
47
|
+
print("Cannot complete without running")
|
|
48
|
+
return
|
|
49
|
+
|
|
50
|
+
if state == STATE_ERROR:
|
|
51
|
+
print("Error occurred, transitioning to ERROR state")
|
|
52
|
+
self.state = state
|
|
53
|
+
return
|
|
54
|
+
|
|
55
|
+
self.state = state
|
|
56
|
+
print(f"Transitioned to state: {bin(self.state)}")
|
|
57
|
+
|
|
58
|
+
def getState(self):
|
|
59
|
+
"""get state"""
|
|
60
|
+
return bin(self.state)
|
|
61
|
+
|
|
62
|
+
def checkInputStatus(self, status):
|
|
63
|
+
"""check input status"""
|
|
64
|
+
if status == 1 and self.state == STATE_INIT:
|
|
65
|
+
self.addState(STATE_RUNNING)
|
|
66
|
+
print("model service calculating!")
|
|
67
|
+
elif status == 2:
|
|
68
|
+
self.addState(STATE_COMPLETED)
|
|
69
|
+
print("model calculation was completed!")
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PyGeoModel
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: An intelligent Python toolkit for geographic modeling with smart model recommendations
|
|
5
|
+
Home-page: https://github.com/yourusername/PyGeoModel
|
|
6
|
+
Author: Your Name
|
|
7
|
+
Author-email: your.email@example.com
|
|
8
|
+
Keywords: geographic modeling,GIS,machine learning,model recommendation,geospatial analysis,jupyter
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: ipywidgets>=7.6.0
|
|
23
|
+
Requires-Dist: requests>=2.25.0
|
|
24
|
+
Requires-Dist: openai>=1.0.0
|
|
25
|
+
Requires-Dist: ipyfilechooser>=0.6.0
|
|
26
|
+
Requires-Dist: markdown>=3.3.0
|
|
27
|
+
Requires-Dist: nest-asyncio>=1.5.0
|
|
28
|
+
Requires-Dist: geopandas>=0.10.0
|
|
29
|
+
Requires-Dist: rasterio>=1.2.0
|
|
30
|
+
Requires-Dist: nbformat>=5.1.0
|
|
31
|
+
Requires-Dist: tenacity>=8.0.0
|
|
32
|
+
Dynamic: author
|
|
33
|
+
Dynamic: author-email
|
|
34
|
+
Dynamic: classifier
|
|
35
|
+
Dynamic: description
|
|
36
|
+
Dynamic: description-content-type
|
|
37
|
+
Dynamic: home-page
|
|
38
|
+
Dynamic: keywords
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
Dynamic: requires-dist
|
|
41
|
+
Dynamic: requires-python
|
|
42
|
+
Dynamic: summary
|
|
43
|
+
|
|
44
|
+
# Model GUI Tool
|
|
45
|
+
|
|
46
|
+
This is a GUI tool for displaying and running computational models, implemented using ipywidgets in Jupyter notebook.
|
|
47
|
+
|
|
48
|
+
## Features
|
|
49
|
+
|
|
50
|
+
- Load model definitions from JSON configuration files
|
|
51
|
+
- Provide graphical interface for model selection, parameter configuration and execution
|
|
52
|
+
- Display model basic information (name, description, author, tags etc.)
|
|
53
|
+
- Support file chooser for model parameter inputs
|
|
54
|
+
- Provide output area for execution results
|
|
55
|
+
- Support multiple model management
|
|
56
|
+
- Real-time model status monitoring
|
|
57
|
+
- Parameter validation and error handling
|
|
58
|
+
- Support model state transitions
|
|
59
|
+
- Export model results to various formats
|
|
60
|
+
- Model comparison and analysis tools
|
|
61
|
+
- Batch processing capabilities
|
|
62
|
+
- Customizable model visualization
|
|
63
|
+
- Integration with external tools and libraries
|
|
64
|
+
- Comprehensive logging and debugging features
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
1. Ensure required dependencies are installed:
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
pygeomodel.py,sha256=3wrUEK4pMlgNyS2t5ryrqNfDA7ldByWEVcUaJebS_kw,103905
|
|
2
|
+
scripts.py,sha256=MMjwutjzMCJSjBcs84zV6gBqAMHH8vBi3a-qM2g2iDQ,5862
|
|
3
|
+
ogmsServer2/__init__.py,sha256=-bD8jrIG4mdQs-Oj7bVVC_tw8266IuY-EmphwMrCx0w,587
|
|
4
|
+
ogmsServer2/base.py,sha256=hKNPHJOERiP05iDrimZDrsCILs-r3GHPmYJ7HLPW0bQ,1160
|
|
5
|
+
ogmsServer2/constants.py,sha256=smDuFk2Xp2T_se0ChGUBLJnSUJNSGRMkU6WDAK0Q3Jg,682
|
|
6
|
+
ogmsServer2/openModel.py,sha256=o5d-ePjQh-0-dzkJxgx1yAdPuDMG6gwty5w49K9f61k,15350
|
|
7
|
+
ogmsServer2/data/PGA.tif,sha256=Yb43WS84mLX0ZYlarjeH3QLyJcSrEu09SH5kXBQvdgc,66368
|
|
8
|
+
ogmsServer2/data/baseclip.tif,sha256=ZLbfJqJ3H62G0_1an-HubttEwLSNbn8WzHIj8agdTg0,263005
|
|
9
|
+
ogmsServer2/data/intensity.tif,sha256=rjpbOA-flY_Xe3sSOlxhg-U4lH4g0vMQSwBXGOGQOso,33600
|
|
10
|
+
ogmsServer2/data/地震群发滑坡概率评估预警模型_67c32dc057e89375/LandSlide-outputIntensitypbtyTif.tif,sha256=b7gwhktEQUmJfBzUjmDxRUnmUSfxvAQTIt0ByxzTWBk,162288
|
|
11
|
+
ogmsServer2/data/地震群发滑坡概率评估预警模型_67c32dc057e89375/LandSlide-outputPGApbtyTif.tif,sha256=gxQtO_3pB6w8LyfhRyqLfVt9oI1P14nbLXSZma0yw-U,162288
|
|
12
|
+
ogmsServer2/data/地震群发滑坡概率评估预警模型_7972c0716caa1213/LandSlide-outputIntensitypbtyTif.tif,sha256=b7gwhktEQUmJfBzUjmDxRUnmUSfxvAQTIt0ByxzTWBk,162288
|
|
13
|
+
ogmsServer2/data/地震群发滑坡概率评估预警模型_7972c0716caa1213/LandSlide-outputPGApbtyTif.tif,sha256=gxQtO_3pB6w8LyfhRyqLfVt9oI1P14nbLXSZma0yw-U,162288
|
|
14
|
+
ogmsServer2/data/地震群发滑坡概率评估预警模型_a044c410df669372/LandSlide-outputIntensitypbtyTif.tif,sha256=b7gwhktEQUmJfBzUjmDxRUnmUSfxvAQTIt0ByxzTWBk,162288
|
|
15
|
+
ogmsServer2/data/地震群发滑坡概率评估预警模型_a044c410df669372/LandSlide-outputPGApbtyTif.tif,sha256=gxQtO_3pB6w8LyfhRyqLfVt9oI1P14nbLXSZma0yw-U,162288
|
|
16
|
+
ogmsServer2/data/地震群发滑坡概率评估预警模型_b6ba56c07bf80c30/LandSlide-outputIntensitypbtyTif.tif,sha256=b7gwhktEQUmJfBzUjmDxRUnmUSfxvAQTIt0ByxzTWBk,162288
|
|
17
|
+
ogmsServer2/data/地震群发滑坡概率评估预警模型_b6ba56c07bf80c30/LandSlide-outputPGApbtyTif.tif,sha256=gxQtO_3pB6w8LyfhRyqLfVt9oI1P14nbLXSZma0yw-U,162288
|
|
18
|
+
ogmsServer2/openUtils/__init__.py,sha256=aDdiNILgqP3y7MWc52pWb06kvFdpFtxrFB0LN2U40rE,480
|
|
19
|
+
ogmsServer2/openUtils/exceptions.py,sha256=lJcX5-BFk-a71ZCSFLVnDj6jYjHRfl6pTAq_9pJABSg,1920
|
|
20
|
+
ogmsServer2/openUtils/http_client.py,sha256=ysL9yAUtvZqUb1CreuM0tu-DcTbloQYn9eLfryGAUBo,7893
|
|
21
|
+
ogmsServer2/openUtils/mdlUtils.py,sha256=gen4oPm4tu9_nMVObd8WPXtLnFqDSSXKhiTLr0cx-nA,4475
|
|
22
|
+
ogmsServer2/openUtils/parameterValidator.py,sha256=aJ1jErdnpCYQl_qesLbIX2TqHe686AMcZ3OZRQZNKcI,1490
|
|
23
|
+
ogmsServer2/openUtils/stateManager.py,sha256=i-o-I3jif65S5ExGZRS1qRD3a80Gb0JI_T8-lOvyz9o,1826
|
|
24
|
+
pygeomodel-1.0.0.dist-info/licenses/LICENSE,sha256=d0s_lsrYXV0oUUz3EkBpLyFMjg4kQzOnm2wxgA1wu5g,1067
|
|
25
|
+
pygeomodel-1.0.0.dist-info/METADATA,sha256=60iZNI8rHiMLLXQqC3rHEwRZwha4kUGWF5h0fLg8Sfw,2430
|
|
26
|
+
pygeomodel-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
27
|
+
pygeomodel-1.0.0.dist-info/top_level.txt,sha256=FZA4z-JV_S6Z1vMeG01FRhWHq5C-ckm8ZrZwymhHIEM,31
|
|
28
|
+
pygeomodel-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 PyGeoModel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|