Skip to content

Commit

Permalink
Merge pull request #399 from OWASP/link_improvements
Browse files Browse the repository at this point in the history
Link improvements
  • Loading branch information
john681611 authored Sep 19, 2023
2 parents fba3d4e + fabe286 commit 61bdf52
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions application/database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def gap_analysis(self, name_1, name_2):
OPTIONAL MATCH (CompareStandard:Standard|Tool {name: $name2})
OPTIONAL MATCH p = shortestPath((BaseStandard)-[*..20]-(CompareStandard))
WITH p
WHERE length(p) > 1 AND ALL(n in NODES(p) WHERE n:CRE or n.name = $name1 or n.name = $name2)
WHERE length(p) > 1 AND ALL(n in NODES(p) WHERE n:CRE or n = BaseStandard or n = CompareStandard)
RETURN p
""",
name1=name_1,
Expand All @@ -356,7 +356,7 @@ def gap_analysis(self, name_1, name_2):
OPTIONAL MATCH (CompareStandard:Standard|Tool {name: $name2})
OPTIONAL MATCH p = shortestPath((BaseStandard)-[:(LINKED_TO|CONTAINS)*..20]-(CompareStandard))
WITH p
WHERE length(p) > 1 AND ALL(n in NODES(p) WHERE n:CRE or n.name = $name1 or n.name = $name2)
WHERE length(p) > 1 AND ALL(n in NODES(p) WHERE n:CRE or n = BaseStandard or n = CompareStandard)
RETURN p
""",
name1=name_1,
Expand Down
6 changes: 3 additions & 3 deletions application/frontend/src/pages/GapAnalysis/GapAnalysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const GetSegmentText = (segment, segmentID) => {
<br />
{arrow}{' '}
<span style={{ textTransform: 'capitalize' }}>
{segment.relationship.replace('_', ' ').toLowerCase()}
{segment.relationship.replace('_', ' ').toLowerCase()} {segment.score > 0 && <> (+{segment.score})</>}
</span>
<br /> {getDocumentDisplayName(textPart, true)} {textPart.section ?? ''} {textPart.subsection ?? ''}{' '}
{textPart.description ?? ''}
Expand All @@ -51,14 +51,14 @@ function useQuery() {
const GetStrength = (score) => {
if (score == 0) return 'Direct';
if (score < 5) return 'Strong';
if (score > 20) return 'Weak';
if (score >= 20) return 'Weak';
return 'Average';
};

const GetStrengthColor = (score) => {
if (score === 0) return '#D1B000';
if (score < 5) return 'Green';
if (score > 20) return 'Red';
if (score >= 20) return 'Red';
return 'Orange';
};

Expand Down
1 change: 1 addition & 0 deletions application/frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface GapAnalysisPathSegment {
start: Document;
end: Document;
relationship: string;
score: number;
}

interface GapAnalysisPath {
Expand Down
6 changes: 6 additions & 0 deletions application/tests/gap_analysis_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def test_get_path_score_one_up_returns_one_up_penaltiy(self):
],
}
self.assertEqual(get_path_score(path), PENALTIES["CONTAINS_UP"])
self.assertEqual(path["path"][1]["score"], PENALTIES["CONTAINS_UP"])

def test_get_path_score_one_down_one_returns_one_down_penaltiy(self):
path = {
Expand Down Expand Up @@ -140,6 +141,7 @@ def test_get_path_score_one_down_one_returns_one_down_penaltiy(self):
],
}
self.assertEqual(get_path_score(path), PENALTIES["CONTAINS_DOWN"])
self.assertEqual(path["path"][1]["score"], PENALTIES["CONTAINS_DOWN"])

def test_get_path_score_related_returns_related_penalty(self):
path = {
Expand Down Expand Up @@ -174,6 +176,7 @@ def test_get_path_score_related_returns_related_penalty(self):
],
}
self.assertEqual(get_path_score(path), PENALTIES["RELATED"])
self.assertEqual(path["path"][1]["score"], PENALTIES["RELATED"])

def test_get_path_score_one_of_each_returns_penalty(self):
path = {
Expand Down Expand Up @@ -225,3 +228,6 @@ def test_get_path_score_one_of_each_returns_penalty(self):
+ PENALTIES["CONTAINS_UP"]
+ PENALTIES["CONTAINS_DOWN"],
)
self.assertEqual(path["path"][1]["score"], PENALTIES["CONTAINS_DOWN"])
self.assertEqual(path["path"][2]["score"], PENALTIES["RELATED"])
self.assertEqual(path["path"][3]["score"], PENALTIES["CONTAINS_UP"])
4 changes: 3 additions & 1 deletion application/utils/gap_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def get_path_score(path):

if step["relationship"] == "CONTAINS":
penalty_type = f"CONTAINS_{get_relation_direction(step, previous_id)}"
score += PENALTIES[penalty_type]
pentalty = PENALTIES[penalty_type]
score += pentalty
step["score"] = pentalty
previous_id = get_next_id(step, previous_id)
return score

Expand Down

0 comments on commit 61bdf52

Please sign in to comment.