This repository was archived by the owner on Aug 31, 2026. It is now read-only.
forked from krmorse/PIVelocity
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCalculator.js
More file actions
106 lines (97 loc) · 3.75 KB
/
Copy pathCalculator.js
File metadata and controls
106 lines (97 loc) · 3.75 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
Ext.define('Calculator', {
config: {
bucketBy: '',
aggregateBy: ''
},
constructor: function (config) {
this.initConfig(config);
},
prepareChartData: function (store) {
var groupedData = this._groupData(store.getRange()),
categories = _.keys(groupedData);
if (this.bucketBy === 'release') {
return this._generateStackedColumns(categories, groupedData);
} else {
return this._generateColumns(categories, groupedData);
}
},
_groupData: function (records) {
return _.groupBy(records, function (record) {
var endDate = record.get('ActualEndDate');
if (this.bucketBy === 'month') {
return moment(endDate).startOf('month').format('MMM \'YY');
} else if (this.bucketBy === 'quarter') {
return moment(endDate).startOf('quarter').format('YYYY [Q]Q');
} else if (this.bucketBy === 'release') {
return record.get('Release')._refObjectName;
} else if (this.bucketBy === 'year') {
return moment(endDate).startOf('year').format('YYYY');
}
}, this);
},
_generateStackedColumns: function (categories, groupedData) {
var stackValues = ['Not Started', 'In Progress', 'Completed'];
var series = {};
_.each(categories, function (category) {
var group = groupedData[category];
var recordsByStackValue = _.groupBy(group, function (record) {
if (record.get('ActualEndDate')) {
return 'Completed';
} else if (record.get('ActualStartDate')) {
return 'In Progress';
} else {
return 'Not Started';
}
});
_.each(stackValues, function (stackValue) {
series[stackValue] = series[stackValue] || [];
var records = recordsByStackValue[stackValue];
if (this.aggregateBy === 'count') {
series[stackValue].push((records && records.length) || 0);
} else {
var valueTotal = _.reduce(records, function (total, r) {
var valueField = Utils.getFieldForAggregationType(this.aggregateBy);
return total + r.get(valueField);
}, 0, this);
series[stackValue].push(valueTotal);
}
}, this);
}, this);
return {
categories: categories,
series: _.map(stackValues, function (value) {
return {
name: value,
type: 'column',
data: series[value]
};
}, this)
};
},
_generateColumns: function (categories, groupedData) {
var seriesData;
if (this.aggregateBy === 'count') {
seriesData = _.map(groupedData, function (value, key) {
return [key, value.length];
});
} else {
seriesData = _.map(groupedData, function (value, key) {
var valueTotal = _.reduce(value, function (total, r) {
var valueField = Utils.getFieldForAggregationType(this.aggregateBy);
return total + r.get(valueField);
}, 0, this);
return [key, valueTotal];
}, this);
}
return {
categories: categories,
series: [
{
name: this.aggregateBy.indexOf('count') >= 0 ? 'Throughput' : 'Velocity',
type: 'column',
data: seriesData
}
]
};
}
});