-
Notifications
You must be signed in to change notification settings - Fork 4
/
transform.js
143 lines (132 loc) · 3.32 KB
/
transform.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
var Transform;
Transform = (function() {
function Transform() {}
return Transform;
})();
Transform.prototype.process = function(obj) {
var i, k, len, results;
results = [];
for (k = 0, len = obj.length; k < len; k++) {
i = obj[k];
if (i.hasOwnProperty("lang") && i.lang === "R") {
results.push(Transform.prototype["R_" + i["function"]](i.properties));
} else {
results.push(Transform.prototype[i["function"]](i.properties));
// results.push(Define.prototype.count(i.properties));
}
}
return results;
};
Transform.prototype.pow = function(obj) {
var dataTable, field, j, k, key, len, power, results, value, variable;
dataTable = lib.GoG_JSON[obj.data];
power = obj.power;
field = obj.field;
variable = obj.name;
results = [];
for (k = 0, len = dataTable.length; k < len; k++) {
j = dataTable[k];
results.push((function() {
var results1;
results1 = [];
for (key in j) {
value = j[key];
results1.push(j[variable] = Math.pow(j[field], power));
}
return results1;
})());
}
return results;
};
Transform.prototype.count = function(obj) {
var dataTable, field, j, k, key, len, power, results, value, variable;
dataTable = lib.GoG_JSON[obj.data];
// power = obj.power;
field = obj.field;
variable = obj.name;
results = [];
for(i=0;i<dataTable.length;i++){
temp=dataTable[i];
count=0;
for(j=0;j<dataTable.length;j++){
if(temp[field]==dataTable[j][field]){
count++;
}
}
temp[variable]= count;
results.push(temp);
}
/* for (k = 0, len = dataTable.length; k < len; k++) {
j = dataTable[k];
results.push((function() {
var results1;
results1 = [];
for (key in j) {
value = j[key];
results1.push(j[variable] = Math.pow(j[field], power));
}
return results1;
})());
}*/
return results;
};
Transform.prototype.groupby = function(obj) {
var dataTable, field, j, k,results, variable, count=0,YAxes,yy;
dataTable = lib.GoG_JSON[obj.data];
field = obj.field;
YAxes=obj.yAxes;
variable = obj.name;
yy=obj.y;
results = [];
dataTable.sort(function(a,b){
return a[field]- b[field]; //to reverse b.date-a.date
});
// power = obj.power;
var Result=[];
temp=dataTable[0];
temp[yy]=dataTable[0][YAxes];
results.push(temp);
for(var k =1 ; k<dataTable.length;k++)
{
temp=dataTable[k];
if(dataTable[k][field]==dataTable[k-1][field])
{
count +=dataTable[k][YAxes];
temp[yy]=count;
results.push(temp);
}
else
{
count=0;
count +=dataTable[k][YAxes];
temp[yy]=count;
results.push(temp);
}
}
return results;
};
Transform.prototype.R_fibonnaci = function(obj) {
var data, dataTable, field, length, library, variable;
dataTable = lib.GoG_JSON[obj.data];
variable = obj.name;
field = obj.field;
length = obj.length;
library = obj.library;
data = {
n: length,
sequence: true
};
ocpu.seturl("http://localhost:5888/ocpu/library/" + library + "/R");
ocpu.rpc("fibonacci", data, function(output) {
var j, k, len, m, results;
m = 0;
results = [];
for (k = 0, len = dataTable.length; k < len; k++) {
j = dataTable[k];
j[variable] = output[m];
results.push(m++);
}
return results;
});
};
//# sourceMappingURL=transform.js.map