-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f16a8d8
commit be06e31
Showing
7 changed files
with
218 additions
and
86 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
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,103 @@ | ||
import unittest | ||
|
||
from application.utils.gap_analysis import ( | ||
get_path_score, | ||
get_relation_direction, | ||
get_next_id, | ||
PENALTIES | ||
) | ||
|
||
|
||
class TestGapAnalysis(unittest.TestCase): | ||
def tearDown(self) -> None: | ||
return None | ||
|
||
def setUp(self) -> None: | ||
return None | ||
|
||
def test_get_relation_direction_UP(self): | ||
step = {"start": {"id": "123"}, "end": {"id": "234"}} | ||
self.assertEqual(get_relation_direction(step, "123"), "UP") | ||
|
||
def test_get_relation_direction_DOWN(self): | ||
step = {"start": {"id": "123"}, "end": {"id": "234"}} | ||
self.assertEqual(get_relation_direction(step, "234"), "DOWN") | ||
|
||
def test_get_next_id_start(self): | ||
step = {"start": {"id": "123"}, "end": {"id": "234"}} | ||
self.assertEqual(get_next_id(step, "234"), "123") | ||
|
||
def test_get_next_id_end(self): | ||
step = {"start": {"id": "123"}, "end": {"id": "234"}} | ||
self.assertEqual(get_next_id(step, "123"), "234") | ||
|
||
def test_get_path_score_direct_siblings_zero(self): | ||
path = { | ||
"start": { | ||
"id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", | ||
}, | ||
"end": { | ||
"id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", | ||
}, | ||
"path": [ | ||
{ | ||
"end": { | ||
"id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", | ||
}, | ||
"relationship": "LINKED_TO", | ||
"start": { | ||
"id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", | ||
}, | ||
}, | ||
{ | ||
"end": { | ||
"id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", | ||
}, | ||
"relationship": "LINKED_TO", | ||
"start": { | ||
"id": "e2ac59b2-c1d8-4525-a6b3-155d480aecc9", | ||
}, | ||
}, | ||
], | ||
} | ||
self.assertEqual(get_path_score(path), 0) | ||
|
||
def test_get_path_score_one_up_zero(self): | ||
path = { | ||
"start": { | ||
"id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", | ||
}, | ||
"end": { | ||
"id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", | ||
}, | ||
"path": [ | ||
{ | ||
"end": { | ||
"id": "029f7cd7-ef2f-4f25-b0d2-3227cde4b34b", | ||
}, | ||
"relationship": "LINKED_TO", | ||
"start": { | ||
"id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", | ||
}, | ||
}, | ||
{ | ||
"end": { | ||
"id": "123", | ||
}, | ||
"relationship": "CONTAINS", | ||
"start": { | ||
"id": "07bc9f6f-5387-4dc6-b277-0022ed76049f", | ||
}, | ||
}, | ||
{ | ||
"end": { | ||
"id": "7d030730-14cc-4c43-8927-f2d0f5fbcf5d", | ||
}, | ||
"relationship": "LINKED_TO", | ||
"start": { | ||
"id": "123", | ||
}, | ||
}, | ||
], | ||
} | ||
self.assertEqual(get_path_score(path), PENALTIES['CONTAINS_UP']) |
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 |
---|---|---|
@@ -1,5 +1,26 @@ | ||
import random | ||
PENALTIES = {"RELATED": 20, "CONTAINS_UP": 2, "CONTAINS_DOWN": 1, "LINKED_TO": 0} | ||
|
||
|
||
def get_path_score(path): | ||
return random.randint(10, 100) | ||
def get_path_score(path, start_id): | ||
score = 0 | ||
previous_id = start_id | ||
for step in path["path"]: | ||
penalty_type = step["relationship"] | ||
|
||
if step["relationship"] == "CONTAINS": | ||
penalty_type = f"CONTAINS_{get_relation_direction(step, previous_id)}" | ||
score += PENALTIES[penalty_type] | ||
previous_id = get_next_id(step, previous_id) | ||
return score | ||
|
||
|
||
def get_relation_direction(step, previous_id): | ||
if step["start"]["id"] == previous_id: | ||
return "UP" | ||
return "DOWN" | ||
|
||
|
||
def get_next_id(step, previous_id): | ||
if step["start"]["id"] == previous_id: | ||
return step["end"]["id"] | ||
return step["start"]["id"] |
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