/
ProjectionsMapper.js
57 lines (45 loc) · 1.09 KB
/
ProjectionsMapper.js
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
define(['./_module'], function (app) {
'use strict';
return app.provider('ProjectionsMapper', function () {
var lastRequest = {},
lastTimestamp;
function map (data) {
var proj = data.projections,
current = {},
currentTime = new Date(),
i = 0,
length = proj.length,
item,
eventProcessed,
elapsedTime,
last,
name;
proj.sort(function (a, b) {
return a.name.localeCompare(b.name);
});
for(; i < length; i++) {
item = proj[i];
name = item.name;
last = lastRequest[name];
current[name] = item;
if(last !== undefined && lastTimestamp) {
eventProcessed = item.eventsProcessedAfterRestart - last.eventsProcessedAfterRestart;
elapsedTime = currentTime - lastTimestamp;
item.eventsPerSecond = (1000.0 * eventProcessed / elapsedTime).toFixed(1);
}
item.location = encodeURIComponent(item.statusUrl);
proj[i] = item;
}
lastRequest = current;
lastTimestamp = currentTime;
return proj;
}
this.$get = [
function () {
return {
map: map
};
}
];
});
});