Solved type issues in traverseOperations etc. Changed functions to take a object single parameter. Condensed endpoints into a function call
This commit is contained in:
@@ -1,37 +1,38 @@
|
||||
import { Operation } from "../../declarations/Operation";
|
||||
import { Action } from "../../declarations/Action";
|
||||
import { PdfFile } from "../wrappers/PdfFile";
|
||||
|
||||
export function organizeWaitOperations(operations: Operation[]) {
|
||||
export function organizeWaitOperations(actions: Action[]) {
|
||||
|
||||
// Initialize an object to store the counts and associated "done" operations
|
||||
const waitCounts = {};
|
||||
const doneOperations = {};
|
||||
const waitCounts: {[key: string]: number} = {};
|
||||
const doneOperations: {[key: string]: Action} = {};
|
||||
|
||||
// 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;
|
||||
function countWaitOperationsAndDone(actions: Action[]) {
|
||||
for (const action of actions) {
|
||||
if (action.type === "wait") {
|
||||
const id = action.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 (action.type === "done") {
|
||||
const id = action.values.id;
|
||||
doneOperations[id] = action;
|
||||
}
|
||||
if (operation.operations) {
|
||||
countWaitOperationsAndDone(operation.operations);
|
||||
if (action.actions) {
|
||||
countWaitOperationsAndDone(action.actions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start counting and associating from the root operations
|
||||
countWaitOperationsAndDone(operations);
|
||||
countWaitOperationsAndDone(actions);
|
||||
|
||||
// Combine counts and associated "done" operations
|
||||
const result = {};
|
||||
const result: ResultType = {};
|
||||
for (const id in waitCounts) {
|
||||
result[id] = {
|
||||
waitCount: waitCounts[id],
|
||||
@@ -42,3 +43,10 @@ export function organizeWaitOperations(operations: Operation[]) {
|
||||
return result;
|
||||
}
|
||||
|
||||
export type ResultType = {
|
||||
[key: string]: {
|
||||
waitCount: number,
|
||||
doneOperation: Action,
|
||||
input: PdfFile[]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user