Skip to content

Commit

Permalink
BIH-39 Fix submit tests for BIH (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulineribeyre authored Aug 26, 2024
1 parent f8b57de commit 715150b
Showing 1 changed file with 1 addition and 27 deletions.
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

0 comments on commit 715150b

Please sign in to comment.