-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ITG-103] List of relation types added to Task (#38)
Added relation_types to Task.
- Loading branch information
Showing
8 changed files
with
88 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from bode.app import db | ||
from bode.models.task_relation import RelationType, TaskRelation | ||
from bode.resources.task_relations.schemas import DirectedRelationType | ||
|
||
|
||
def get_lhs_related_tasks(task_id, filters=list()): | ||
from bode.models.task import Task | ||
|
||
all_filters = [TaskRelation.first_task_id == task_id] + filters | ||
return ( | ||
db.session.query(TaskRelation, Task) | ||
.filter(*all_filters) | ||
.join(Task, TaskRelation.second_task_id == Task.id) | ||
.all() | ||
) | ||
|
||
|
||
def get_rhs_related_tasks(task_id, filters=list()): | ||
from bode.models.task import Task | ||
|
||
all_filters = [TaskRelation.second_task_id == task_id] + filters | ||
return ( | ||
db.session.query(TaskRelation, Task) | ||
.filter(*all_filters) | ||
.join(Task, TaskRelation.first_task_id == Task.id) | ||
.all() | ||
) | ||
|
||
|
||
def get_related_tasks(task_id): | ||
return get_lhs_related_tasks(task_id) + get_rhs_related_tasks(task_id) | ||
|
||
|
||
def map_to_related_task_schema(relation: TaskRelation, task_id): | ||
match relation.type: | ||
case RelationType.Dependent.value: | ||
if task_id == relation.first_task_id: | ||
return DirectedRelationType.IsBlockedBy.value | ||
return DirectedRelationType.Blocks.value | ||
case RelationType.Subtask.value: | ||
if task_id == relation.first_task_id: | ||
return DirectedRelationType.Supertask.value | ||
return DirectedRelationType.Subtask.value | ||
case _: | ||
return DirectedRelationType.Interchangable.value | ||
|
||
|
||
def get_relation_types(task_id): | ||
relations_lhs = db.session.query(TaskRelation).filter(TaskRelation.first_task_id == task_id).all() | ||
relations_rhs = db.session.query(TaskRelation).filter(TaskRelation.second_task_id == task_id).all() | ||
return {map_to_related_task_schema(relation, task_id) for relation in relations_lhs + relations_rhs} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from enum import Enum | ||
|
||
|
||
class DirectedRelationType(Enum): | ||
Blocks = "blocks" | ||
IsBlockedBy = "is_blocked_by" | ||
Subtask = "subtask" | ||
Supertask = "supertask" | ||
Interchangable = "interchangable" | ||
|
||
@classmethod | ||
def list(cls): | ||
return [c.value for c in cls] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters