Created
August 13, 2014 12:55
-
-
Save nownabe/c69a6475f8d8da8cdbc1 to your computer and use it in GitHub Desktop.
7db7w Riak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"inputs": "rooms", | |
"query": [ | |
{ | |
"map": { | |
"language": "javascript", | |
"source": " | |
function(v) { | |
key = v.key; | |
floor = key.substring(0, key.length - 2); | |
parsed_data = JSON.parse(v.values[0].data); | |
var data = {}; | |
data[floor] = parsed_data.capacity; | |
return [data] | |
} | |
" | |
} | |
}, | |
{ | |
"reduce": { | |
"language": "javascript", | |
"source": " | |
function(v) { | |
var totals = {}; | |
for (var i in v) { | |
for (var floor in v[i]) { | |
if (totals[floor]) totals[floor] += v[i][floor]; | |
else totals[floor] = v[i][floor]; | |
} | |
} | |
return [totals]; | |
} | |
" | |
} | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"inputs": { | |
"bucket": "rooms", | |
"key_filters": [["string_to_int"], ["between", 4201, 4399]] | |
}, | |
"query": [ | |
{ | |
"map": { | |
"language": "javascript", | |
"source": " | |
function(v) { | |
key = v.key; | |
floor = key.substring(0, key.length - 2); | |
parsed_data = JSON.parse(v.values[0].data); | |
var data = {}; | |
data[floor] = parsed_data.capacity; | |
return [data] | |
} | |
" | |
} | |
}, | |
{ | |
"reduce": { | |
"language": "javascript", | |
"source": " | |
function(v) { | |
var totals = {}; | |
for (var i in v) { | |
for (var floor in v[i]) { | |
if (totals[floor]) totals[floor] += v[i][floor]; | |
else totals[floor] = v[i][floor]; | |
} | |
} | |
return [totals]; | |
} | |
" | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment