UNPKG

@hpcc-js/comms

Version:
289 lines 10.5 kB
import { __assign, __extends } from "tslib"; import { Cache, Edge, Graph, StateObject, Subgraph, Vertex } from "@hpcc-js/util"; var ECLGraph = /** @class */ (function (_super) { __extends(ECLGraph, _super); function ECLGraph(wu, eclGraph, eclTimers) { var _this = _super.call(this) || this; _this.wu = wu; var duration = 0; for (var _i = 0, eclTimers_1 = eclTimers; _i < eclTimers_1.length; _i++) { var eclTimer = eclTimers_1[_i]; if (eclTimer.GraphName === eclGraph.Name && !eclTimer.HasSubGraphId) { duration = Math.round(eclTimer.Seconds * 1000) / 1000; break; } } _this.set(__assign({ Time: duration }, eclGraph)); return _this; } Object.defineProperty(ECLGraph.prototype, "properties", { get: function () { return this.get(); }, enumerable: false, configurable: true }); Object.defineProperty(ECLGraph.prototype, "Name", { get: function () { return this.get("Name"); }, enumerable: false, configurable: true }); Object.defineProperty(ECLGraph.prototype, "Label", { get: function () { return this.get("Label"); }, enumerable: false, configurable: true }); Object.defineProperty(ECLGraph.prototype, "Type", { get: function () { return this.get("Type"); }, enumerable: false, configurable: true }); Object.defineProperty(ECLGraph.prototype, "Complete", { get: function () { return this.get("Complete"); }, enumerable: false, configurable: true }); Object.defineProperty(ECLGraph.prototype, "WhenStarted", { get: function () { return this.get("WhenStarted"); }, enumerable: false, configurable: true }); Object.defineProperty(ECLGraph.prototype, "WhenFinished", { get: function () { return this.get("WhenFinished"); }, enumerable: false, configurable: true }); Object.defineProperty(ECLGraph.prototype, "Time", { get: function () { return this.get("Time"); }, enumerable: false, configurable: true }); Object.defineProperty(ECLGraph.prototype, "Running", { get: function () { return this.get("Running"); }, enumerable: false, configurable: true }); Object.defineProperty(ECLGraph.prototype, "RunningId", { get: function () { return this.get("RunningId"); }, enumerable: false, configurable: true }); Object.defineProperty(ECLGraph.prototype, "Failed", { get: function () { return this.get("Failed"); }, enumerable: false, configurable: true }); ECLGraph.prototype.fetchScopeGraph = function (subgraphID) { if (subgraphID) { return this.wu.fetchGraphDetails([subgraphID], ["subgraph"]).then(function (scopes) { return createGraph(scopes); }); } return this.wu.fetchGraphDetails([this.Name], ["graph"]).then(function (scopes) { return createGraph(scopes); }); }; return ECLGraph; }(StateObject)); export { ECLGraph }; var GraphCache = /** @class */ (function (_super) { __extends(GraphCache, _super); function GraphCache() { return _super.call(this, function (obj) { return Cache.hash([obj.Name]); }) || this; } return GraphCache; }(Cache)); export { GraphCache }; function walkXmlJson(node, callback, stack) { stack = stack || []; stack.push(node); callback(node.name, node.$, node.children(), stack); node.children().forEach(function (childNode) { walkXmlJson(childNode, callback, stack); }); stack.pop(); } function flattenAtt(nodes) { var retVal = {}; nodes.forEach(function (node) { if (node.name === "att") { retVal[node.$["name"]] = node.$["value"]; } }); return retVal; } var XGMMLGraph = /** @class */ (function (_super) { __extends(XGMMLGraph, _super); function XGMMLGraph() { return _super !== null && _super.apply(this, arguments) || this; } return XGMMLGraph; }(Graph)); export { XGMMLGraph }; var XGMMLSubgraph = /** @class */ (function (_super) { __extends(XGMMLSubgraph, _super); function XGMMLSubgraph() { return _super !== null && _super.apply(this, arguments) || this; } return XGMMLSubgraph; }(Subgraph)); export { XGMMLSubgraph }; var XGMMLVertex = /** @class */ (function (_super) { __extends(XGMMLVertex, _super); function XGMMLVertex() { return _super !== null && _super.apply(this, arguments) || this; } return XGMMLVertex; }(Vertex)); export { XGMMLVertex }; var XGMMLEdge = /** @class */ (function (_super) { __extends(XGMMLEdge, _super); function XGMMLEdge() { return _super !== null && _super.apply(this, arguments) || this; } return XGMMLEdge; }(Edge)); export { XGMMLEdge }; export function createXGMMLGraph(id, graphs) { var subgraphs = {}; var vertices = {}; var edges = {}; var graph = new XGMMLGraph(function (item) { return item._["id"]; }); var stack = [graph.root]; walkXmlJson(graphs, function (tag, attributes, childNodes, _stack) { var top = stack[stack.length - 1]; switch (tag) { case "graph": break; case "node": if (childNodes.length && childNodes[0].children().length && childNodes[0].children()[0].name === "graph") { var subgraph = top.createSubgraph(flattenAtt(childNodes)); stack.push(subgraph); subgraphs[attributes["id"]] = subgraph; } else { } // TODO: Is this really a node when its also a subgraph? var vertex = top.createVertex(flattenAtt(childNodes)); vertices[attributes["id"]] = vertex; break; case "edge": var edge = top.createEdge(vertices[attributes["source"]], vertices[attributes["target"]], flattenAtt(childNodes)); edges[attributes["id"]] = edge; break; default: } }); return graph; } var ScopeGraph = /** @class */ (function (_super) { __extends(ScopeGraph, _super); function ScopeGraph() { return _super !== null && _super.apply(this, arguments) || this; } return ScopeGraph; }(Graph)); export { ScopeGraph }; var ScopeSubgraph = /** @class */ (function (_super) { __extends(ScopeSubgraph, _super); function ScopeSubgraph() { return _super !== null && _super.apply(this, arguments) || this; } return ScopeSubgraph; }(Subgraph)); export { ScopeSubgraph }; var ScopeVertex = /** @class */ (function (_super) { __extends(ScopeVertex, _super); function ScopeVertex() { return _super !== null && _super.apply(this, arguments) || this; } return ScopeVertex; }(Vertex)); export { ScopeVertex }; var ScopeEdge = /** @class */ (function (_super) { __extends(ScopeEdge, _super); function ScopeEdge() { return _super !== null && _super.apply(this, arguments) || this; } return ScopeEdge; }(Edge)); export { ScopeEdge }; export function createGraph(scopes) { var subgraphs = {}; var edges = {}; var vertices = {}; var graph; for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) { var scope = scopes_1[_i]; switch (scope.ScopeType) { case "graph": graph = new ScopeGraph(function (item) { return item._.Id; }, scope); subgraphs[scope.ScopeName] = graph.root; break; case "subgraph": if (!graph) { graph = new ScopeGraph(function (item) { return item._.Id; }, scope); subgraphs[scope.ScopeName] = graph.root; } var scopeStack = scope.parentScope().split(":"); var scopeParent1 = subgraphs[scope.parentScope()]; while (scopeStack.length && !scopeParent1) { scopeParent1 = subgraphs[scopeStack.join(":")]; scopeStack.pop(); } if (!scopeParent1) { console.warn("Missing SG:Parent (".concat(scope.Id, "): ").concat(scope.parentScope())); } else { var parent1 = scopeParent1; subgraphs[scope.ScopeName] = parent1.createSubgraph(scope); } break; case "activity": var scopeParent2 = subgraphs[scope.parentScope()]; if (!scopeParent2) { console.warn("Missing A:Parent (".concat(scope.Id, "): ").concat(scope.parentScope())); } else { vertices[scope.ScopeName] = scopeParent2.createVertex(scope); } break; case "edge": edges[scope.ScopeName] = scope; break; case "function": var scopeParent3 = vertices[scope.parentScope()]; if (!scopeParent3) { console.warn("Missing F:Parent (".concat(scope.Id, "): ").concat(scope.parentScope())); } else { scopeParent3._.children().push(scope); } break; } } for (var id in edges) { var scope = edges[id]; var scopeParent3 = subgraphs[scope.parentScope()]; if (!scopeParent3) { console.warn("Missing E:Parent (".concat(scope.Id, "): ").concat(scope.parentScope())); } else { var parent3 = scopeParent3; try { var source = graph.vertex(scope.attr("IdSource").RawValue); var target = graph.vertex(scope.attr("IdTarget").RawValue); parent3.createEdge(source, target, scope); } catch (e) { // const sourceIndex = scope.attr("SourceIndex").RawValue; // const targetIndex = scope.attr("TargetIndex").RawValue; console.warn("Invalid Edge: ".concat(id)); } } } return graph; } //# sourceMappingURL=graph.js.map