-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoreTree.js
233 lines (233 loc) · 8.34 KB
/
scoreTree.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
// Serves the score report page.
const serveScoreReport = op => {
const {
err,
fs,
globals,
reportPrep,
reportScriptPrep,
scorePriorities,
scoreRisks,
servePage
} = op;
fs.readFile('scoreReport.html', 'utf8')
.then(
htmlContent => {
fs.readFile('report.js', 'utf8')
.then(
jsContent => {
const newJSContent = reportScriptPrep(jsContent, '/scoretally', [
'total',
'verdicts',
'scoreVerdicts',
'passes',
'fails',
'defects',
'major',
'minor',
'score',
'numerator',
'denominator',
'error'
]);
const newContent = reportPrep(htmlContent, newJSContent)
.replace('__riskMin__', globals.scoreWeights.risk[scoreRisks[0]])
.replace('__priorityMin__', globals.scoreWeights.priority[scorePriorities[0]])
.replace('__riskMax__', globals.scoreWeights.risk[scoreRisks.slice(-1)])
.replace('__priorityMax__', globals.scoreWeights.priority[scorePriorities.slice(-1)]);
servePage(newContent, true);
},
error => err(error, 'reading report script')
);
},
error => err(error, 'reading scoreReport page')
);
};
// Handles score requests.
const scoreHandle = (op, bodyObject) => {
const {
err,
globals,
scorePriorities,
scoreRisks
} = op;
// Checks for weight errors.
const validateWeights = (name, min, max) => {
const context = 'retrieving score';
const minNumber = Number.parseInt(min);
const maxNumber = Number.parseInt(max);
if (Number.isNaN(minNumber) || Number.isNaN(maxNumber)) {
err(`Nonnumeric ${name} weight`, context);
}
else if (minNumber < 0 || maxNumber < 0) {
err(`Negative ${name} weight`, context);
}
else if (maxNumber < minNumber) {
err(`Maximum ${name} weight smaller than minimum`, context);
}
};
// Sets the score weights.
const setScoreWeights = (key, values, min, max) => {
const minNumber = Number.parseInt(min, 10);
globals.scoreWeights[key] = {};
for (let i = 0; i < values.length; i++) {
globals.scoreWeights[key][values[i]]
= minNumber
+ i * (Number.parseInt(max, 10) - minNumber) / (values.length - 1);
}
};
const {scoreRiskMin, scoreRiskMax, scorePriorityMin, scorePriorityMax} = bodyObject;
// Validate the weights.
validateWeights('risk', scoreRiskMin, scoreRiskMax);
if (! globals.isError) {
validateWeights('priority', scorePriorityMin, scorePriorityMax);
if (! globals.isError) {
// Set the score weights.
setScoreWeights('risk', scoreRisks, scoreRiskMin, scoreRiskMax);
setScoreWeights('priority', scorePriorities, scorePriorityMin, scorePriorityMax);
// Serve a report of the scores.
serveScoreReport(op);
}
}
};
// Reports scores and tallies of test results and defects.
const scoreTree = (op, storyRef) => {
const {globals, totals, err, shorten, report, getItemData, getCollectionData} = op;
// Get data on the user story.
getItemData(storyRef, ['FormattedID'], ['Children', 'TestCases'])
.then(
// When the data arrive:
data => {
if (! globals.isError) {
// Report progress in the console if requested.
if (globals.debug) {
console.log(`Processing ${data.formattedID}`);
}
// Get data on the test cases of the user story, if any.
getCollectionData(
data.testCases.count ? data.testCases.ref : '',
['LastVerdict', 'Risk', 'Priority'],
['Defects']
)
.then(
// When the data, if any, arrive:
cases => {
// Process the test cases in parallel.
cases.forEach(testCase => {
if (! globals.isError) {
const verdict = testCase.lastVerdict;
const riskWeight = globals.scoreWeights.risk[testCase.risk];
const priorityWeight = globals.scoreWeights.priority[testCase.priority];
const weight = Number.parseInt(riskWeight) + Number.parseInt(priorityWeight);
const defectsCollection = testCase.defects;
let newNumerator;
report([['total']]);
if (verdict === 'Pass') {
newNumerator = totals.numerator + weight;
report([
['verdicts'],
['scoreVerdicts'],
['passes'],
[
'score',
Math.round(
newNumerator ? 100 * newNumerator / (totals.denominator + weight) : 0
) - totals.score
],
['numerator', weight],
['denominator', weight]
]);
}
else if (verdict === 'Fail') {
newNumerator = totals.numerator;
report([
['verdicts'],
['scoreVerdicts'],
['fails'],
[
'score',
Math.round(
newNumerator ? 100 * newNumerator / (totals.denominator + weight) : 0
) - totals.score
],
['denominator', weight]
]);
}
else if (verdict !== null) {
report([['verdicts']]);
}
// If the test case has any defects:
/*
NOTICE: this condition was liberalized temporarily in February 2021 because of a
Rally bug that reports all defect counts as 0.
*/
if (defectsCollection.count >= 0) {
// Get data on the defects.
getCollectionData(defectsCollection.ref, ['Severity'], [])
.then(
// When the data arrive:
defects => {
// Notify the user whether the defect count bug has been corrected.
if (defects.length) {
if (defectsCollection.count) {
console.log(
'Rally defect-count bug has been corrected! Revise scoreTree().'
);
}
else {
console.log('Rally defect-count bug not yet corrected!');
}
}
report([['defects', defects.length]]);
// Process their severities.
const severities = defects
.map(defect => defect.severity)
.reduce((tally, score) => {
tally[score]++;
return tally;
}, {
'Minor Problem': 0,
'Major Problem': 0
});
report([
['major', severities['Major Problem']],
['minor', severities['Minor Problem']]
]);
},
error => err(error, 'getting data on defects')
);
}
}
else {
return;
}
});
},
error => err(error, `getting data on test cases ${data.testCases.ref}`)
);
// Get data on the child user stories of the user story, if any.
getCollectionData(data.children.count ? data.children.ref : '', [], [])
.then(
// When the data, if any, arrive:
children => {
// Process the children in parallel.
children.forEach(child => {
if (! globals.isError) {
const childRef = shorten(
'hierarchicalrequirement', 'hierarchicalrequirement', child.ref
);
if (! globals.isError) {
scoreTree(op, childRef);
}
}
});
},
error => err(error, 'getting data on child user stories')
);
}
},
error => err(error, 'getting data on user story')
);
};
exports.scoreHandle = scoreHandle;
exports.scoreTree = scoreTree;