Skip to content

Commit

Permalink
poc: relation mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
orhanrauf committed Feb 4, 2025
1 parent 9cf92a2 commit 03dba48
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
79 changes: 79 additions & 0 deletions backend/app/platform/chunks/trello.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel

from app.platform.chunks._base import BaseChunk


class TrelloOrganizationChunk(BaseChunk):
"""Schema for Trello organization (Workspace) chunks."""

id: str
display_name: Optional[str] = None
name: Optional[str] = None
desc: Optional[str] = None
Expand All @@ -23,6 +26,7 @@ class TrelloOrganizationChunk(BaseChunk):
class TrelloBoardChunk(BaseChunk):
"""Schema for Trello board chunks."""

id: str
name: Optional[str] = None
desc: Optional[str] = None
closed: bool = False # Trello uses 'closed' to indicate archive status
Expand All @@ -36,6 +40,7 @@ class TrelloBoardChunk(BaseChunk):
class TrelloListChunk(BaseChunk):
"""Schema for Trello list chunks."""

id: str
name: Optional[str] = None
board_id: Optional[str] = None
closed: bool = False
Expand All @@ -45,6 +50,7 @@ class TrelloListChunk(BaseChunk):
class TrelloCardChunk(BaseChunk):
"""Schema for Trello card chunks."""

id: str
name: Optional[str] = None
desc: Optional[str] = None
closed: bool = False
Expand All @@ -59,6 +65,7 @@ class TrelloCardChunk(BaseChunk):
class TrelloMemberChunk(BaseChunk):
"""Schema for Trello member chunks."""

id: str
avatar_url: Optional[str] = None
initials: Optional[str] = None
full_name: Optional[str] = None
Expand All @@ -71,7 +78,79 @@ class TrelloMemberChunk(BaseChunk):
class TrelloActionChunk(BaseChunk):
"""Schema for Trello action chunks."""

id: str
action_type: Optional[str] = None
date: Optional[datetime] = None
member_creator_id: Optional[str] = None
data: Optional[dict] = None


class Relation(BaseModel):
"""A relation between two entities."""

id: str
source_chunk_type: type[BaseChunk]
source_entity_id_attribute: str
target_chunk_type: type[BaseChunk]
target_entity_id_attribute: str
relation_type: str


RELATIONS = [
Relation(
source_chunk_type=TrelloCardChunk,
source_entity_id_attribute="list_id",
target_chunk_type=TrelloListChunk,
target_entity_id_attribute="id",
relation_type="is_in_list",
),
Relation(
source_chunk_type=TrelloCardChunk,
source_entity_id_attribute="board_id",
target_chunk_type=TrelloBoardChunk,
target_entity_id_attribute="id",
relation_type="is_in_board",
),
Relation(
source_chunk_type=TrelloCardChunk,
source_entity_id_attribute="member_creator_id",
target_chunk_type=TrelloMemberChunk,
target_entity_id_attribute="id",
relation_type="is_created_by",
),
Relation(
source_chunk_type=TrelloListChunk,
target_chunk_type=TrelloBoardChunk,
source_entity_id_attribute="board_id",
target_entity_id_attribute="id",
relation_type="is_in_board",
),
Relation(
source_chunk_type=TrelloBoardChunk,
source_entity_id_attribute="organization_id",
target_chunk_type=TrelloOrganizationChunk,
target_entity_id_attribute="id",
relation_type="is_in_organization",
),
Relation(
source_chunk_type=TrelloMemberChunk,
target_chunk_type=TrelloOrganizationChunk,
source_entity_id_attribute="organization_id",
target_entity_id_attribute="id",
relation_type="is_in_organization",
),
Relation(
source_chunk_type=TrelloMemberChunk,
source_entity_id_attribute="boards",
target_chunk_type=TrelloBoardChunk,
target_entity_id_attribute="id",
relation_type="is_member_of_board",
),
Relation(
source_chunk_type=TrelloActionChunk,
source_entity_id_attribute="member_creator_id",
target_chunk_type=TrelloMemberChunk,
target_entity_id_attribute="id",
relation_type="is_created_by",
),
]
10 changes: 10 additions & 0 deletions backend/app/platform/sources/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ async def create(cls, credentials: Optional[Any] = None) -> "BaseSource":
async def generate_chunks(self) -> AsyncGenerator[BaseChunk, None]:
"""Generate chunks for the source."""
pass


class Relation(BaseModel):
"""A relation between two entities."""

source_chunk_type: type[BaseChunk]
source_entity_id_attribute: str
target_chunk_type: type[BaseChunk]
target_entity_id_attribute: str
relation_type: str

0 comments on commit 03dba48

Please sign in to comment.