Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
357 changes: 357 additions & 0 deletions examples/data_usage.ipynb

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion geoengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from geoengine_openapi_client.exceptions import BadRequestException, OpenApiException, ApiTypeError, ApiValueError, \
ApiKeyError, ApiAttributeError, ApiException, NotFoundException
from geoengine_openapi_client import UsageSummaryGranularity
from .auth import Session, get_session, initialize, reset
from .colorizer import Colorizer, ColorBreakpoint, LinearGradientColorizer, PaletteColorizer, \
LogarithmicGradientColorizer
Expand All @@ -30,7 +31,8 @@
MultiBandRasterColorizer

from .util import clamp_datetime_ms_ns
from .workflow import WorkflowId, Workflow, workflow_by_id, register_workflow, get_quota, update_quota
from .workflow import WorkflowId, Workflow, workflow_by_id, register_workflow, get_quota, update_quota, data_usage, \
data_usage_summary
from .raster import RasterTile2D
from .raster_workflow_rio_writer import RasterWorkflowRioWriter

Expand Down
39 changes: 39 additions & 0 deletions geoengine/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,3 +967,42 @@ def update_quota(user_id: UUID, new_available_quota: int, timeout: int = 60) ->
),
_request_timeout=timeout
)


def data_usage(offset: int = 0, limit: int = 10) -> List[geoengine_openapi_client.DataUsage]:
'''
Get data usage
'''

session = get_session()

with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
user_api = geoengine_openapi_client.UserApi(api_client)
response = user_api.data_usage_handler(offset=offset, limit=limit)

# create dataframe from response
usage_dicts = [data_usage.dict(by_alias=True) for data_usage in response]
df = pd.DataFrame(usage_dicts)

return df


def data_usage_summary(granularity: geoengine_openapi_client.UsageSummaryGranularity,
data: Optional[str] = None,
offset: int = 0, limit: int = 10) -> pd.DataFrame:
'''
Get data usage summary
'''

session = get_session()

with geoengine_openapi_client.ApiClient(session.configuration) as api_client:
user_api = geoengine_openapi_client.UserApi(api_client)
response = user_api.data_usage_summary_handler(data=data, granularity=granularity,
offset=offset, limit=limit)

# create dataframe from response
usage_dicts = [data_usage.dict(by_alias=True) for data_usage in response]
df = pd.DataFrame(usage_dicts)

return df
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package_dir =
packages = find:
python_requires = >=3.9
install_requires =
geoengine-openapi-client == 0.0.17
geoengine-openapi-client == 0.0.18
geopandas >=0.9,<0.15
matplotlib >=3.5,<3.8
numpy >=1.21,<2
Expand Down