From 79a38ab1ba0532ffc6e7d45422b37d240cb8b9cb Mon Sep 17 00:00:00 2001 From: john681611 Date: Thu, 14 Sep 2023 12:55:24 +0100 Subject: [PATCH] GA: Show all strong links by default (or min of 3) --- application/database/db.py | 34 +++++++++---------- .../src/pages/GapAnalysis/GapAnalysis.tsx | 19 ++++++----- application/frontend/src/types.ts | 8 ++--- application/frontend/src/utils/document.ts | 4 +-- application/tests/db_test.py | 2 -- 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/application/database/db.py b/application/database/db.py index c44ea9584..e6b4ba656 100644 --- a/application/database/db.py +++ b/application/database/db.py @@ -198,12 +198,12 @@ def add_cre(self, dbcre: CRE): self.driver.execute_query( "MERGE (n:CRE {id: $nid, name: $name, description: $description, doctype: $doctype, links: $links, metadata: $metadata, tags: $tags})", name=dbcre.name, - doctype="CRE", #dbcre.ntype, + doctype="CRE", # dbcre.ntype, nid=dbcre.id, description=dbcre.description, - links=[], #dbcre.links, + links=[], # dbcre.links, tags=dbcre.tags, - metadata="{}", #dbcre.metadata, + metadata="{}", # dbcre.metadata, database_="neo4j", ) @@ -218,13 +218,13 @@ def add_dbnode(self, dbnode: Node): doctype=dbnode.ntype, nid=dbnode.id, description=dbnode.description, - links=[], #dbnode.links, + links=[], # dbnode.links, tags=dbnode.tags, - metadata="{}", #dbnode.metadata, - hyperlink="", #dbnode.hyperlink or "", + metadata="{}", # dbnode.metadata, + hyperlink="", # dbnode.hyperlink or "", version=dbnode.version or "", section=dbnode.section, - sectionID=dbnode.section_id,#dbnode.sectionID, + sectionID=dbnode.section_id, # dbnode.sectionID, subsection=dbnode.subsection or "", database_="neo4j", ) @@ -236,15 +236,15 @@ def add_dbnode(self, dbnode: Node): doctype=dbnode.ntype, nid=dbnode.id, description=dbnode.description, - links=[], #dbnode.links, + links=[], # dbnode.links, tags=dbnode.tags, - metadata="{}", #dbnode.metadata, - hyperlink="", #dbnode.hyperlink or "", + metadata="{}", # dbnode.metadata, + hyperlink="", # dbnode.hyperlink or "", version=dbnode.version or "", section=dbnode.section, - sectionID=dbnode.section_id,#dbnode.sectionID, + sectionID=dbnode.section_id, # dbnode.sectionID, subsection=dbnode.subsection or "", - tooltype="", #dbnode.tooltype, + tooltype="", # dbnode.tooltype, database_="neo4j", ) return @@ -345,7 +345,7 @@ def standards(self) -> List[str]: if not self.connected: return records, _, _ = self.driver.execute_query( - 'MATCH (n:Standard) ' "RETURN collect(distinct n.name)", + "MATCH (n:Standard) " "RETURN collect(distinct n.name)", database_="neo4j", ) return records[0][0] @@ -379,8 +379,8 @@ def parse_node(self, node: neo4j.graph.Node) -> cre_defs.Document: metadata=metadata, hyperlink=(node["hyperlink"] if "hyperlink" in node else None), version=(node["version"] if "version" in node else None), - section=node['section'], - sectionID=node['sectionID'], + section=node["section"], + sectionID=node["sectionID"], subsection=(node["subsection"] if "subsection" in node else None), ) if "Tool" in node.labels: @@ -393,8 +393,8 @@ def parse_node(self, node: neo4j.graph.Node) -> cre_defs.Document: metadata=metadata, hyperlink=(node["hyperlink"] if "hyperlink" in node else None), version=(node["version"] if "version" in node else None), - section=node['section'], - sectionID=node['sectionID'], + section=node["section"], + sectionID=node["sectionID"], subsection=(node["subsection"] if "subsection" in node else None), ) if "CRE" in node.labels: diff --git a/application/frontend/src/pages/GapAnalysis/GapAnalysis.tsx b/application/frontend/src/pages/GapAnalysis/GapAnalysis.tsx index 9dc1f0f4a..21c81b904 100644 --- a/application/frontend/src/pages/GapAnalysis/GapAnalysis.tsx +++ b/application/frontend/src/pages/GapAnalysis/GapAnalysis.tsx @@ -14,11 +14,10 @@ import { Table, } from 'semantic-ui-react'; -import { GapAnalysisPathStart } from '../../types'; -import { getDocumentDisplayName } from '../../utils'; - import { LoadingAndErrorIndicator } from '../../components/LoadingAndErrorIndicator'; import { useEnvironment } from '../../hooks'; +import { GapAnalysisPathStart } from '../../types'; +import { getDocumentDisplayName } from '../../utils'; const GetSegmentText = (segment, segmentID) => { let textPart = segment.end; @@ -69,6 +68,9 @@ export const GapAnalysis = () => { return 'Orange'; }; + const GetStrongPathsCount = (paths) => + Math.max(Object.values(paths).filter((x) => GetStrength(x.score) === 'Strong').length, 3); + useEffect(() => { const fetchData = async () => { const result = await axios.get(`${apiUrl}/standards`); @@ -185,9 +187,7 @@ export const GapAnalysis = () => {

- - {getDocumentDisplayName(gapAnalysis[key].start, true)} - + {getDocumentDisplayName(gapAnalysis[key].start, true)} { {Object.values(gapAnalysis[key].paths) .sort((a, b) => a.score - b.score) - .slice(0, 3) + .slice(0, GetStrongPathsCount(gapAnalysis[key].paths)) .map((path) => { let segmentID = gapAnalysis[key].start.id; return ( @@ -246,7 +246,10 @@ export const GapAnalysis = () => { {Object.values(gapAnalysis[key].paths) .sort((a, b) => a.score - b.score) - .slice(3, Object.keys(gapAnalysis[key].paths).length) + .slice( + GetStrongPathsCount(gapAnalysis[key].paths), + Object.keys(gapAnalysis[key].paths).length + ) .map((path) => { let segmentID = gapAnalysis[key].start.id; return ( diff --git a/application/frontend/src/types.ts b/application/frontend/src/types.ts index e24aa94a8..64d73cdca 100644 --- a/application/frontend/src/types.ts +++ b/application/frontend/src/types.ts @@ -24,14 +24,14 @@ interface GapAnalysisPathSegment { start: Document; end: Document; relationship: string; -}; +} interface GapAnalysisPath { end: Document; - path: GapAnalysisPathSegment[] -}; + path: GapAnalysisPathSegment[]; +} export interface GapAnalysisPathStart { start: Document; paths: Record; -}; +} diff --git a/application/frontend/src/utils/document.ts b/application/frontend/src/utils/document.ts index 3ab94dedf..1e01d2b35 100644 --- a/application/frontend/src/utils/document.ts +++ b/application/frontend/src/utils/document.ts @@ -7,14 +7,14 @@ import { } from '../const'; import { Document, LinkedDocument } from '../types'; -export const getDocumentDisplayName = (document: Document, noID=false) => { +export const getDocumentDisplayName = (document: Document, noID = false) => { // [document.doctype, document.id, document.name, document.section, document.subsection].filter(Boolean).join(' - '); // format: Standard - ASVS - V1.1 if (!document) { return ''; } return [ document.doctype, - noID? "" : document.id, + noID ? '' : document.id, document.name, document.version, document.sectionID, diff --git a/application/tests/db_test.py b/application/tests/db_test.py index 3c41908f1..714b11423 100644 --- a/application/tests/db_test.py +++ b/application/tests/db_test.py @@ -1306,7 +1306,6 @@ def test_gap_analysis_duplicate_link_path_existing_higher(self, gap_mock): } self.assertEqual(collection.gap_analysis(["a", "b"]), expected) - def test_get_embeddings_by_doc_type_paginated(self): """Given: a range of embedding for Nodes and a range of embeddings for CREs when called with doc_type CRE return the cre embeddings @@ -1471,6 +1470,5 @@ def test_get_embeddings_by_doc_type(self): self.assertEqual(tool_emb, {}) - if __name__ == "__main__": unittest.main()