From 89433f288115e7606459a2599c56032d5bfa81ff Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Thu, 21 Sep 2017 12:56:34 +0000 Subject: [PATCH] Fixed wrong map reduce git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/GenerateMapReduceCouchbase@154381 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../top_resourceOwner/resourceOwner/map.js | 21 +++++++++++++++++++ .../top_resourceOwner/resourceOwner/reduce.js | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/main/resources/MapReduce/extraStorage/top_resourceOwner/resourceOwner/map.js b/src/main/resources/MapReduce/extraStorage/top_resourceOwner/resourceOwner/map.js index e69de29..a299361 100644 --- a/src/main/resources/MapReduce/extraStorage/top_resourceOwner/resourceOwner/map.js +++ b/src/main/resources/MapReduce/extraStorage/top_resourceOwner/resourceOwner/map.js @@ -0,0 +1,21 @@ +function(doc,meta) { + if(doc.usageRecordType == "StorageUsageRecord" || doc.recordType == "StorageUsageRecord"){ + if((doc.operationCount && isNaN(Number(doc.operationCount))) || (doc.duration && isNaN(Number(doc.duration)))){ + emit([0, "Invalid Value", doc.id], doc); + return; + } + var data = {}; + data[doc.resourceOwner] = doc.dataVolume; + var propertiesKey = []; + 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()); + var finalKey = propertiesKey.concat(dataKey); + finalKey.unshift(doc.scope); + emit(finalKey, data); + } +} \ No newline at end of file diff --git a/src/main/resources/MapReduce/extraStorage/top_resourceOwner/resourceOwner/reduce.js b/src/main/resources/MapReduce/extraStorage/top_resourceOwner/resourceOwner/reduce.js index e69de29..a299361 100644 --- a/src/main/resources/MapReduce/extraStorage/top_resourceOwner/resourceOwner/reduce.js +++ b/src/main/resources/MapReduce/extraStorage/top_resourceOwner/resourceOwner/reduce.js @@ -0,0 +1,21 @@ +function(doc,meta) { + if(doc.usageRecordType == "StorageUsageRecord" || doc.recordType == "StorageUsageRecord"){ + if((doc.operationCount && isNaN(Number(doc.operationCount))) || (doc.duration && isNaN(Number(doc.duration)))){ + emit([0, "Invalid Value", doc.id], doc); + return; + } + var data = {}; + data[doc.resourceOwner] = doc.dataVolume; + var propertiesKey = []; + 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()); + var finalKey = propertiesKey.concat(dataKey); + finalKey.unshift(doc.scope); + emit(finalKey, data); + } +} \ No newline at end of file