-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStatCalculator.js
258 lines (207 loc) · 7.54 KB
/
StatCalculator.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
define([], function() {
function StatisticsCalculator(issueArray) {
this.issueArray = issueArray;
}
function getStartDate(issue) {
return parseDate(issue.fields.created);
}
function getResolutionDate(issue) {
var finalState = null;
var finalDate = null;
issue.changelog.histories.forEach(function(history) {
var dateOccured = parseDate(history.created);
history.items.forEach(function(item) {
if (item.field == "status" && item.toString == "Resolved") {
finalState = item.toString;
finalDate = dateOccured;
}
}.bind(this));
});
return finalDate;
}
function getTotalTimeInColumns(issue) {
var columnChanges = getColumnChanges(issue);
var columnMap = {};
function initialiseColumnIfEmpty(key) {
if (!columnMap[key]) {
columnMap[key] = 0;
}
}
columnChanges.forEach(function(change) {
initialiseColumnIfEmpty(change.column);
columnMap[change.column] += change.time;
})
return columnMap;
}
function getColumnChanges(issue) {
var previousDate = getStartDate(issue);
var transitionArray = [];
var finalState = null;
issue.changelog.histories.forEach(function(history) {
var dateOccured = parseDate(history.created);
history.items.forEach(function(item) {
if (item.field == "status") {
transitionArray.push({column: item.fromString, time: Math.round((dateOccured - previousDate) / 1000 / 60 / 60 / 24)})
previousDate = dateOccured;
finalState = item.toString;
}
}.bind(this));
});
transitionArray.push({column: finalState, time: Math.round((new Date() - previousDate) / 1000 / 60 / 60 / 24)})
return transitionArray;
}
function getResolutionTime(issue) {
var startDate = getStartDate(issue);
var resolutionDate = getResolutionDate(issue);
if (resolutionDate) {
return Math.round((resolutionDate - startDate) / 1000 / 60 / 60 / 24);
}
return null;
}
/**
* Returns issues created before or on a certain date
*
* date: Date object
* optionalIssues: Array of issues to filter on. Filters on all issues if not present
*/
StatisticsCalculator.prototype.getIssuesCreatedBeforeOrOn = function(date, optionalIssues) {
var issues = optionalIssues ? optionalIssues : this.issueArray;
return issues.filter(function(issue) { return parseDate(issue.fields.created) <= date });
}
/**
* Returns issues created after or on a certain date
*
* date: Date object
* optionalIssues: Array of issues to filter on. Filters on all issues if not present
*/
StatisticsCalculator.prototype.getIssuesCreatedAfterOrOn = function(date, optionalIssues) {
var issues = optionalIssues ? optionalIssues : this.issueArray;
return issues.filter(function(issue) { return parseDate(issue.fields.created) >= date });
}
/**
* Returns a map of priorities to an array of issues
* e.g. {"High": [issue1Obj, issue2Obj], "Medium": [issue3Obj]}
*
* optionalIssues: Array of issues to filter on. Filters on all issues if not present
*/
StatisticsCalculator.prototype.getPriorities = function(optionalIssues) {
var issues = optionalIssues ? optionalIssues : this.issueArray;
var priorityMap = {};
var issueMap = {};
function initialiseMapKeyIfEmpty(key) {
if (!issueMap[key]) {
issueMap[key] = [];
}
}
issues.forEach(function(issue) {
var priorityKey = issue.fields.priority.id;
var priorityName = issue.fields.priority.name;
initialiseMapKeyIfEmpty(priorityKey);
issueMap[priorityKey].push(issue);
priorityMap[priorityKey] = priorityName;
})
return {issues: issueMap, priorityMap: priorityMap}
}
/**
* Returns a map of components to an array of issues
* e.g. {"Browser": [issue1Obj, issue2Obj], "Server": [issue3Obj]}
*
* optionalIssues: Array of issues to filter on. Filters on all issues if not present
*/
StatisticsCalculator.prototype.getComponents = function(optionalIssues) {
var issues = optionalIssues ? optionalIssues : this.issueArray;
var componentMap = {};
function initialiseComponentIfEmpty(key) {
if (!componentMap[key]) {
componentMap[key] = [];
}
}
issues.forEach(function(issue) {
issue.fields.components.forEach(function(component) {
initialiseComponentIfEmpty(component.name);
componentMap[component.name].push(issue);
})
})
return componentMap;
}
/**
* Returns a map of resolutions to an array of issues
* e.g. {"Fixed": [issue1Obj, issue2Obj], "Not a bug": [issue3Obj]}
*
* optionalIssues: Array of issues to filter on. Filters on all issues if not present
*/
StatisticsCalculator.prototype.getResolution = function(optionalIssues) {
var issues = optionalIssues ? optionalIssues : this.issueArray;
var resolutionMap = {};
function initialiseResolutionIfEmpty(key) {
if (!resolutionMap[key]) {
resolutionMap[key] = [];
}
}
issues.forEach(function(issue) {
var resolution = issue.fields.resolution ? issue.fields.resolution.name : "No Resolution"
initialiseResolutionIfEmpty(resolution);
resolutionMap[resolution].push(issue);
})
return resolutionMap;
}
/**
* Returns a map of reporters to an array of issues
* e.g. {"John Smith": [issue1Obj, issue2Obj], "Father Ted": [issue3Obj]}
*
* optionalIssues: Array of issues to filter on. Filters on all issues if not present
*/
StatisticsCalculator.prototype.getReporters = function(optionalIssues) {
var issues = optionalIssues ? optionalIssues : this.issueArray;
var reporterMap = {};
function initialiseReporterIfEmpty(key) {
if (!reporterMap[key]) {
reporterMap[key] = [];
}
}
issues.forEach(function(issue) {
var reporter = issue.fields.reporter.displayName
initialiseReporterIfEmpty(reporter);
reporterMap[reporter].push(issue);
})
return reporterMap;
}
/**
* Returns a map of days to resolution to an array of issues. "null" key if not resolved
* e.g. {4: [issue1Obj, issue2Obj], 10: [issue3Obj], null: [issue4Obj]}
*
* optionalIssues: Array of issues to filter on. Filters on all issues if not present
*/
StatisticsCalculator.prototype.getResolutionTime = function(optionalIssues) {
var issues = optionalIssues ? optionalIssues : this.issueArray;
var resolutionMap = {};
function initialiseResolutionIfEmpty(key) {
if (!resolutionMap[key]) {
resolutionMap[key] = [];
}
}
issues.forEach(function(issue) {
var resolutionTime = getResolutionTime(issue);
initialiseResolutionIfEmpty(resolutionTime);
resolutionMap[resolutionTime].push(issue);
})
return resolutionMap;
}
/**
* Returns an array of objects, which includes an issue and a with map of
* how many days that issue was in each column
* e.g. [{issue: issue1Obj, columnDuration: {"In Dev": 5, "In Test": 2, "Closed": 112}}]
*
* optionalIssues: Array of issues to filter on. Filters on all issues if not present
*/
StatisticsCalculator.prototype.getColumnDuration = function(optionalIssues) {
var issues = optionalIssues ? optionalIssues : this.issueArray;
var issuesArray = [];
issues.forEach(function(issue) {
var totalTimeInColumns = getTotalTimeInColumns(issue);
issuesArray.push({issue: issue, columnDuration: totalTimeInColumns})
})
return issuesArray;
}
return StatisticsCalculator;
});