Added missing map-reduce
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/GenerateMapReduceCouchbase@157575 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
07c0a68cec
commit
09115443b7
|
@ -0,0 +1,23 @@
|
|||
function(doc,meta) {
|
||||
if(doc.usageRecordType == "StorageUsageRecord" || doc.recordType == "StorageUsageRecord"){
|
||||
if((doc.dataVolume && isNaN(Number(doc.dataVolume))) || (doc.operationCount && isNaN(Number(doc.operationCount)))){
|
||||
emit([0, "Invalid Value", doc.id], doc);
|
||||
return;
|
||||
}
|
||||
var data = {};
|
||||
data.dataVolume = doc.dataVolume ? Number(doc.dataVolume) : 0;
|
||||
data.operationCount = doc.operationCount ? Number(doc.operationCount) : 1;
|
||||
var timestamp = Number(doc.creationTime);
|
||||
var date = new Date(timestamp);
|
||||
var dataKey = [];
|
||||
dataKey.push(date.getUTCFullYear());
|
||||
dataKey.push(date.getUTCMonth()+1);
|
||||
dataKey.push(date.getUTCDate());
|
||||
dataKey.push(date.getUTCHours());
|
||||
dataKey.push(date.getUTCMinutes());
|
||||
dataKey.push(doc.operationType);
|
||||
|
||||
emit(dataKey, data);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
function(keys, values, rereduce){
|
||||
var total = 0;
|
||||
var dataVolume = 0;
|
||||
for(i=0; i<values.length; i++){
|
||||
total = Number(total) + Number(values[i].operationCount);
|
||||
dataVolume = Number(dataVolume) + Number(values[i].dataVolume);
|
||||
}
|
||||
|
||||
ret = {};
|
||||
ret.operationCount = Number(total);
|
||||
ret.dataVolume = Number(dataVolume);
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue