ConceptPortal-public/rsconcept/frontend/src/models/OssLoader.ts

42 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-06-04 23:00:22 +03:00
/**
* Module: OSS data loading and processing.
*/
2024-07-21 15:19:57 +03:00
import { Graph } from './Graph';
import { IOperation, IOperationSchema, IOperationSchemaData, OperationID } from './oss';
2024-06-04 23:00:22 +03:00
/**
* Loads data into an {@link IOperationSchema} based on {@link IOperationSchemaData}.
*
*/
export class OssLoader {
2024-07-21 15:19:57 +03:00
private oss: IOperationSchemaData;
private graph: Graph = new Graph();
private operationByID: Map<OperationID, IOperation> = new Map();
2024-06-04 23:00:22 +03:00
constructor(input: IOperationSchemaData) {
2024-07-21 15:19:57 +03:00
this.oss = input;
2024-06-04 23:00:22 +03:00
}
produceOSS(): IOperationSchema {
2024-07-21 15:19:57 +03:00
const result = this.oss as IOperationSchema;
this.prepareLookups();
this.createGraph();
result.operationByID = this.operationByID;
result.graph = this.graph;
2024-06-04 23:00:22 +03:00
return result;
}
2024-07-21 15:19:57 +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-04 23:00:22 +03:00
}