-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.js
More file actions
69 lines (58 loc) · 1.95 KB
/
Copy pathstats.js
File metadata and controls
69 lines (58 loc) · 1.95 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
function maphelpQuality() {
emit(this.engine, // Or put a GROUP BY key here
{sum: this.helpQuality, // the field you want stats for
min: this.helpQuality,
max: this.helpQuality,
count:1,
diff: 0, // M2,n: sum((val-mean)^2)
});
}
function mapqualityRating_misc() {
emit(this.engine, // Or put a GROUP BY key here
{sum: this.qualityRating_misc, // the field you want stats for
min: this.qualityRating_misc,
max: this.qualityRating_misc,
count:1,
diff: 0, // M2,n: sum((val-mean)^2)
});
}
function mapqualityRating_newspapers() {
emit(this.engine, // Or put a GROUP BY key here
{sum: this.qualityRating_newspapers, // the field you want stats for
min: this.qualityRating_newspapers,
max: this.qualityRating_newspapers,
count:1,
diff: 0, // M2,n: sum((val-mean)^2)
});
}
function mapspeedRating() {
emit(this.engine, // Or put a GROUP BY key here
{sum: this.speedRating, // the field you want stats for
min: this.speedRating,
max: this.speedRating,
count:1,
diff: 0, // M2,n: sum((val-mean)^2)
});
}
function reduce(key, values) {
var a = values[0]; // will reduce into here
for (var i=1/*!*/; i < values.length; i++){
var b = values[i]; // will merge 'b' into 'a'
// temp helpers
var delta = a.sum/a.count - b.sum/b.count; // a.mean - b.mean
var weight = (a.count * b.count)/(a.count + b.count);
// do the reducing
a.diff += b.diff + delta*delta*weight;
a.sum += b.sum;
a.count += b.count;
a.min = Math.min(a.min, b.min);
a.max = Math.max(a.max, b.max);
}
return a;
}
function finalize(key, value){
value.avg = value.sum / value.count;
value.variance = value.diff / value.count;
value.stddev = Math.sqrt(value.variance);
return value;
}