-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathscope.ts
More file actions
187 lines (165 loc) · 6.41 KB
/
scope.ts
File metadata and controls
187 lines (165 loc) · 6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import { StateObject, StringAnyMap } from "@hpcc-js/util";
import { WsWorkunits } from "../services/wsWorkunits.ts";
import { Workunit } from "./workunit.ts";
export interface AttributeEx extends WsWorkunits.Property {
FormattedEnd?: string;
}
export class Attribute extends StateObject<AttributeEx, AttributeEx> implements AttributeEx {
readonly scope: BaseScope;
get properties(): AttributeEx { return this.get(); }
get Name(): string { return this.get("Name"); }
get RawValue(): string { return this.get("RawValue"); }
get Formatted(): string { return this.get("Formatted"); }
get FormattedEnd(): string | undefined { return this.get("FormattedEnd"); }
get Measure(): string { return this.get("Measure"); }
get Creator(): string { return this.get("Creator"); }
get CreatorType(): string { return this.get("CreatorType"); }
constructor(scope: BaseScope, attribute: WsWorkunits.Property) {
super();
this.scope = scope;
this.set(attribute);
}
}
export interface ScopeEx extends WsWorkunits.Scope {
}
export interface IScopeVisitor {
start(scope: BaseScope): boolean;
end(scope: BaseScope): boolean;
}
export class BaseScope extends StateObject<ScopeEx, ScopeEx> implements ScopeEx {
protected _attributeMap: { [key: string]: Attribute } = {};
protected _children: BaseScope[] = [];
get properties(): ScopeEx { return this.get(); }
get ScopeName(): string { return this.get("ScopeName"); }
get Id(): string { return this.get("Id"); }
get ScopeType(): string { return this.get("ScopeType"); }
get Properties(): WsWorkunits.Properties { return this.get("Properties", { Property: [] }); }
get Notes(): WsWorkunits.Notes { return this.get("Notes", { Note: [] }); }
get SinkActivity(): string { return this.get("SinkActivity"); }
get CAttributes(): Attribute[] {
// Match "started" and time elapsed
const retVal: Attribute[] = [];
const timeElapsed: { start: AttributeEx | null, end: AttributeEx | null } = {
start: null,
end: null
};
this.Properties.Property.forEach((scopeAttr) => {
if (scopeAttr.Measure === "ts" && scopeAttr.Name.indexOf("Started") >= 0) {
timeElapsed.start = scopeAttr;
} else if (this.ScopeName && scopeAttr.Measure === "ts" && scopeAttr.Name.indexOf("Finished") >= 0) {
timeElapsed.end = scopeAttr;
} else {
retVal.push(new Attribute(this, scopeAttr));
}
});
if (timeElapsed.start && timeElapsed.end) {
// const endTime = parser(timeElapsed.start.Formatted);
// endTime!.setMilliseconds(endTime!.getMilliseconds() + (+timeElapsed.elapsed.RawValue) / 1000000);
// timeElapsed.start.FormattedEnd = formatter(endTime!);
timeElapsed.start.FormattedEnd = timeElapsed.end.Formatted;
retVal.push(new Attribute(this, timeElapsed.start));
} else if (timeElapsed.start) {
retVal.push(new Attribute(this, timeElapsed.start));
} else if (timeElapsed.end) {
retVal.push(new Attribute(this, timeElapsed.end)); // Should not happen?
}
return retVal;
}
constructor(scope: WsWorkunits.Scope) {
super();
this.update(scope);
}
update(scope: WsWorkunits.Scope) {
this.set(scope);
this.CAttributes.forEach((attr) => {
this._attributeMap[attr.Name] = attr;
});
this.Properties.Property = [];
for (const key in this._attributeMap) {
if (this._attributeMap.hasOwnProperty(key)) {
this.Properties.Property.push(this._attributeMap[key].properties);
}
}
}
parentScope(): string {
const scopeParts = this.ScopeName.split(":");
scopeParts.pop();
return scopeParts.join(":");
}
children(): BaseScope[];
children(_: BaseScope[]): BaseScope;
children(_?: BaseScope[]): BaseScope[] | BaseScope {
if (!arguments.length) return this._children;
this._children = _!;
return this;
}
walk(visitor: IScopeVisitor): boolean {
if (visitor.start(this)) return true;
for (const scope of this.children()) {
if (scope.walk(visitor)) {
return true;
}
}
return visitor.end(this);
}
formattedAttrs(): StringAnyMap {
const retVal: StringAnyMap = {};
for (const attr in this._attributeMap) {
retVal[attr] = this._attributeMap[attr].Formatted || this._attributeMap[attr].RawValue;
}
return retVal;
}
rawAttrs(): StringAnyMap {
const retVal: StringAnyMap = {};
for (const attr in this._attributeMap) {
retVal[attr] = this._attributeMap[attr].RawValue;
}
return retVal;
}
hasAttr(name: string): boolean {
return this._attributeMap[name] !== undefined;
}
attr(name: string): Attribute {
return this._attributeMap[name] || new Attribute(this, {
Creator: "",
CreatorType: "",
Formatted: "",
Measure: "",
Name: "",
RawValue: ""
});
}
attrMeasure(name: string): string {
return this._attributeMap[name].Measure;
}
calcTooltip(parentScope?: BaseScope) {
let label = this.Id;
const rows: string[] = [];
rows.push(`<tr><td class="key">ID:</td><td class="value">${this.Id}</td></tr>`);
if (parentScope) {
rows.push(`<tr><td class="key">Parent ID:</td><td class="value">${parentScope.Id}</td></tr>`);
}
rows.push(`<tr><td class="key">Scope:</td><td class="value">${this.ScopeName}</td></tr>`);
const attrs = this.formattedAttrs();
for (const key in attrs) {
if (key === "Label") {
label = attrs[key];
} else {
rows.push(`<tr><td class="key">${key}</td><td class="value">${attrs[key]}</td></tr>`);
}
}
return `<div class="eclwatch_WUGraph_Tooltip" style="max-width:480px">
<h4 align="center">${label}</h4>
<table>
${rows.join("")}
</table>
</div>`;
}
}
export class Scope extends BaseScope {
readonly wu: Workunit;
constructor(wu: Workunit, scope: WsWorkunits.Scope) {
super(scope);
this.wu = wu;
}
}