2024-06-07 20:17:03 +03:00
|
|
|
/**
|
|
|
|
* Module: OSS data loading and processing.
|
|
|
|
*/
|
|
|
|
|
2024-07-20 18:26:32 +03:00
|
|
|
import { Graph } from './Graph';
|
|
|
|
import { IOperation, IOperationSchema, IOperationSchemaData, OperationID } from './oss';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads data into an {@link IOperationSchema} based on {@link IOperationSchemaData}.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
export class OssLoader {
|
2024-07-20 18:26:32 +03:00
|
|
|
private oss: IOperationSchemaData;
|
|
|
|
private graph: Graph = new Graph();
|
|
|
|
private operationByID: Map<OperationID, IOperation> = new Map();
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
constructor(input: IOperationSchemaData) {
|
2024-07-20 18:26:32 +03:00
|
|
|
this.oss = input;
|
2024-06-07 20:17:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
produceOSS(): IOperationSchema {
|
2024-07-20 18:26:32 +03:00
|
|
|
const result = this.oss as IOperationSchema;
|
|
|
|
this.prepareLookups();
|
|
|
|
this.createGraph();
|
|
|
|
|
|
|
|
result.operationByID = this.operationByID;
|
|
|
|
result.graph = this.graph;
|
2024-06-07 20:17:03 +03:00
|
|
|
return result;
|
|
|
|
}
|
2024-07-20 18:26:32 +03:00
|
|
|
|
|
|
|
private prepareLookups() {
|
|
|
|
this.oss.items.forEach(operation => {
|
|
|
|
this.operationByID.set(operation.id, operation);
|
|
|
|
this.graph.addNode(operation.id);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private createGraph() {
|
|
|
|
this.oss.arguments.forEach(argument => this.graph.addEdge(argument.argument, argument.operation));
|
|
|
|
}
|
2024-06-07 20:17:03 +03:00
|
|
|
}
|