geobox 2.0.1__py3-none-any.whl → 2.2.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.
- geobox/__init__.py +61 -63
- geobox/aio/__init__.py +61 -63
- geobox/aio/api.py +489 -473
- geobox/aio/apikey.py +263 -263
- geobox/aio/attachment.py +341 -339
- geobox/aio/base.py +261 -262
- geobox/aio/basemap.py +196 -196
- geobox/aio/dashboard.py +340 -342
- geobox/aio/feature.py +23 -33
- geobox/aio/field.py +315 -321
- geobox/aio/file.py +72 -72
- geobox/aio/layout.py +340 -341
- geobox/aio/log.py +23 -23
- geobox/aio/map.py +1033 -1034
- geobox/aio/model3d.py +415 -415
- geobox/aio/mosaic.py +696 -696
- geobox/aio/plan.py +314 -314
- geobox/aio/query.py +693 -693
- geobox/aio/raster.py +907 -869
- geobox/aio/raster_analysis.py +740 -0
- geobox/aio/route.py +4 -4
- geobox/aio/scene.py +340 -342
- geobox/aio/settings.py +18 -18
- geobox/aio/task.py +404 -402
- geobox/aio/tile3d.py +337 -339
- geobox/aio/tileset.py +102 -103
- geobox/aio/usage.py +52 -51
- geobox/aio/user.py +506 -507
- geobox/aio/vector_tool.py +1968 -0
- geobox/aio/vectorlayer.py +315 -306
- geobox/aio/version.py +272 -273
- geobox/aio/view.py +1019 -983
- geobox/aio/workflow.py +340 -341
- geobox/api.py +18 -2
- geobox/apikey.py +262 -262
- geobox/attachment.py +336 -337
- geobox/base.py +384 -384
- geobox/basemap.py +194 -194
- geobox/dashboard.py +339 -341
- geobox/enums.py +432 -348
- geobox/feature.py +5 -5
- geobox/field.py +320 -320
- geobox/file.py +4 -4
- geobox/layout.py +339 -340
- geobox/log.py +4 -4
- geobox/map.py +1031 -1032
- geobox/model3d.py +410 -410
- geobox/mosaic.py +696 -696
- geobox/plan.py +313 -313
- geobox/query.py +691 -691
- geobox/raster.py +907 -863
- geobox/raster_analysis.py +737 -0
- geobox/scene.py +341 -342
- geobox/settings.py +194 -194
- geobox/task.py +399 -400
- geobox/tile3d.py +337 -338
- geobox/tileset.py +4 -4
- geobox/usage.py +3 -3
- geobox/user.py +503 -503
- geobox/vector_tool.py +1968 -0
- geobox/vectorlayer.py +5 -5
- geobox/version.py +272 -272
- geobox/view.py +981 -981
- geobox/workflow.py +338 -339
- {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/METADATA +15 -1
- geobox-2.2.0.dist-info/RECORD +72 -0
- geobox-2.0.1.dist-info/RECORD +0 -68
- {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/WHEEL +0 -0
- {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/licenses/LICENSE +0 -0
- {geobox-2.0.1.dist-info → geobox-2.2.0.dist-info}/top_level.txt +0 -0
geobox/aio/usage.py
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
from urllib.parse import urlencode
|
|
2
|
-
from typing import
|
|
1
|
+
from urllib.parse import urlencode
|
|
2
|
+
from typing import Dict, List, Union, TYPE_CHECKING
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
|
|
5
5
|
from .base import AsyncBase
|
|
6
|
-
from .user import
|
|
7
|
-
from .apikey import
|
|
6
|
+
from .user import AsyncUser
|
|
7
|
+
from .apikey import AsyncApiKey
|
|
8
8
|
from ..utils import clean_data
|
|
9
9
|
from ..enums import UsageScale, UsageParam
|
|
10
10
|
|
|
11
11
|
if TYPE_CHECKING:
|
|
12
12
|
from . import AsyncGeoboxClient
|
|
13
|
-
from ..api import GeoboxClient
|
|
14
|
-
from ..usage import Usage
|
|
13
|
+
from ..api import GeoboxClient
|
|
14
|
+
from ..usage import Usage
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
class
|
|
17
|
+
class AsyncUsage(AsyncBase):
|
|
18
18
|
|
|
19
19
|
BASE_ENDPOINT = 'usage/'
|
|
20
20
|
|
|
21
21
|
def __init__(self,
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
api: 'AsyncGeoboxClient',
|
|
23
|
+
user: 'AsyncUser'):
|
|
24
24
|
"""
|
|
25
25
|
Constructs the necessary attributes for the Usage object.
|
|
26
26
|
|
|
@@ -39,25 +39,25 @@ class Usage(AsyncBase):
|
|
|
39
39
|
Returns:
|
|
40
40
|
str: A string representation of the Usage object.
|
|
41
41
|
"""
|
|
42
|
-
return f"
|
|
42
|
+
return f"AsyncUsage(user={self.user})"
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
@classmethod
|
|
46
46
|
async def get_api_usage(cls,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
api: 'AsyncGeoboxClient',
|
|
48
|
+
resource: Union['AsyncUser', 'AsyncApiKey'],
|
|
49
|
+
scale: 'UsageScale',
|
|
50
|
+
param: 'UsageParam',
|
|
51
|
+
from_date: 'datetime' = None,
|
|
52
|
+
to_date: 'datetime' = None,
|
|
53
|
+
days_before_now: int = None,
|
|
54
|
+
limit: int = None) -> List:
|
|
55
55
|
"""
|
|
56
56
|
[async] Get the api usage of a user
|
|
57
57
|
|
|
58
58
|
Args:
|
|
59
59
|
api (AsyncGeoboxClient): The AsyncGeoboxClient instance for making requests.
|
|
60
|
-
resource (
|
|
60
|
+
resource (AsyncUser | AsyncApiKey): User or ApiKey object.
|
|
61
61
|
scale (UsageScale): the scale of the report.
|
|
62
62
|
param (UsageParam): traffic or calls.
|
|
63
63
|
from_date (datetime, optional): datetime object in this format: "%Y-%m-%dT%H:%M:%S".
|
|
@@ -74,10 +74,10 @@ class Usage(AsyncBase):
|
|
|
74
74
|
|
|
75
75
|
Example:
|
|
76
76
|
>>> from geobox.aio import AsyncGeoboxClient
|
|
77
|
-
>>> from geobox.aio.usage import
|
|
77
|
+
>>> from geobox.aio.usage import AsyncUsage
|
|
78
78
|
>>> async with AsyncGeoboxClient() as client:
|
|
79
79
|
>>> user = await client.get_user() # gets current user
|
|
80
|
-
>>> usage = await
|
|
80
|
+
>>> usage = await AsyncUsage.get_api_usage(client,
|
|
81
81
|
... resource=user,
|
|
82
82
|
... scale=UsageScale.Day,
|
|
83
83
|
... param=UsageParam.Calls,
|
|
@@ -92,21 +92,22 @@ class Usage(AsyncBase):
|
|
|
92
92
|
raise ValueError("one of days_before_now or from_date/to_date parameters must have value")
|
|
93
93
|
|
|
94
94
|
params = {}
|
|
95
|
-
if isinstance(resource,
|
|
95
|
+
if isinstance(resource, AsyncUser):
|
|
96
96
|
params['eid'] = resource.user_id
|
|
97
|
-
elif isinstance(resource,
|
|
97
|
+
elif isinstance(resource, AsyncApiKey):
|
|
98
98
|
params['eid'] = resource.key
|
|
99
99
|
else:
|
|
100
|
-
raise ValueError("resource must be a '
|
|
101
|
-
|
|
102
|
-
params = clean_data({
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
raise ValueError("resource must be a 'AsyncUser' or 'AsyncApikey' object")
|
|
101
|
+
|
|
102
|
+
params = clean_data({
|
|
103
|
+
**params,
|
|
104
|
+
'scale': scale.value if scale else None,
|
|
105
|
+
'param': param.value if param else None,
|
|
106
|
+
'from_date': from_date.strftime("%Y-%m-%dT%H:%M:%S.%f") if from_date else None,
|
|
107
|
+
'to_date': to_date.strftime("%Y-%m-%dT%H:%M:%S.%f") if to_date else None,
|
|
108
|
+
'days_before_now': days_before_now,
|
|
109
|
+
'limit': limit
|
|
110
|
+
})
|
|
110
111
|
query_strings = urlencode(params)
|
|
111
112
|
endpoint = f"{cls.BASE_ENDPOINT}api?{query_strings}"
|
|
112
113
|
|
|
@@ -115,11 +116,11 @@ class Usage(AsyncBase):
|
|
|
115
116
|
|
|
116
117
|
@classmethod
|
|
117
118
|
async def get_process_usage(cls,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
api: 'AsyncGeoboxClient',
|
|
120
|
+
user_id: int = None,
|
|
121
|
+
from_date: datetime = None,
|
|
122
|
+
to_date: datetime = None,
|
|
123
|
+
days_before_now: int = None) -> float:
|
|
123
124
|
"""
|
|
124
125
|
[async] Get process usage of a user in seconds
|
|
125
126
|
|
|
@@ -138,9 +139,9 @@ class Usage(AsyncBase):
|
|
|
138
139
|
|
|
139
140
|
Example:
|
|
140
141
|
>>> from geobox.aio import AsyncGeoboxClient
|
|
141
|
-
>>> from geobox.aio.usage import
|
|
142
|
+
>>> from geobox.aio.usage import AsyncUsage
|
|
142
143
|
>>> async with AsyncGeoboxClient() as client:
|
|
143
|
-
>>> process_usage = await
|
|
144
|
+
>>> process_usage = await AsyncUsage.get_process_usage(client, days_before_now=5)
|
|
144
145
|
or
|
|
145
146
|
>>> process_usage = await client.get_process_usage(days_before_now=5)
|
|
146
147
|
"""
|
|
@@ -172,9 +173,9 @@ class Usage(AsyncBase):
|
|
|
172
173
|
|
|
173
174
|
Returns:
|
|
174
175
|
>>> from geobox.aio import AsyncGeoboxClient
|
|
175
|
-
>>> from geobox.aio.usage import
|
|
176
|
+
>>> from geobox.aio.usage import AsyncUsage
|
|
176
177
|
>>> async with AsyncGeoboxClient() as client:
|
|
177
|
-
>>> usage_summary = await
|
|
178
|
+
>>> usage_summary = await AsyncUsage.get_usage_summary(client)
|
|
178
179
|
or
|
|
179
180
|
>>> usage_summary = await client.get_usage_summary()
|
|
180
181
|
"""
|
|
@@ -200,9 +201,9 @@ class Usage(AsyncBase):
|
|
|
200
201
|
|
|
201
202
|
Example:
|
|
202
203
|
>>> from geobox.aio import AsyncGeoboxClient
|
|
203
|
-
>>> from geobox.aio.usage import
|
|
204
|
+
>>> from geobox.aio.usage import AsyncUsage
|
|
204
205
|
>>> async with AsyncGeoboxClient() as client:
|
|
205
|
-
>>> await
|
|
206
|
+
>>> await AsyncUsage.update_usage(client)
|
|
206
207
|
or
|
|
207
208
|
>>> await client.update_usage()
|
|
208
209
|
"""
|
|
@@ -213,31 +214,31 @@ class Usage(AsyncBase):
|
|
|
213
214
|
return await api.post(endpoint, payload=data)
|
|
214
215
|
|
|
215
216
|
|
|
216
|
-
def to_sync(self, sync_client: '
|
|
217
|
+
def to_sync(self, sync_client: 'GeoboxClient') -> 'Usage':
|
|
217
218
|
"""
|
|
218
219
|
Switch to sync version of the usage instance to have access to the sync methods
|
|
219
220
|
|
|
220
221
|
Args:
|
|
221
|
-
sync_client (
|
|
222
|
+
sync_client (GeoboxClient): The sync version of the GeoboxClient instance for making requests.
|
|
222
223
|
|
|
223
224
|
Returns:
|
|
224
|
-
|
|
225
|
+
Usage: the sync instance of the usage.
|
|
225
226
|
|
|
226
227
|
Example:
|
|
227
228
|
>>> from geobox import Geoboxclient
|
|
228
229
|
>>> from geobox.aio import AsyncGeoboxClient
|
|
229
|
-
>>> from geobox.aio.usage import
|
|
230
|
+
>>> from geobox.aio.usage import AsyncUsage
|
|
230
231
|
>>> client = GeoboxClient()
|
|
231
232
|
>>> async with AsyncGeoboxClient() as async_client:
|
|
232
233
|
>>> user = await async_client.get_user()
|
|
233
|
-
>>> usage = await
|
|
234
|
+
>>> usage = await AsyncUsage.get_api_usage(async_client,
|
|
234
235
|
... resource=user,
|
|
235
236
|
... scale=UsageScale.Day,
|
|
236
237
|
... param=UsageParam.Calls,
|
|
237
238
|
... days_before_now=5)
|
|
238
239
|
>>> sync_usage = await usage.to_sync(client)
|
|
239
240
|
"""
|
|
240
|
-
from ..usage import Usage
|
|
241
|
+
from ..usage import Usage
|
|
241
242
|
|
|
242
243
|
user = self.user.to_sync(sync_client)
|
|
243
|
-
return
|
|
244
|
+
return Usage(api=sync_client, user=user)
|