Skip to content

Commit

Permalink
GA: Show all strong links by default (or min of 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
john681611 committed Sep 14, 2023
1 parent 97ffd79 commit 79a38ab
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 33 deletions.
34 changes: 17 additions & 17 deletions application/database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand All @@ -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",
)
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
19 changes: 11 additions & 8 deletions application/frontend/src/pages/GapAnalysis/GapAnalysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,6 +68,9 @@ export const GapAnalysis = () => {
return 'Orange';
};

const GetStrongPathsCount = (paths) =>
Math.max(Object.values<any>(paths).filter((x) => GetStrength(x.score) === 'Strong').length, 3);

useEffect(() => {
const fetchData = async () => {
const result = await axios.get(`${apiUrl}/standards`);
Expand Down Expand Up @@ -185,9 +187,7 @@ export const GapAnalysis = () => {
<Table.Row key={key}>
<Table.Cell>
<p>
<b>
{getDocumentDisplayName(gapAnalysis[key].start, true)}
</b>
<b>{getDocumentDisplayName(gapAnalysis[key].start, true)}</b>
<a
href={`/node/standard/${gapAnalysis[key].start.name}/section/${gapAnalysis[key].start.section}`}
target="_blank"
Expand All @@ -199,7 +199,7 @@ export const GapAnalysis = () => {
<Table.Cell style={{ minWidth: '35vw' }}>
{Object.values<any>(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 (
Expand Down Expand Up @@ -246,7 +246,10 @@ export const GapAnalysis = () => {
<Accordion.Content active={activeIndex === key}>
{Object.values<any>(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 (
Expand Down
8 changes: 4 additions & 4 deletions application/frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, GapAnalysisPath>;
};
}
4 changes: 2 additions & 2 deletions application/frontend/src/utils/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions application/tests/db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1471,6 +1470,5 @@ def test_get_embeddings_by_doc_type(self):
self.assertEqual(tool_emb, {})



if __name__ == "__main__":
unittest.main()

0 comments on commit 79a38ab

Please sign in to comment.