Skip to content

Commit

Permalink
feat[EC-5567]: Sync Active project from SDK (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim-Encord authored Dec 9, 2024
1 parent e74dca5 commit afec1e0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
19 changes: 19 additions & 0 deletions encord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
)
from encord.http.v2.api_client import ApiClient
from encord.http.v2.payloads import Page
from encord.orm.active import ActiveProjectImportPayload, ActiveProjectMode
from encord.orm.analytics import (
CollaboratorTimer,
CollaboratorTimerParams,
Expand Down Expand Up @@ -1606,6 +1607,24 @@ def get_label_validation_errors(self, label_hash: str) -> List[str]:

return errors.errors or []

def active_import(self, project_mode: ActiveProjectMode, video_sampling_rate: Optional[float] = None) -> None:
self._get_api_client().post(
f"active/{self.project_hash}/import",
params=None,
payload=ActiveProjectImportPayload(project_mode=project_mode, video_sampling_rate=video_sampling_rate),
result_type=None,
)
logger.info("Import initiated in Active, please check the app to see progress")

def active_sync(self) -> None:
self._get_api_client().post(
f"active/{self.project_hash}/sync",
params=None,
payload=None,
result_type=None,
)
logger.info("Sync initiated in Active, please check the app to see progress")


def _device_to_string(device: Device) -> str:
if not isinstance(device, Device):
Expand Down
16 changes: 16 additions & 0 deletions encord/orm/active.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from enum import Enum
from typing import Optional

from encord.orm.base_dto import BaseDTO


class ActiveProjectMode(Enum):
DATA = "data"
LABEL = "label"
METRIC = "metric"
ADVANCED = "advanced"


class ActiveProjectImportPayload(BaseDTO):
project_mode: ActiveProjectMode
video_sampling_rate: Optional[float] = None
15 changes: 15 additions & 0 deletions encord/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from encord.http.v2.api_client import ApiClient
from encord.objects import LabelRowV2, OntologyStructure
from encord.ontology import Ontology
from encord.orm.active import ActiveProjectMode
from encord.orm.analytics import (
CollaboratorTimer,
CollaboratorTimerParams,
Expand Down Expand Up @@ -1227,3 +1228,17 @@ def create_collection(
self._client._get_api_client(), self._project_instance.project_hash, name, description, collection_type
)
return self.get_collection(new_uuid)

def active_sync(self) -> None:
"""Sync the associated Active project"""
self._client.active_sync()

def active_import(self, project_mode: ActiveProjectMode, *, video_sampling_rate: Optional[float] = None) -> None:
"""Import the associated Active project. Progress in the app
Args:
project_mode: Active projects can be imported up to a certain stage. Use the ActiveProjectModeEnum to select the stage
video_sampling_rate: Optional[float]: For videos, what's the sampling rate of frames for analysis
Returns:
None
"""
self._client.active_import(project_mode, video_sampling_rate)

0 comments on commit afec1e0

Please sign in to comment.