-
Notifications
You must be signed in to change notification settings - Fork 0
/
mechanics.js
103 lines (94 loc) · 3.04 KB
/
mechanics.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
// First, checks if it isn't implemented yet.
if (!String.prototype.format) {
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
var current_sheet;
var current_tab;
function load_tab(tab, sheet_id) {
var sheet = document.getElementById(sheet_id);
current_sheet.style.display = "none";
current_tab.style.borderBottom = "1px solid #333333";
tab.style.borderBottom = "1px solid #FFFFFF";
sheet.style.display = "block";
current_tab = tab;
current_sheet = sheet;
}
var datasets = [];
function createDataset(d, fname, genFcn = null) {
/*
* Name dataset
* - making sure it doesn't conflict with existing datasets
*/
var id = fname;
// append number to id if there are duplicates
// get existing ids
var ids = [];
for(var i = 0; i < datasets.length; i++) {
ids.push(datasets[i].name);
}
// increase number until we find a unique one
if (ids.indexOf(id) > -1) {
var ind = 0;
id = id.concat(ind.toString());
while (ids.indexOf(id) > -1) {
id = id.substring(0, id.length-1).concat((++ind).toString());
}
}
// Dataset(id, data, parent_node)
var ds = new Dataset(id, fname, d, document.getElementById("datasets"), genFcn);
datasets.push(ds);
};
function get_dataseries(id) {
var dataset = id.substring(0, id.indexOf("/"));
var column = id.substring(id.indexOf("/")+1, id.length);
for(var i = 0; i < datasets.length; i++) {
if(datasets[i].name == dataset) {
for(var j = 0; j < datasets[i].columns.length; j++) {
if(datasets[i].columns[j] == column) {
return datasets[i].data[datasets[i].columns[j]];
}
}
}
}
console.error("Data series '" + id + "' not found.");
return null;
}
function analyze() {
var analysisType = document.getElementById("analysisType").value;
var dataSeriesName = [document.getElementById("dataSeries0").value, document.getElementById("dataSeries1").value];
var differences = getData(dataSeriesName, analysisType);
var dsArray = [];
for (var i=0; i<differences.length; i++)
dsArray.push([differences[i]]);
createDataset(dsArray, 'differences', function() {return getData(dataSeriesName, analysisType);})
}
function getData(dataSeriesName, analysisType) {
var dataSeries = [get_dataseries(dataSeriesName[0]), get_dataseries(dataSeriesName[1])];
switch (analysisType) {
case "means":
var nSamples = 100;
var meanSamples = [[],[]];
for (var iSeries=0; iSeries<2; iSeries++) {
var series = dataSeries[iSeries];
for (var iSample=0; iSample<nSamples; iSample++)
meanSamples[iSeries].push(mean(bootstrap(series, series.length)))
}
var differences = subtractArrays(meanSamples[0], meanSamples[1], nSamples);
break;
case "standard deviations":
console.log("not yet implemented");
return;
default:
console.log("unknown analysis type");
return;
}
return differences;
}