Started migrating workflow controller

This commit is contained in:
Felix Kaspar
2023-11-13 00:09:12 +01:00
parent 57142381ca
commit 5ae8cb77ac
29 changed files with 96 additions and 127 deletions

View File

@@ -0,0 +1,44 @@
import { Operation } from "../../declarations/Operation";
export function organizeWaitOperations(operations: Operation[]) {
// Initialize an object to store the counts and associated "done" operations
const waitCounts = {};
const doneOperations = {};
// Function to count "type: wait" operations and associate "done" operations per id
function countWaitOperationsAndDone(operations: Operation[]) {
for (const operation of operations) {
if (operation.type === "wait") {
const id = operation.values.id;
if (id in waitCounts) {
waitCounts[id]++;
} else {
waitCounts[id] = 1;
}
}
if (operation.type === "done") {
const id = operation.values.id;
doneOperations[id] = operation;
}
if (operation.operations) {
countWaitOperationsAndDone(operation.operations);
}
}
}
// Start counting and associating from the root operations
countWaitOperationsAndDone(operations);
// Combine counts and associated "done" operations
const result = {};
for (const id in waitCounts) {
result[id] = {
waitCount: waitCounts[id],
doneOperation: doneOperations[id],
input: []
};
}
return result;
}