Skip to content

Commit

Permalink
more workspace datapoints operations
Browse files Browse the repository at this point in the history
  • Loading branch information
pritamrungta committed Mar 11, 2024
1 parent 4530d5d commit 4154b5e
Show file tree
Hide file tree
Showing 7 changed files with 498 additions and 165 deletions.
2 changes: 1 addition & 1 deletion docs/sdk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Organization
Workspace
----------------------
.. autoclass:: redbrick.workspace.RBWorkspace
:members: name, org_id, workspace_id
:members: name, org_id, workspace_id, metadata_schema, classification_schema, cohorts, update_schema, update_cohorts, get_datapoints, archive_datapoints, unarchive_datapoints, add_datapoints_to_cohort, remove_datapoints_from_cohort, update_datapoint_attributes
:show-inheritance:

.. _project:
Expand Down
51 changes: 50 additions & 1 deletion redbrick/common/workspace.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Interface for getting basic information about a workspace."""

from typing import Dict, List
from typing import Dict, List, Optional, Tuple
from abc import ABC, abstractmethod


Expand Down Expand Up @@ -28,3 +28,52 @@ def create_workspace(
Raise an exception if workspace already exists.
"""

@abstractmethod
def update_schema(
self,
org_id: str,
workspace_id: str,
metadata_schema: Optional[List[Dict]],
classification_schema: Optional[List[Dict]],
) -> None:
"""Update workspace metadata and classification schema."""

@abstractmethod
def update_cohorts(
self, org_id: str, workspace_id: str, cohorts: List[Dict]
) -> None:
"""Update workspace cohorts."""

@abstractmethod
def get_datapoints(
self,
org_id: str,
workspace_id: str,
first: int = 50,
after: Optional[str] = None,
) -> Tuple[List[Dict], Optional[str]]:
"""Get datapoints for a workspace."""

@abstractmethod
def toggle_datapoints_archived_status(
self, org_id: str, dp_ids: List[str], archived: bool
) -> None:
"""Toggle archived status for datapoints."""

@abstractmethod
def toggle_datapoints_cohorts(
self,
org_id: str,
workspace_id: str,
cohort_name: str,
dp_ids: List[str],
include: bool,
) -> None:
"""Toggle cohort membership for workspace datapoints."""

@abstractmethod
def update_datapoint_attributes(
self, org_id: str, dp_id: str, attributes: Dict
) -> None:
"""Update datapoint attributes."""
205 changes: 87 additions & 118 deletions redbrick/repo/shards.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
"""Partial queries to prevent duplication."""

ATTRIBUTE_SHARD = """
name
attrType
attrId
options {
name
optionId
color
archived
}
archived
parents
hint
defaultValue
"""

WORKSPACE_SHARD = f"""
orgId
workspaceId
name
desc
createdAt
status
metadataSchema {{
uniqueName
displayName
dataType
options
required
}}
classificationSchema {{
{ATTRIBUTE_SHARD}
}}
cohorts {{
name
color
createdBy
createdAt
}}
"""

PROJECT_SHARD = """
orgId
projectId
Expand Down Expand Up @@ -44,52 +85,19 @@
}
"""

TAXONOMY_SHARD = """
orgId
OLD_ATTRIBUTE_SHARD = """
name
version
createdAt
categories {
name
children {
name
classId
disabled
children {
name
classId
disabled
children {
name
classId
disabled
children {
name
classId
disabled
children {
name
classId
disabled
children {
name
classId
disabled
}
}
}
}
}
}
}
attributes {
attrType
whitelist
disabled
"""

OLD_CATEGORY_SHARD = """
name
children {
name
attrType
whitelist
classId
disabled
}
taskCategories {
name
children {
name
classId
Expand All @@ -110,102 +118,62 @@
name
classId
disabled
children {
name
classId
disabled
}
}
}
}
}
}
}
taskAttributes {
name
attrType
whitelist
disabled
}
colorMap {
"""

TAXONOMY_SHARD = f"""
orgId
name
version
createdAt
categories {{
{OLD_CATEGORY_SHARD}
}}
attributes {{
{OLD_ATTRIBUTE_SHARD}
}}
taskCategories {{
{OLD_CATEGORY_SHARD}
}}
taskAttributes {{
{OLD_ATTRIBUTE_SHARD}
}}
colorMap {{
name
color
classid
trail
taskcategory
}
}}
archived
isNew
taxId
studyClassify {
name
attrType
attrId
options {
name
optionId
color
archived
}
archived
parents
hint
defaultValue
}
seriesClassify {
name
attrType
attrId
options {
name
optionId
color
archived
}
archived
parents
hint
defaultValue
}
instanceClassify {
name
attrType
attrId
options {
name
optionId
color
archived
}
archived
parents
hint
defaultValue
}
objectTypes {
studyClassify {{
{ATTRIBUTE_SHARD}
}}
seriesClassify {{
{ATTRIBUTE_SHARD}
}}
instanceClassify {{
{ATTRIBUTE_SHARD}
}}
objectTypes {{
category
classId
labelType
attributes {
name
attrType
attrId
options {
name
optionId
color
archived
}
archived
parents
hint
defaultValue
}
attributes {{
{ATTRIBUTE_SHARD}
}}
color
archived
parents
hint
}
}}
"""

TASK_DATA_SHARD = """
Expand Down Expand Up @@ -266,6 +234,7 @@
def datapoint_shard(raw_items: bool, presigned_items: bool) -> str:
"""Return the datapoint shard."""
return f"""
dpId
name
{"items(presigned: false)" if raw_items else ""}
{"itemsPresigned:items(presigned: true)" if presigned_items else ""}
Expand Down
Loading

0 comments on commit 4154b5e

Please sign in to comment.