forked from SciLifeLab/external_kpis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
couchdb_views.js
141 lines (127 loc) · 3.34 KB
/
couchdb_views.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
/**
* ================= Database: projects ========================================
*/
/*
* Design: kpi_external
* View: projects
* Map function
*/
/*
* kpi_external/projects
* Map function
*/
function(doc) {
var queued = "0000-00-00";
var close = "0000-00-00";
var day = 1000*60*60*24;
var dayDiff = function (date1, date2) {
var diff = Math.ceil((date2.getTime()-date1.getTime())/(day));
return diff;
}
var production = (doc["details"]["type"] == "Production");
if(production) {
if (doc["details"]["queued"]) {
queued = doc["details"]["queued"];
}
if (doc["close_date"]) {
close = doc["close_date"];
}
var bin = null;
var today = new Date();
var diff;
//var unit = "week";
var unit = "w";
if(doc["details"]["queued"] && doc["close_date"]) {
var qD = new Date(queued);
var cD = new Date(close);
diff = dayDiff(qD, cD);
//diff = Math.ceil( (cD.getTime()-qD.getTime()) / day);
//if(diff <= 4 * 7) {
if(diff <= 6 * 7) {
//bin = "0-4 weeks";
bin = "0-6 " + unit;
//} else if (diff <= 8 * 7) {
// bin = "4-8 weeks";
} else if (diff <= 12 * 7) {
//bin = "8-12 weeks";
bin = "6-12 " + unit;
} else if (diff <= 24 * 7) {
bin = "12-24 " + unit;
} else if (diff <= 52 * 7) {
bin = "24-52 " + unit;
}
}
var KPI = Object();
KPI["Queue date"] = queued;
KPI["Close date"] = close;
KPI["Total time"] = diff;
emit([ bin, doc["project_name"] ], KPI);
}
}
/*
* Design: kpi_external
* View: projects
* Reduce function
*/
function(keys, values, rereduce) {
if (rereduce) {
return sum(values);
} else {
return values.length;
}
}
/*
* Design: kpi_external
* View: application_projects
* Map function
*/
function(doc) {
if(doc["source"] == "lims" && doc["details"]["type"] == "Production") {
/* skip some bad apples */
if(doc["application"] == null) { exit; }
if(doc["application"].indexOf("bogus") != -1) { exit; }
/* emit application & project id */
emit(doc["application"], doc["project_id"]);
}
}
/*
* Design: kpi_external
* View: application_projects
* Reduce function
*/
_count
/*
* Design: kpi_external
* View: application_samples
* Map function
*/
function(doc) {
if(doc["source"] == "lims" && doc["details"]["type"] == "Production") {
/* skip some bad apples */
if(doc["application"] == null) { exit; }
if(doc["application"].indexOf("bogus") != -1) { exit; }
no_of_samples = +doc["no_of_samples"] || 0
// emit([doc["open_date"], doc["application"]], no_of_samples);
emit(doc["application"], no_of_samples);
}
}
/*
* Design: kpi_external
* View: application_samples
* Reduce function
*/
_sum
/**
* ================= Database: flowcells ========================================
*/
/**
* Design: reads
* View: per_lane
*/
function(doc) {
var lanes = doc["illumina"]["run_summary"];
for (l in lanes) {
var reads = doc["illumina"]["run_summary"][l]["Clusters PF R1"];
emit([doc["RunParameters"]["RunMode"], doc["RunInfo"]["Id"], l],reads);
}
}