-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetric.js
371 lines (356 loc) · 21 KB
/
metric.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
#! /usr/bin/env node
const fs = require('fs');
const _ = require('lodash');
module.exports = {
metric: function (input) {
try {
_.keys(input).forEach((section) => {
// Check if we are in the object metric_history
if (section === "metric_history") {
// In metric_history run over the subObjects (assigned_tasks,...)
_.keys(input[section]).forEach((subSection) => {
// depending on the subSection evaluate in a different way
switch (subSection) {
case "assigned_tasks":
assigned_tasks(_.values(input[section][subSection]));
break;
case "average_time_comment":
average_time_comment(_.values(input[section][subSection]));
break;
case "commit_distance":
commit_distance(_.values(input[section][subSection]));
break;
case "commit_length":
commit_length(_.values(input[section][subSection]));
break;
case "commit_size":
commit_size(_.values(input[section][subSection]));
break;
case "communication_miscalculation_effort":
communication_miscalculation_effort(_.values(input[section][subSection]));
break;
case "correlation_jira_activity_push":
correlation_jira_activity_push(_.values(input[section][subSection]));
break;
case "night_weekend_work_time":
night_weekend_work_time(_.values(input[section][subSection]));
break;
case "open_sprint_issues":
open_sprint_issues(_.values(input[section][subSection]));
break;
case "story_point_complexity":
story_point_complexity(_.values(input[section][subSection]));
break;
case "time_since_last_commit":
time_since_last_commit(_.values(input[section][subSection]));
break;
}
});
} else if (section === "mood_history") {
_.keys(input[section]).forEach(() => {
moods_calc(_.values(input[section]));
});
}
});
} catch (e) {
console.error(`[ERROR]: ${e.message}`);
process.exit(1);
}
/**
* Calculates the Moodhistory by timeMS
* @param data jsonData for metric_history mood_history
* */
function moods_calc(data) {
let content = "date,mood,userId,value,timeSubmitted \n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
let singleValues = row["teamMood"]["singleValues"];
singleValues.forEach((singleValues_row) => {
let mood = singleValues_row["mood"] ? singleValues_row["mood"] : "";
let userId = singleValues_row["userId"] ? singleValues_row["userId"] : "";
let value = singleValues_row["value"] ? singleValues_row["value"] : "";
let timeSubmitted = singleValues_row["timestamp"]["time"] ? singleValues_row["timestamp"]["time"] : 0;
let dt = new Date(timeSubmitted);
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," +
mood + "," + userId + "," + value + "," + dt.getDay() + "." + (dt.getMonth() + 1) + "." + dt.getFullYear() +
" " + dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getMilliseconds() + '\n';
});
});
fs.writeFileSync(`moods_history.csv`, content);
}
/**
* Calculates the assigned_tasks per user and timeMS and creates a csv called assigned_tasks_history.csv
* @param data jsonData for metric_history assigned_tasks
* */
function assigned_tasks(data) {
let content = "date,displayName,email,name,numIssues\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
if (row["metric"]) {
let users = row["metric"]["users"];
users.forEach((user) => {
let issuesNum = 0;
if (user["issues"]) {
issuesNum = user["issues"].length;
}
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," +
user["displayName"] + "," + user["email"] + "," + user["name"] + "," + issuesNum + '\n';
});
}
});
fs.writeFileSync(`assigned_tasks_history.csv`, content);
}
/**
* Calculates the average_time_comment per timeMS and creates a csv called average_time_comment_history.csv
* @param data jsonData for metric_history average_time_comment
* */
function average_time_comment(data) {
let content = "date,averageResponseTime,numberOfAnsweredQuestions,numberOfNotAnsweredQuestions,numberOfQuestions\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
let averageResponseTime = row["metric"]["averageResponseTime"] ? row["metric"]["averageResponseTime"] : 0;
let numberOfAnsweredQuestions = row["metric"]["numberOfAnsweredQuestions"] ? row["metric"]["numberOfAnsweredQuestions"] : 0;
let numberOfNotAnsweredQuestions = row["metric"]["numberOfNotAnsweredQuestions"] ? row["metric"]["numberOfNotAnsweredQuestions"] : 0;
let numberOfQuestions = row["metric"]["numberOfQuestions"] ? row["metric"]["numberOfQuestions"] : 0;
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," +
averageResponseTime + "," + numberOfAnsweredQuestions + "," + numberOfNotAnsweredQuestions + "," +
numberOfQuestions + '\n';
});
fs.writeFileSync(`average_time_comment_history.csv`, content);
}
/**
* Calculates the commit_distance per timeMs and user and creates a csv called commit_distance_history.csv
* @param data jsonData for metric_history commit_distance
* */
function commit_distance(data) {
let content = "date,averageMinuteDistance,commitCount,displayName,email\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
if (row["metric"]) {
let users = row["metric"]["users"];
users.forEach((user) => {
let averageMinuteDistance = user["averageMinuteDistance"] ? user["averageMinuteDistance"] : 0;
let commitCount = user["commitCount"] ? user["commitCount"] : 0;
let displayName = user["displayName"] ? user["displayName"] : 0;
let email = user["email"] ? user["email"] : 0;
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," +
averageMinuteDistance + "," + commitCount + "," + displayName + "," + email + '\n';
});
}
});
fs.writeFileSync(`commit_distance_history.csv`, content);
}
/**
* Calculates the commit_length per timeMs and User and creates a csv called commit_length_history.csv
* @param data jsonData for metric_history commit_length
* */
function commit_length(data) {
let content = "date,avgCommitLength,displayName,email\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
if (row["metric"]) {
let users = row["metric"]["users"];
users.forEach((user) => {
let avgCommitLength = user["avgCommitLength"] ? user["avgCommitLength"] : 0;
let displayName = user["displayName"] ? user["displayName"] : 0;
let email = user["email"] ? user["email"] : 0;
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," +
avgCommitLength + "," + displayName + "," + email + '\n';
});
}
});
fs.writeFileSync(`commit_length_history.csv`, content);
}
/**
* Calculates the commit_size per timeMS and User and creates a csv called commit_size_history.csv
* @param data jsonData for metric_history commit_size
* */
function commit_size(data) {
let content = "date,additionsAverage,additionsSum,deletionsAverage,deletionsSum,displayName,email,totalAverage,totalSum\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
if (row["metric"]) {
let users = row["metric"]["users"];
users.forEach((user) => {
let additionsAverage = user["additionsAverage"] ? user["additionsAverage"] : 0;
let additionsSum = user["additionsSum"] ? user["additionsSum"] : 0;
let deletionsAverage = user["deletionsAverage"] ? user["deletionsAverage"] : 0;
let deletionsSum = user["deletionsSum"] ? user["deletionsSum"] : 0;
let displayName = user["displayName"] ? user["displayName"] : 0;
let email = user["email"] ? user["email"] : 0;
let totalAverage = user["totalAverage"] ? user["totalAverage"] : 0;
let totalSum = user["totalSum"] ? user["totalSum"] : 0;
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," +
additionsAverage + "," + additionsSum + "," + deletionsAverage + ',' + deletionsSum +
"," + displayName + ',' + email + ',' + totalAverage + ',' + totalSum + '\n';
});
}
});
fs.writeFileSync(`commit_size_history.csv`, content);
}
/**
* Calculates the communication_miscalculation_effort per timeMS and creates a csv called communication_miscalculation_effort_history.csv
* @param data jsonData for metric_history communication_miscalculation_effort
* */
function communication_miscalculation_effort(data) {
let content = "date,communicationTime,communicationTimeInPercent,deltaEstimate,initialEstimate,issueKey,newTotalEstimate\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
if (row["metric"]) {
let logs = row["metric"]["logs"];
logs.forEach((log) => {
let communicationTime = log["communicationTime"] ? log["communicationTime"] : 0;
let communicationTimeInPercent = log["communicationTimeInPercent"] ? log["communicationTimeInPercent"] : 0;
let deltaEstimate = log["deltaEstimate"] ? log["deltaEstimate"] : 0;
let initialEstimate = log["initialEstimate"] ? log["initialEstimate"] : 0;
let issueKey = log["issue"]["key"] ? log["issue"]["key"] : "";
let newTotalEstimate = log["newTotalEstimate"] ? log["newTotalEstimate"] : 0;
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," +
communicationTime + "," + communicationTimeInPercent + "," + deltaEstimate + "," +
initialEstimate + "," + issueKey + "," + newTotalEstimate + '\n';
});
}
});
fs.writeFileSync(`communication_miscalculation_effort_history.csv`, content);
}
/**
* Calculates the correlation_jira_activity_push per timeMS and users and creates a csv called correlation_jira_activity_push_history.csv
* @param data jsonData for metric_history correlation_jira_activity_push
* */
function correlation_jira_activity_push(data) {
let content = "date,lastUpdated,contentActivity,id,title,publishedTime\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
let lastUpdated = row["metric"]["lastUpdated"]["time"] ? row["metric"]["lastUpdated"]["time"] : "0";
let dl = new Date(lastUpdated);
if (row["metric"]) {
let activities = row["metric"]["activities"];
if (activities) {
activities.forEach((activity => {
let contentActivity = activity["content"] ? activity["content"] : "";
let id = activity["id"] ? activity["id"] : "";
let title = activity["title"] ? activity["title"] : "";
let publishedTime = activity["published"]["time"] ? activity["published"]["time"] : 0;
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," +
dl.getDay() + "." + (dl.getMonth() + 1) + "." + dl.getFullYear() + " " + dl.getHours() + ":" + dl.getMinutes() +
":" + dl.getMilliseconds() +
"," + contentActivity + "," + id + "," + title + "," + publishedTime + '\n';
}));
}
}
});
fs.writeFileSync(`correlation_jira_activity_push_history.csv`, content);
}
/**
* Calculates the night_weekend_work_time per timeMS and users and creates a csv called night_weekend_work_time_history.csv
* @param data jsonData for metric_history night_weekend_work_time
* */
function night_weekend_work_time(data) {
let content = "date,avgCommitLength,displayName,email\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
if (row["metric"]) {
let users = row["metric"]["users"];
users.forEach((user) => {
let allWorkTimeMillis = user["allWorkTimeMillis"] ? user["allWorkTimeMillis"] : 0;
let displayName = user["displayName"] ? user["displayName"] : 0;
let email = user["email"] ? user["email"] : 0;
let name = user["name"] ? user["name"] : 0;
let nightWorkTimeMillis = user["nightWorkTimeMillis"] ? user["nightWorkTimeMillis"] : 0;
let weekendWorkTimeMillis = user["weekendWorkTimeMillis"] ? user["weekendWorkTimeMillis"] : 0;
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," +
allWorkTimeMillis + "," + displayName + "," + email + ',' +
name + ',' + nightWorkTimeMillis + ',' + weekendWorkTimeMillis + '\n';
});
}
});
fs.writeFileSync(`night_weekend_work_time_history.csv`, content);
}
/**
* Calculates the open_sprint_issues per timeMS and users and creates a csv called open_sprint_issues_history.csv
* @param data jsonData for metric_history open_sprint_issues
* */
function open_sprint_issues(data) {
let content = "date,numIssues,estimatedTimeSum\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
if (row["metric"]) {
let openIssues = row["metric"]["openIssues"];
let numIssues = openIssues.length;
let estimatedTimeSum = 0;
openIssues.forEach((issue) => {
if (issue["estimatedTime"]) {
estimatedTimeSum += parseInt(issue["estimatedTime"]);
}
});
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," + numIssues + "," + estimatedTimeSum + '\n';
}
});
fs.writeFileSync(`open_sprint_issues_history.csv`, content);
}
/**
* Calculates the story_point_complexity per timeMS and creates a csv called story_point_complexity_history.csv
* @param data jsonData for metric_history story_point_complexity
* */
function story_point_complexity(data) {
let content = "date,points,storyCount\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
if (row["metric"]) {
let story_storyPoints = row["metric"]["storyPoints"];
story_storyPoints.forEach((story) => {
let points = story["points"] ? story["points"] : 0;
let storyCount = story["storyCount"] ? story["storyCount"] : 0;
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," + points + "," + storyCount + '\n';
});
}
});
fs.writeFileSync(`story_point_complexity_history.csv`, content);
}
/**
* Calculates the time_since_last_commit per timeMS and User and creates a csv called time_since_last_commit_history.csv
* @param data jsonData for metric_history time_since_last_commit
* */
function time_since_last_commit(data) {
let content = "date,displayName,email,timeSinceLastCommit,timeLastCommit\n";
data.forEach((row) => {
let timeMS = row["timestamp"]["time"];
let d = new Date(timeMS);
if (row["metric"]) {
let users = row["metric"]["users"];
users.forEach((user) => {
let displayName = user["displayName"] ? user["displayName"] : 0;
let email = user["email"] ? user["email"] : 0;
let timeSinceLastCommit = user["timeSinceLastCommit"] ? user["timeSinceLastCommit"] : 0;
let timeLastCommit = user["timestampLastCommit"]["time"] ? user["timestampLastCommit"]["time"] : 0;
content += d.getDay() + '.' + (d.getMonth() + 1) + '.' + d.getFullYear() + " " + d.getHours() + ":" + d.getMinutes() +
":" + d.getMilliseconds() + "," + displayName + "," + email + "," + timeSinceLastCommit + "," + timeLastCommit + '\n';
});
}
});
fs.writeFileSync(`time_since_last_commit_history.csv`, content);
}
}
}