Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
#337 initial state for Data Source Status reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof (Chris) Bernat committed Sep 27, 2017
1 parent 45f2f40 commit e8c0450
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
22 changes: 22 additions & 0 deletions cate/core/ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@

import glob
from abc import ABCMeta, abstractmethod
from enum import Enum
from math import ceil, sqrt
from typing import Sequence, Optional, Union, Tuple, Any

Expand Down Expand Up @@ -137,6 +138,13 @@ def protocols(self) -> []:
def data_store(self) -> 'DataStore':
"""The data store to which this data source belongs."""

@property
def status(self) -> 'DataSourceStatus':
"""
Return information about data source accessibility
"""
return DataSourceStatus.READY

# TODO (forman): issue #399 - remove "ds_id", see TODO on "DataStore.query()"
def matches(self, ds_id: str = None, query_expr: str = None) -> bool:
"""
Expand Down Expand Up @@ -330,6 +338,20 @@ def _repr_html_(self):
"""Provide an HTML representation of this object for IPython."""


class DataSourceStatus(Enum):
"""
Enum stating current state of Data Source accessibility.
* READY - data is complete and ready to use
* ERROR - data initialization process has been interrupted, causing that data source is incomplete or/and corrupted
* PROCESSING - data source initialization process is in progress.
* CANCELLED - data initialization process has been intentionally interrupted by user
"""
READY = "READY",
ERROR = "ERROR",
PROCESSING = "PROCESSING",
CANCELLED = "CANCELLED"


class DataStore(metaclass=ABCMeta):
"""
Represents a data store of data sources.
Expand Down
23 changes: 14 additions & 9 deletions cate/ds/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

from cate.conf import get_config_value, get_data_stores_path
from cate.conf.defaults import NETCDF_COMPRESSION_LEVEL
from cate.core.ds import DATA_STORE_REGISTRY, DataStore, DataSource, open_xarray_dataset
from cate.core.ds import DATA_STORE_REGISTRY, DataSourceStatus, DataStore, DataSource, open_xarray_dataset
from cate.core.types import Polygon, PolygonLike, TimeRange, TimeRangeLike, VarNames, VarNamesLike
from cate.util.monitor import Monitor

Expand All @@ -79,8 +79,8 @@ def add_to_data_store_registry():
# TODO (kbernat): document this class
class LocalDataSource(DataSource):
"""
:param ds_id:
Local Data Source implementation provides access to locally stored data sets.
:param ds_id: unique ID of data source
:param files:
:param data_store:
:param temporal_coverage:
Expand Down Expand Up @@ -131,7 +131,7 @@ def __init__(self,
'standard_name': ''
} for var_name in self._variables]

self._is_complete = True
self._state = DataSourceStatus.READY

def _resolve_file_path(self, path) -> Sequence:
return glob(os.path.join(self._data_store.data_store_path, path))
Expand Down Expand Up @@ -540,6 +540,10 @@ def spatial_coverage(self):
def data_store(self) -> DataStore:
return self._data_store

@property
def status(self) -> DataSourceStatus:
return self._status

@property
def id(self) -> str:
return self._id
Expand All @@ -562,7 +566,7 @@ def is_complete(self) -> bool:
Return a DataSource creation state
:return:
"""
return self._is_complete
return self._state is DataSourceStatus.READY

@property
def is_empty(self) -> bool:
Expand All @@ -574,11 +578,12 @@ def is_empty(self) -> bool:

def set_completed(self, state: bool):
"""
Sets state of DataSource creation/completion
:param state: Is DataSource completed
:return:
Sets state of DataSource completion
"""
self._is_complete = state
if state:
self._state = DataSourceStatus.READY
else:
self._state = DataSourceStatus.PROCESSING

def _repr_html_(self):
import html
Expand Down

0 comments on commit e8c0450

Please sign in to comment.