Skip to content

Commit

Permalink
feat(lib): collect child names to check regroup criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
narekhovhannisyan committed Dec 17, 2024
1 parent a261e52 commit fc6cc88
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions src/if-run/lib/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ const {
OBSERVING,
} = STRINGS;

const childNames = new Set();

/**
* Traverses all child nodes based on children grouping.
*/
const traverse = async (children: any, params: ComputeParams) => {
for (const child in children) {
console.debug(COMPUTING_COMPONENT_PIPELINE(child));
childNames.add(child);
await computeNode(children[child], params);
}
};
Expand Down Expand Up @@ -129,6 +132,7 @@ const computeNode = async (node: Node, params: ComputeParams): Promise<any> => {
node.inputs = outputStorage;

if (params.context.explainer) {
console.log('reached here');
addExplainData({
pluginName,
metadata: plugin.metadata,
Expand All @@ -143,27 +147,40 @@ const computeNode = async (node: Node, params: ComputeParams): Promise<any> => {
if ((noFlags || params.regroup) && pipelineCopy.regroup) {
const originalOutputs = params.append ? node.outputs || [] : [];

node.children = Regroup(
outputStorage,
originalOutputs,
pipelineCopy.regroup
// Grabs all the values according to grouping criteria.
const regroupValues = pipelineCopy.regroup
.map(group => [...new Set(outputStorage.map(output => output[group]))])
.flat();
// Checks if regroup values are present in the children list.
const isRegrouped = regroupValues.every(one =>
[...childNames].includes(one)
);
console.log(isRegrouped);
console.log(regroupValues);

delete node.inputs;
delete node.outputs;
if (!isRegrouped) {
node.children = Regroup(
outputStorage,
originalOutputs,
pipelineCopy.regroup
);

debugLogger.setExecutingPluginName();
console.debug(REGROUPING);
delete node.inputs;
delete node.outputs;

return traverse(node.children, {
...params,
pipeline: {
...pipelineCopy,
regroup: undefined,
},
defaults,
config,
});
debugLogger.setExecutingPluginName();
console.debug(REGROUPING);

return traverse(node.children, {
...params,
pipeline: {
...pipelineCopy,
regroup: undefined,
},
defaults,
config,
});
}
}

console.debug('\n');
Expand Down

0 comments on commit fc6cc88

Please sign in to comment.