-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
344 lines (284 loc) · 14.5 KB
/
code.js
File metadata and controls
344 lines (284 loc) · 14.5 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
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
// JIRA Fields Global readonly Metadata
let storyIdField = "";
let podField = "";
let assigneeField = "";
let storyPointsField = "";
let actualEndDateColumnField = "";
let plannedEndDateColumnField = "";
let originalEstimateField = "";
let timeSpentField = "";
let remainingTimeField = "";
let storyStatusField = "";
//Non-JIRA Global readonly metadata
let completeStatusString = "";
let incompleteStatusString = "";
let devNotStartedString = "";
/**
* Function to be executed when sheet opens
*/
function onOpen() {
let ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('JIRA Menubar')
.addItem('Click to Retrieve', 'logJiraInfo')
.addToUi();
}
function initializeMetaData(){
let storiesMetaDataSheet = SpreadsheetApp.getActive().getSheetByName('Metadata');
let metadata = storiesMetaDataSheet.getDataRange().getValues();
for(let rownum=1; rownum < metadata.length; rownum++){
if((metadata[rownum][0]) === "storyIdField"){
storyIdField = metadata[rownum][1];
} else if((metadata[rownum][0]) === "podField"){
podField = metadata[rownum][1];
} else if((metadata[rownum][0]) === "assigneeField"){
assigneeField = metadata[rownum][1];
} else if((metadata[rownum][0]) === "storyPointsField"){
storyPointsField = metadata[rownum][1];
} else if((metadata[rownum][0]) === "actualEndDateColumnField"){
actualEndDateColumnField = metadata[rownum][1];
} else if((metadata[rownum][0]) === "plannedEndDateColumnField"){
plannedEndDateColumnField = metadata[rownum][1];
} else if((metadata[rownum][0]) === "originalEstimateField"){
originalEstimateField = metadata[rownum][1];
} else if((metadata[rownum][0]) === "timeSpentField"){
timeSpentField = metadata[rownum][1];
} else if((metadata[rownum][0]) === "remainingTimeField"){
remainingTimeField = metadata[rownum][1];
} else if((metadata[rownum][0]) === "storyStatusField"){
storyStatusField = metadata[rownum][1];
} else if((metadata[rownum][0]) === "completeStatusString"){
completeStatusString = metadata[rownum][1];
} else if((metadata[rownum][0]) === "incompleteStatusString"){
incompleteStatusString = metadata[rownum][1];
} else if((metadata[rownum][0]) === "devNotStartedString"){
devNotStartedString = metadata[rownum][1];
}
}
}
function roundToTwo(num) {
return +(Math.round(num + "e+2") + "e-2");
}
/**
* This function is to calculate the non working days between two dates
* @param {*} startDate
* @param {*} endDate
*/
function getNonWorkingDaysBtwTwoDates(startDate, endDate) {
let counter = 0;
let datesSheet = SpreadsheetApp.getActive().getSheetByName('Calendar');
let datesData = datesSheet.getDataRange().getValues();
let nonWorkingDays = [];
for (let rownum = 1; rownum < datesData.length; rownum++) {
if (datesData[rownum][0] !== ""){
nonWorkingDays.push(new Date(datesData[rownum][0]));
}
}
nonWorkingDays.forEach(nonWorkingDay => {
if ((nonWorkingDay >= startDate) && (nonWorkingDay <= endDate)) {
counter++;
}
});
return counter;
}
/**
* This function returns the total working days in a sprint
*/
function getSprintWorkingDays(){
let datesSheet = SpreadsheetApp.getActive().getSheetByName('Calendar');
let datesData = datesSheet.getDataRange().getValues();
let totalWorkingDays = [];
for (let rownum = 1; rownum < datesData.length; rownum++) {
if (datesData[rownum][1] !== ""){
totalWorkingDays.push(new Date(datesData[rownum][0]));
}
}
return totalWorkingDays;
}
/**
* This function is used to log into google sheets information from JIRA
*
*/
function logJiraInfo() {
initializeMetaData();
let storiesDumpSheet = SpreadsheetApp.getActive().getSheetByName('StoriesDump');
let storiesAnalysisSheet = SpreadsheetApp.getActive().getSheetByName('StoriesChart');
let data = storiesDumpSheet.getDataRange().getValues();
//First get the indexes right for the Actual Start Date, Actual End Date, Planned Start Date and Due Date
let storyIdIndex = data[0].indexOf(storyIdField);
let podIndex = data[0].indexOf(podField);
let assigneeIndex = data[0].indexOf(assigneeField);
let storyPointsIndex = data[0].indexOf(storyPointsField);
let actualEndDateColumnIndex = data[0].indexOf(actualEndDateColumnField);
let plannedEndDateColumnIndex = data[0].indexOf(plannedEndDateColumnField);
let originalEstimateIndex = data[0].indexOf(originalEstimateField);
let timeSpentIndex = data[0].indexOf(timeSpentField);
let remainingTimeIndex = data[0].indexOf(remainingTimeField);
let storyStatusIndex = data[0].indexOf(storyStatusField);
let today = new Date();
storiesAnalysisSheet.clear();
storiesAnalysisSheet.appendRow(["Key", "<ProjectName> POD", "Delay in Start - Not yet started", "Delay In Progress - Due date based", "ETC - Not yet Started", "ETC - In Progress Stories", "Delay - Completed", "Story Status", "Original Estimate", "Remaining Effort", "Time Already Spent", "Assignee", "JIRA Status", "Story Points", "Planned Due Date", "Projected Due Date"]);
let finalStoriesArray = [];
for (let rownum = 1; rownum < data.length; rownum++) {
let storyKey = data[rownum][storyIdIndex];
let storyPoints = data[rownum][storyPointsIndex];
if (storyPoints === "") {
storyPoints = 0;
}
let jiraStatus = data[rownum][storyStatusIndex];
let effortRemaining = data[rownum][remainingTimeIndex] / 28800;
let plannedDueDate = data[rownum][plannedEndDateColumnIndex];
let projectedDueDate = new Date();
let storyStatusCategory;
//If the story does not have a planned date, skip it
if (plannedDueDate === "") {
continue;
} else {
plannedDueDate = new Date(data[rownum][plannedEndDateColumnIndex]);
plannedDueDate.setHours(23, 59, 59);
}
//Status for not started Story
let yetToStart_delayInStart = 0;
let yetToStart_ETC = roundToTwo((data[rownum][originalEstimateIndex]) / 28800);;
if ((devNotStartedString.indexOf(data[rownum][storyStatusIndex])) !== -1) {
let plannedStartDate = new Date(plannedDueDate.getTime() - effortRemaining * (24 * 3600 * 1000));
if ((plannedStartDate.getDay() > 5) || (plannedStartDate.getDay() < 1)) {
plannedStartDate.setDate(plannedStartDate.getDate() - 2);
}
if (plannedStartDate < today) {
yetToStart_delayInStart = roundToTwo((today.getTime() - plannedStartDate.getTime()) / (24 * 3600 * 1000)) - getNonWorkingDaysBtwTwoDates(plannedStartDate, today);
}
if (yetToStart_delayInStart === 0) {
projectedDueDate = plannedDueDate;
} else {
projectedDueDate.setDate(plannedDueDate.getDate() + roundToTwo(yetToStart_ETC));
projectedDueDate.setDate(projectedDueDate.getDate() + getNonWorkingDaysBtwTwoDates(plannedDueDate, projectedDueDate));
}
storyStatusCategory = "Not yet Started";
}
//Status for in-progress Story
let delayInProgress_DueDateBased = 0;
let delayInProgress_ETC = 0;
if ((incompleteStatusString.indexOf(data[rownum][storyStatusIndex])) !== -1) {
let estimatedCompletionDate = new Date(today.getTime() + effortRemaining * (24 * 3600 * 1000));
if ((estimatedCompletionDate.getDay() > 5) || (estimatedCompletionDate.getDay() < 1)) {
estimatedCompletionDate.setDate(estimatedCompletionDate.getDate() + 2);
}
let nonWorkingDays_InProgress;
if (estimatedCompletionDate < plannedDueDate) {
nonWorkingDays_InProgress = getNonWorkingDaysBtwTwoDates(estimatedCompletionDate, plannedDueDate);
delayInProgress_DueDateBased = -1.0 * (roundToTwo(((plannedDueDate.getTime() - estimatedCompletionDate.getTime()) / (24 * 3600 * 1000))) - nonWorkingDays_InProgress);
console.log("Story id: " + storyKey + "::::" + plannedDueDate + "::::" + estimatedCompletionDate);
} else {
nonWorkingDays_InProgress = getNonWorkingDaysBtwTwoDates(plannedDueDate, estimatedCompletionDate);
delayInProgress_DueDateBased = roundToTwo(((estimatedCompletionDate.getTime() - plannedDueDate.getTime()) / (24 * 3600 * 1000))) - nonWorkingDays_InProgress;
console.log("Story id: " + storyKey + "::::" + plannedDueDate + "::::" + estimatedCompletionDate + "::::" + delayInProgress_DueDateBased);
}
projectedDueDate = estimatedCompletionDate;
delayInProgress_ETC = roundToTwo((data[rownum][remainingTimeIndex]) / 28800);
storyStatusCategory = "In Progress";
}
//Status for completed Story
let delayInCompletion_Completed = 0;
if ((completeStatusString.indexOf(data[rownum][storyStatusIndex])) !== -1) {
let actualCompletionDate = data[rownum][actualEndDateColumnIndex];
storyStatusCategory = "Dev Complete";
if (actualCompletionDate !== "") {
// Need to account for non-working days - remove them
delayInCompletion_Completed = roundToTwo((actualCompletionDate.getTime() - plannedDueDate.getTime()) / (24 * 3600 * 1000));
}
}
finalStoriesArray.push([data[rownum][storyIdIndex], data[rownum][podIndex], yetToStart_delayInStart, delayInProgress_DueDateBased, yetToStart_ETC, delayInProgress_ETC, delayInCompletion_Completed, storyStatusCategory, data[rownum][originalEstimateIndex], data[rownum][remainingTimeIndex], data[rownum][timeSpentIndex], data[rownum][assigneeIndex], jiraStatus, storyPoints, plannedDueDate, projectedDueDate]);
}
// Batch Update
storiesAnalysisSheet.getRange(storiesAnalysisSheet.getLastRow() + 1, 1, finalStoriesArray.length, finalStoriesArray[0].length).setValues(finalStoriesArray);
getPODStatusGeneric();
}
function getPODStatusGeneric(){
let podNames = getPODNames();
let consolidatedPODStatus = {};
let storiesAnalysisSheet = SpreadsheetApp.getActive().getSheetByName('StoriesChart');
let storiesCartData = storiesAnalysisSheet.getDataRange().getValues();
let sprintWorkingDays = getSprintWorkingDays();
for(let rownum = 0; rownum<podNames.length; rownum++){
let podName = podNames[rownum].trim();
consolidatedPODStatus[podName]={};
consolidatedPODStatus[podName].OverallSP = 0;
consolidatedPODStatus[podName].SPAchieved = 0;
consolidatedPODStatus[podName].SPExpected = 0;
consolidatedPODStatus[podName].SPExpectedTillYesterday = 0;
consolidatedPODStatus[podName].OriginalEstimates = 0;
consolidatedPODStatus[podName].ETCRemaining = 0;
consolidatedPODStatus[podName].ETCExpected = 0;
}
let podIndex = storiesCartData[0].indexOf("<ProjectName> POD");
let storyPointsIndex = storiesCartData[0].indexOf("Story Points");
let completionStatusIndex = storiesCartData[0].indexOf("Story Status");
let plannedEndDateColumnIndex = storiesCartData[0].indexOf("Planned Due Date");
let originalEstimatesIndex = storiesCartData[0].indexOf("Original Estimate");
let etcRemainingIndex = storiesCartData[0].indexOf("Remaining Effort");
let eodToday = new Date();
eodToday.setHours(23, 59, 59);
let eodYesterday = new Date();
eodYesterday.setHours(23, 59, 59);
eodYesterday.setDate(eodYesterday.getDate() - 1);
for (let rownum = 1; rownum < storiesCartData.length; rownum++) {
let podName = (storiesCartData[rownum][podIndex]).trim().toUpperCase();
let value = consolidatedPODStatus[podName];
try{
consolidatedPODStatus[podName].OverallSP += storiesCartData[rownum][storyPointsIndex];
// SP Status
if (storiesCartData[rownum][completionStatusIndex] === "Dev Complete") {
consolidatedPODStatus[podName].SPAchieved += storiesCartData[rownum][storyPointsIndex];
}
if (storiesCartData[rownum][plannedEndDateColumnIndex] <= eodToday) {
consolidatedPODStatus[podName].SPExpected += storiesCartData[rownum][storyPointsIndex];
}
if (storiesCartData[rownum][plannedEndDateColumnIndex] <= eodYesterday) {
consolidatedPODStatus[podName].SPExpectedTillYesterday += storiesCartData[rownum][storyPointsIndex];
}
// ETC Status
if (storiesCartData[rownum][originalEstimatesIndex] !== "") {
consolidatedPODStatus[podName].OriginalEstimates += storiesCartData[rownum][originalEstimatesIndex];
}
if (storiesCartData[rownum][etcRemainingIndex] !== "") {
consolidatedPODStatus[podName].ETCRemaining += storiesCartData[rownum][etcRemainingIndex];
}
let index = 0;
for (let i = 0; i < sprintWorkingDays.length; i++) {
if (sprintWorkingDays[i] > new Date()) {
index = i + 1;
break;
}
}
consolidatedPODStatus[podName].ETCExpected = consolidatedPODStatus[podName].OriginalEstimates * (index / sprintWorkingDays.length);
}catch(err){
}
//console.log("Hello");
}
console.log(consolidatedPODStatus);
//Add data to visualization sheet
let podStatusSheet = SpreadsheetApp.getActive().getSheetByName('POD Status');
podStatusSheet.clear();
podStatusSheet.appendRow(["Responsive POD", "SP - Total", "SP - Expected by EOD", "SP - Achieved", "Original Estimates", "ETC - Expected", "ETC - Pending", "SP - Efficiency", "ETC - Overflow", "SP - Expected by Yesterday"]);
let podStatusKeys = Object.keys(consolidatedPODStatus);
for(let rownum = 0; rownum <podStatusKeys.length; rownum++){
let key = podStatusKeys[rownum];
podStatusSheet.appendRow([key,Math.round(consolidatedPODStatus[key].OverallSP), Math.round(consolidatedPODStatus[key].SPExpected), Math.round(consolidatedPODStatus[key].SPAchieved), roundToTwo(consolidatedPODStatus[key].OriginalEstimates / 28800), roundToTwo(consolidatedPODStatus[key].ETCExpected / 28800), roundToTwo(consolidatedPODStatus[key].ETCRemaining / 28800), roundToTwo(consolidatedPODStatus[key].SPAchieved / consolidatedPODStatus[key].SPExpected), roundToTwo(consolidatedPODStatus[key].ETCRemaining / consolidatedPODStatus[key].ETCExpected) - 1, Math.round(consolidatedPODStatus[key].SPExpectedTillYesterday)]);
}
}
function getPODNames(){
let podNames = [];
let cleanedPODNames = []
let storiesMetaDataSheet = SpreadsheetApp.getActive().getSheetByName('Metadata');
let metadata = storiesMetaDataSheet.getDataRange().getValues();
let rowData;
for(rowData in metadata){
if(metadata[rowData][0] === "podNamesField"){
podNames = metadata[rowData][1].split(";");
}
}
podNames.forEach(entry => cleanedPODNames.push(entry.trim().toUpperCase()));
console.log(podNames);
return cleanedPODNames;
}