-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path210-processResults.gs
More file actions
78 lines (75 loc) · 2.16 KB
/
210-processResults.gs
File metadata and controls
78 lines (75 loc) · 2.16 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
/**
* Takes an array with results from each game iterations. Outputs processed and
* formatted results to the log and returns an array processed results that should
* be displayed in the spreadsheet.
*
* @param {array} results: The array with results from each game iteration. Each
* entry should be an object with data on the form property:numericValue.
*/
function processResults(results) {
/**
* Process and display + return data.
*/
// Sort results. (Needed for percentiles.)
var sortedResults = {};
for (let i in results[0]) {
sortedResults[i] = [];
}
for (let i in results) {
for (let j in results[i]) {
sortedResults[j].push(results[i][j]);
}
}
for (let i in sortedResults) {
sortedResults[i].sort(function(a, b) {return a - b;});
}
/**
* First build log messages.
*/
// Header row
let message = 'DISTRIBUTION: average (percentile ';
let values = [];
for (let p of BPTstatic.statistics.percentiles) {
values.push(p);
}
message += values.join(' | ') + ')\r\n---\r\n';
// Each result
for (let i in sortedResults) {
message += i + ': ';
message += average(sortedResults[i]).toFixed(2) + ' (';
values = [];
for (let p of BPTstatic.statistics.percentiles) {
values.push(percentile(sortedResults[i], p).toFixed(2));
}
message += values.join(' | ') + ') Positive at ';
message += getPositiveThreshold(sortedResults[i]).toFixed(2) + '\r\n';
}
log(message, 'statistics');
/**
* Then build output array to send to a calling spreadsheet.
*/
// Labels
let output = [['']];
for (let i in sortedResults) {
output[0].push(i);
}
// Average values
output.push(['Average']);
for (let i in sortedResults) {
output[1].push(average(sortedResults[i]));
}
// First percentile where value is non-zero
output.push(['Positive at']);
for (let i in sortedResults) {
output[2].push(getPositiveThreshold(sortedResults[i]));
}
// Percentiles
for (let p of BPTstatic.statistics.percentiles) {
let line = ['percentile ' + p];
for (let i in sortedResults) {
line.push(percentile(sortedResults[i], p));
}
output.push(line);
}
return output;
}