Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BIH-39 Fix submit tests for BIH #1053

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions utils/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ class Node {
* @param {Object} props.data - JSON object of node data
* @param {number} props.order - Sort index
* @param {string} props.category - Category of the node (e.g. file, clinical, administrative...)
* @param {string[]} props.target - Array of names of nodes this node points to in graph
* @param {Object} props.orig_props - Copy of props for cloning node properties
*/
constructor(props) {
this.data = props.data;
this.order = props.order;
this.category = props.category;
this.name = props.name;
this.target = props.target;
this.orig_props = props;
}

Expand Down Expand Up @@ -77,7 +75,6 @@ const getAllNodes = function () {
const nodesDict = {};
try {
let order = 1;
let target = 'project'; // first node (project) is related to program
for (const line of lines) {
const parts = line.split('\t');
const nodeName = parts[0];
Expand All @@ -89,9 +86,7 @@ const getAllNodes = function () {
order,
category: parts[1],
name: nodeName,
target,
});
target = nodeName;
order += 1;
}
return nodesDict;
Expand All @@ -117,35 +112,14 @@ const cloneNodes = function (originalNodes) {
return newNodes;
};

/**
* Uses BFS to find a path to project node from given starting node
* @param {string} startNodeName - node to start search from
* @param {Object} allNodes - Nodes keyed by node name
*/
const nodePathToProject = function (startNodeName, allNodes) {
// BFS to find path to project from a starting node name
// returns a dict containing nodes keyed by name
const nodesInPath = {};
let que = [startNodeName];
while (que.length > 0) {
const s = que.pop();
if (s === 'project') {
break;
}
nodesInPath[s] = allNodes[s];
que = allNodes[s].target.concat(que);
}
return nodesInPath;
};

/**
* Finds a file node and gets a path to the project node
* @param {Object} allNodes - Nodes keyed by node name
* @returns {{path: Node[], file: Node}} - Path up to the node, and file node itself
*/
const getPathWithFileNode = function (allNodes) {
const allNodesClone = cloneNodes(allNodes);
const fileNodeName = Object.keys(allNodesClone).find(
const fileNodeName = Object.keys(allNodesClone).findLast(
(nodeName) => allNodesClone[nodeName].category.includes('_file'),
);
const file = allNodesClone[fileNodeName].clone();
Expand Down
Loading