fable 3.0.78 → 3.0.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.0.78",
3
+ "version": "3.0.80",
4
4
  "description": "An entity behavior management and API bundling library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
@@ -58,7 +58,7 @@
58
58
  "cachetrax": "^1.0.4",
59
59
  "cookie": "^0.5.0",
60
60
  "data-arithmatic": "^1.0.7",
61
- "fable-log": "^3.0.10",
61
+ "fable-log": "^3.0.12",
62
62
  "fable-serviceproviderbase": "^3.0.10",
63
63
  "fable-settings": "^3.0.8",
64
64
  "fable-uuid": "^3.0.5",
@@ -423,6 +423,24 @@ class DataFormat extends libFableServiceProviderBase
423
423
  return tmpMonths[pJavascriptDate.getMonth()];
424
424
  }
425
425
 
426
+ formatMonthDayYearFromDate (pJavascriptDate, pStrict)
427
+ {
428
+ let tmpStrict = (typeof(pStrict) !== 'undefined') ? pStrict : false;
429
+
430
+ let tmpMonth = pJavascriptDate.getMonth() + 1;
431
+ let tmpDay = pJavascriptDate.getDate();
432
+ let tmpYear = pJavascriptDate.getFullYear();
433
+
434
+ if (tmpStrict)
435
+ {
436
+ tmpMonth = this.stringPadStart(tmpMonth, 2, '0');
437
+ tmpDay = this.stringPadStart(tmpDay, 2, '0');
438
+ tmpYear = this.stringPadStart(tmpYear, 4, '0');
439
+ }
440
+
441
+ return `${tmpMonth}/${tmpDay}/${tmpYear}`;
442
+ }
443
+
426
444
  formatSortableStringFromDate (pDate)
427
445
  {
428
446
  return pDate.getFullYear()+this.stringPadStart(pDate.getMonth(),2,'0')+this.stringPadStart(pDate.getDate(),2,'0');
@@ -9,6 +9,11 @@ class FableOperation extends libFableServiceBase
9
9
  {
10
10
  super(pFable, pOptions, pServiceHash);
11
11
 
12
+ // Timestamps will just be the long ints
13
+ this.timeStamps = {};
14
+ // ProgressTrackers have an object format of: {Hash:'SomeHash',EndTime:UINT,CurrentTime:UINT,TotalCount:INT,CurrentCount:INT}
15
+ this.progressTrackers = {};
16
+
12
17
  this.serviceType = 'PhasedOperation';
13
18
 
14
19
  this.state = JSON.parse(_OperationStatePrototypeString);
@@ -79,6 +84,195 @@ class FableOperation extends libFableServiceBase
79
84
  this.writeOperationErrors(pLogText, pLogObject);
80
85
  this.fable.log.fatal(pLogText, pLogObject);
81
86
  }
87
+
88
+ /************************************************************************
89
+ * BEGINNING OF --> Telemetry Helpers
90
+ */
91
+ createTimeStamp(pTimeStampHash)
92
+ {
93
+ let tmpTimeStampHash = (typeof(pTimeStampHash) == 'string') ? pTimeStampHash : 'Default';
94
+ this.timeStamps[tmpTimeStampHash] = +new Date();
95
+ return this.timeStamps[tmpTimeStampHash];
96
+ }
97
+
98
+ getTimeDelta(pTimeStampHash)
99
+ {
100
+ let tmpTimeStampHash = (typeof(pTimeStampHash) == 'string') ? pTimeStampHash : 'Default';
101
+ if (this.timeStamps.hasOwnProperty(tmpTimeStampHash))
102
+ {
103
+ let tmpEndTime = +new Date();
104
+ return tmpEndTime-this.timeStamps[tmpTimeStampHash];
105
+ }
106
+ else
107
+ {
108
+ return -1;
109
+ }
110
+ }
111
+
112
+ logTimeDelta(pTimeStampHash, pMessage)
113
+ {
114
+ let tmpTimeStampHash = (typeof(pTimeStampHash) == 'string') ? pTimeStampHash : 'Default';
115
+ let tmpMessage = (typeof(pMessage) !== 'undefined') ? pMessage : `Elapsed for ${tmpTimeStampHash}: `;
116
+ let tmpOperationTime = this.getTimeDelta(pTimeStampHash);
117
+ this.info(tmpMessage +' ('+tmpOperationTime+'ms)');
118
+ return tmpOperationTime;
119
+ }
120
+
121
+ createProgressTracker(pTotalOperations, pProgressTrackerHash)
122
+ {
123
+ let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
124
+ let tmpTotalOperations = (typeof(pTotalOperations) == 'number') ? pTotalOperations : 100;
125
+
126
+ let tmpProgressTracker = (
127
+ {
128
+ Hash: tmpProgressTrackerHash,
129
+ StartTime: this.createTimeStamp(tmpProgressTrackerHash),
130
+ EndTime: 0,
131
+ CurrentTime: 0,
132
+ PercentComplete: -1,
133
+ AverageOperationTime: -1,
134
+ EstimatedCompletionTime: -1,
135
+ TotalCount: tmpTotalOperations,
136
+ CurrentCount:-1
137
+ });
138
+
139
+ this.progressTrackers[tmpProgressTrackerHash] = tmpProgressTracker;
140
+
141
+ return tmpProgressTracker;
142
+ }
143
+
144
+ solveProgressTrackerStatus(pProgressTrackerHash)
145
+ {
146
+ let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
147
+
148
+ if (!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash))
149
+ {
150
+ this.createProgressTracker(100, tmpProgressTrackerHash);
151
+ }
152
+
153
+ let tmpProgressTracker = this.progressTrackers[tmpProgressTrackerHash];
154
+
155
+ tmpProgressTracker.CurrentTime = this.getTimeDelta(tmpProgressTracker.Hash);
156
+
157
+ if ((tmpProgressTracker.CurrentCount > 0) && (tmpProgressTracker.TotalCount > 0))
158
+ {
159
+ tmpProgressTracker.PercentComplete = (tmpProgressTracker.CurrentCount / tmpProgressTracker.TotalCount) * 100.0;
160
+ }
161
+
162
+ if ((tmpProgressTracker.CurrentCount > 0) && (tmpProgressTracker.CurrentTime > 0))
163
+ {
164
+ tmpProgressTracker.AverageOperationTime = tmpProgressTracker.CurrentTime / tmpProgressTracker.CurrentCount;
165
+ }
166
+
167
+ if ((tmpProgressTracker.CurrentCount < tmpProgressTracker.TotalCount) && (tmpProgressTracker.AverageOperationTime > 0))
168
+ {
169
+ tmpProgressTracker.EstimatedCompletionTime = (tmpProgressTracker.TotalCount - tmpProgressTracker.CurrentCount) * tmpProgressTracker.AverageOperationTime;
170
+ }
171
+ }
172
+
173
+ updateProgressTrackerStatus(pProgressTrackerHash, pCurrentOperations)
174
+ {
175
+ let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
176
+ let tmpCurrentOperations = parseInt(pCurrentOperations);
177
+
178
+ if (isNaN(tmpCurrentOperations))
179
+ {
180
+ return false;
181
+ }
182
+
183
+ if (!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash))
184
+ {
185
+ this.createProgressTracker(100, tmpProgressTrackerHash);
186
+ }
187
+
188
+ this.progressTrackers[tmpProgressTrackerHash].CurrentCount = tmpCurrentOperations;
189
+ this.progressTrackers[tmpProgressTrackerHash].CurrentTime = this.getTimeDelta(tmpProgressTrackerHash);
190
+
191
+ this.solveProgressTrackerStatus(tmpProgressTrackerHash);
192
+
193
+ return this.progressTrackers[tmpProgressTrackerHash];
194
+ }
195
+
196
+ incrementProgressTrackerStatus(pProgressTrackerHash, pIncrementSize)
197
+ {
198
+ let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
199
+ let tmpIncrementSize = parseInt(pIncrementSize);
200
+
201
+ if (isNaN(tmpIncrementSize))
202
+ {
203
+ return false;
204
+ }
205
+
206
+ if (!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash))
207
+ {
208
+ this.createProgressTracker(100, tmpProgressTrackerHash);
209
+ }
210
+
211
+ this.progressTrackers[tmpProgressTrackerHash].CurrentCount = this.progressTrackers[tmpProgressTrackerHash].CurrentCount + tmpIncrementSize;
212
+ this.progressTrackers[tmpProgressTrackerHash].CurrentTime = this.getTimeDelta(tmpProgressTrackerHash);
213
+
214
+ this.solveProgressTrackerStatus(tmpProgressTrackerHash);
215
+
216
+ return this.progressTrackers[tmpProgressTrackerHash];
217
+ }
218
+
219
+ setProgressTrackerEndTime(pProgressTrackerHash, pCurrentOperations)
220
+ {
221
+ let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
222
+ let tmpCurrentOperations = parseInt(pCurrentOperations);
223
+
224
+ if (!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash))
225
+ {
226
+ return false;
227
+ }
228
+ if (!isNaN(tmpCurrentOperations))
229
+ {
230
+ this.updateProgressTrackerStatus(tmpProgressTrackerHash, tmpCurrentOperations);
231
+ }
232
+
233
+ this.progressTrackers[tmpProgressTrackerHash].EndTime = this.getTimeDelta(tmpProgressTrackerHash);
234
+
235
+ this.solveProgressTrackerStatus(tmpProgressTrackerHash);
236
+
237
+ return this.progressTrackers[tmpProgressTrackerHash];
238
+ }
239
+
240
+ printProgressTrackerStatus(pProgressTrackerHash)
241
+ {
242
+ let tmpProgressTrackerHash = (typeof(pProgressTrackerHash) == 'string') ? pProgressTrackerHash : 'DefaultProgressTracker';
243
+
244
+ if (!this.progressTrackers.hasOwnProperty(tmpProgressTrackerHash))
245
+ {
246
+ this.info(`>> Progress Tracker ${tmpProgressTrackerHash} does not exist! No stats to display.`);
247
+ }
248
+ else
249
+ {
250
+ const tmpProgressTracker = this.progressTrackers[tmpProgressTrackerHash];
251
+
252
+ if (tmpProgressTracker.CurrentCount < 1)
253
+ {
254
+ this.info(`>> Progress Tracker ${tmpProgressTracker.Hash} has no completed operations. ${tmpProgressTracker.CurrentTime}ms have elapsed since it was started.`);
255
+ }
256
+ else if (tmpProgressTracker.EndTime < 1)
257
+ {
258
+ this.info(`>> Progress Tracker ${tmpProgressTracker.Hash} is ${tmpProgressTracker.PercentComplete.toFixed(3)}% completed - ${tmpProgressTracker.CurrentCount} / ${tmpProgressTracker.TotalCount} operations over ${tmpProgressTracker.CurrentTime}ms (median ${tmpProgressTracker.AverageOperationTime.toFixed(3)} per). Estimated completion in ${tmpProgressTracker.EstimatedCompletionTime.toFixed(0)}ms or ${(tmpProgressTracker.EstimatedCompletionTime / 1000 / 60).toFixed(2)}minutes`)
259
+ }
260
+ else
261
+ {
262
+ this.info(`>> Progress Tracker ${tmpProgressTracker.Hash} is done and completed ${tmpProgressTracker.CurrentCount} / ${tmpProgressTracker.TotalCount} operations in ${tmpProgressTracker.EndTime}ms.`)
263
+ }
264
+ }
265
+ }
266
+
267
+ // logMemoryResourcesUsed()
268
+ // {
269
+ //
270
+ // const tmpResourcesUsed = process.memoryUsage().heapUsed / 1024 / 1024;
271
+ // this.info(`Memory usage at ${Math.round(tmpResourcesUsed * 100) / 100} MB`);
272
+ // }
273
+ /*
274
+ * END OF --> Logging and Telemetry Helpers
275
+ ************************************************************************/
82
276
  }
83
277
 
84
278
  module.exports = FableOperation;
@@ -103,6 +103,34 @@ suite
103
103
  return fTestComplete();
104
104
  }
105
105
  )
106
+ test
107
+ (
108
+ 'Get a human readable string from date',
109
+ (fTestComplete) =>
110
+ {
111
+ let testFable = new libFable();
112
+ let _DataFormat = testFable.services.DataFormat;
113
+ let tmpDateInput = new Date('1/02/1986');
114
+ Expect(_DataFormat
115
+ .formatMonthDayYearFromDate(tmpDateInput, true))
116
+ .to.equal('01/02/1986');
117
+ return fTestComplete();
118
+ }
119
+ )
120
+ test
121
+ (
122
+ 'Get a human readable string from date no zerofill',
123
+ (fTestComplete) =>
124
+ {
125
+ let testFable = new libFable();
126
+ let _DataFormat = testFable.services.DataFormat;
127
+ let tmpDateInput = new Date('06/02/1999');
128
+ Expect(_DataFormat
129
+ .formatMonthDayYearFromDate(tmpDateInput, false))
130
+ .to.equal('6/2/1999');
131
+ return fTestComplete();
132
+ }
133
+ )
106
134
  }
107
135
  );
108
136
  }