Skip to content

Commit

Permalink
Merge pull request #72 from neuroforgede/wip/django42/main
Browse files Browse the repository at this point in the history
improve typing
  • Loading branch information
s4ke authored Nov 11, 2023
2 parents 3d625a4 + e337b38 commit 110a980
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
21 changes: 14 additions & 7 deletions skipper/skipper/dataseries/storage/contract/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@ class Meta:
fields: Any = []


class BaseDataSeries_DataPointViewSet(Protocol):
action: str
skipper_base_name: str
class BaseDataSeries_DataPointViewSetBulk(Protocol):
def get_serializer_context(self) -> Dict[str, Any]: ...
def access_data_series(self) -> DataSeries: ...

class BaseDataSeries_DataPointViewSetWithSerialization(Protocol):
def get_serializer(self, *args: Any, **kwargs: Any) -> Any: ...

def get_serializer_context(self) -> Dict[str, Any]: ...
class BaseDataSeries_DataPointViewSetCheckExternalIds(Protocol):
def access_data_series(self) -> DataSeries: ...

# this should be a Protocol, but mypy doesn't support that yet
class BaseDataSeries_DataPointViewSet(Protocol):
action: str
skipper_base_name: str

def access_data_series(self) -> DataSeries: ...

Expand Down Expand Up @@ -181,7 +188,7 @@ def data_point_count(self, view: BaseDataSeries_DataPointViewSet) -> int:
@abstractmethod
def create_bulk(
self,
view: BaseDataSeries_DataPointViewSet,
view: BaseDataSeries_DataPointViewSetBulk,
point_in_time_timestamp: float,
user_id: str,
record_source: str,
Expand All @@ -192,10 +199,10 @@ def create_bulk(
raise NotImplementedError()

@abstractmethod
def check_external_ids(self, view: BaseDataSeries_DataPointViewSet, external_ids: List[str]) -> List[str]:
def check_external_ids(self, view: BaseDataSeries_DataPointViewSetCheckExternalIds, external_ids: List[str]) -> List[str]:
raise NotImplementedError()

def serialize_list(self, view: BaseDataSeries_DataPointViewSet, page: Any) -> List[
def serialize_list(self, view: BaseDataSeries_DataPointViewSetWithSerialization, page: Any) -> List[
Dict[str, Any]]:
"""
transforms a given page into a json compatible format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
from skipper.dataseries.storage.contract.base import BaseDataPointModificationSerializer, BaseDataPointSerializer
from skipper.dataseries.storage.contract.factory import \
get_data_point_serializer_for_data_series
from skipper.dataseries.storage.contract.view import BaseDataSeries_DataPointViewSet, StorageViewAdapter
from skipper.dataseries.storage.contract.view import BaseDataSeries_DataPointViewSetCheckExternalIds, \
BaseDataSeries_DataPointViewSetBulk, \
BaseDataSeries_DataPointViewSet, \
StorageViewAdapter
from skipper.dataseries.storage.dynamic_sql.models.datapoint import DataPoint, DisplayDataPoint
from skipper.dataseries.storage.dynamic_sql.queries.check_external_ids import check_external_ids
from skipper.dataseries.storage.dynamic_sql.queries.common import can_use_materialized_table
Expand Down Expand Up @@ -211,8 +214,6 @@ def raw_display_data_point_query(
resolve_dimension_external_ids=external_id_as_dimension_identifier,
data_series_query_info=data_series_query_info
)

print(query_str)

raw = DisplayDataPoint.objects\
.raw(
Expand Down Expand Up @@ -447,7 +448,7 @@ def get_serializer_class(

def create_bulk(
self,
view: BaseDataSeries_DataPointViewSet,
view: BaseDataSeries_DataPointViewSetBulk,
point_in_time_timestamp: float,
user_id: str,
record_source: str,
Expand All @@ -460,14 +461,12 @@ def create_bulk(

task_data_ids: List[int] = []

point_in_time: Optional[datetime.datetime] = view.get_point_in_time()

serializer_class = get_data_point_serializer_for_data_series(
actual_class=DataPointModificationSerializer,
data_series_id=str(data_series_obj.id),
update=True,
point_in_time=point_in_time,
should_include_versions=view.should_include_versions(),
point_in_time=None,
should_include_versions=False,
data_series_query_info=self.data_series_query_info(view.access_data_series())
)
serializer = serializer_class(
Expand Down Expand Up @@ -559,7 +558,7 @@ def create_bulk(

return created_external_ids

def check_external_ids(self, view: BaseDataSeries_DataPointViewSet, external_ids: List[str]) -> List[str]:
def check_external_ids(self, view: BaseDataSeries_DataPointViewSetCheckExternalIds, external_ids: List[str]) -> List[str]:
return check_external_ids(
external_ids=external_ids,
backend=view.access_data_series().backend,
Expand Down
4 changes: 2 additions & 2 deletions skipper/skipper/dataseries/views/datapoint/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from skipper.dataseries.models.metamodel.data_series import DataSeries
from skipper.dataseries.parsers.multipart import DataPointMultipartFormencodeParser
from skipper.dataseries.raw_sql import dbtime
from skipper.dataseries.storage.contract.view import EmptySerializer, BaseDataSeries_DataPointViewSet, \
from skipper.dataseries.storage.contract.view import EmptySerializer, \
StorageViewAdapter
from skipper.dataseries.storage.views import storage_view_adapter
from skipper.dataseries.views.common import get_dataseries_permissions_class
Expand Down Expand Up @@ -67,7 +67,7 @@ def dictreader(self, lines: List[str]) -> csv.DictReader: # type: ignore

class DataSeriesBulkCreateView(CustomizableBrowsableAPIRendererObjectMixin,
GenericAPIView, # type: ignore
BaseDataSeries_DataPointViewSet):
):
"""
For application/json, accepts a list of regular data points wrapped in an object { "batch": [...] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from skipper.core.utils.memoize import Memoize
from skipper.dataseries.models import DATASERIES_PERMISSION_KEY_CHECK_EXTERNAL_IDS
from skipper.dataseries.models.metamodel.data_series import DataSeries
from skipper.dataseries.storage.contract.view import EmptySerializer, BaseDataSeries_DataPointViewSet, \
from skipper.dataseries.storage.contract.view import EmptySerializer, \
StorageViewAdapter
from skipper.dataseries.storage.views import storage_view_adapter
from skipper.dataseries.views.common import get_dataseries_permissions_class
Expand All @@ -30,7 +30,7 @@

class DataSeriesCheckExternalIdsView(CustomizableBrowsableAPIRendererObjectMixin,
GenericAPIView, # type: ignore
BaseDataSeries_DataPointViewSet):
):
"""
For application/json, accepts a list of regular external_ids in the body { "external_ids": [...] }
Expand Down
1 change: 0 additions & 1 deletion skipper/skipper/dataseries/views/datapoint/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class Actual_DataSeries_DataPointViewSet(
RetrieveModelMixin,
ListModelMixin,
GenericViewSet, # type: ignore
BaseDataSeries_DataPointViewSet
):
# custom detail behaviour
history = _history
Expand Down
2 changes: 1 addition & 1 deletion skipper/skipper/environment_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'SKIPPER_INSTALLATION_NAME': 'localhost',
'SKIPPER_DJANGO_SECRET_KEY': 't#oin*ss-y%q9!qh)dl#suaof2cl65e3f#q^m&rvtcznogu3ox',
'SKIPPER_DOMAIN': 'localhost',
'SKIPPER_S3_ENDPOINT_URL': 'http://localhost:' + os.getenv('SEAWEEDFS_DEV_OUTSIDE_PORT', '8001'),
'SKIPPER_S3_ENDPOINT_URL': 'http://localhost:' + os.getenv('SEAWEEDFS_DEV_OUTSIDE_PORT', '8000'),
'SKIPPER_TASK_DASHBOARD_ENABLED': 'true',
'SKIPPER_OTEL_JAEGER_UI_ENABLED': 'true',
"SKIPPER_DB_USER": 'cephalopod',
Expand Down

0 comments on commit 110a980

Please sign in to comment.