Created
April 9, 2009 13:44
-
-
Save kennethkalmer/92476 to your computer and use it in GitHub Desktop.
Experiments in couchdb
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
function(doc) { | |
if(doc.user && doc.service && doc.time && doc.action) { | |
if(doc.action == "LOGOUT" && parseInt(doc.retr) > 0) { | |
var date = new Date( doc.time ); | |
var year = date.getFullYear(); | |
var month = date.getMonth(); | |
if( month.toString().length == 1 ) month = '0' + month; | |
var day = date.getDate(); | |
if( day.toString().length == 1 ) day = '0' + day; | |
var key = year + '-' + month + '-' + day; | |
emit(key, {user: doc.user, size: parseInt(doc.retr)}); | |
} | |
} | |
} |
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
function( keys, values, rereduce ) { | |
var output = {}; | |
if( !rereduce ) { | |
for each( var doc in values ) { | |
if( output[doc.user] ){ | |
output[doc.user]['count'] += 1; | |
output[doc.user]['size'] += doc.size; | |
} | |
else | |
{ | |
output[doc.user] = { 'count': 1, 'size': doc.size }; | |
} | |
} | |
} | |
else { | |
for( var i in values ) { | |
for( var j in values[i]) { | |
output[j] = values[i][j]; | |
} | |
} | |
} | |
return output; | |
} |
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
function(doc) { | |
if(doc.user && doc.service && doc.time && doc.action) { | |
if(doc.action == "LOGOUT" && parseInt(doc.retr) > 0) { | |
var date = new Date( doc.time ); | |
var year = date.getFullYear(); | |
var month = date.getMonth(); | |
if( month.toString().length == 1 ) month = '0' + month; | |
var day = date.getDate(); | |
if( day.toString().length == 1 ) day = '0' + day; | |
var key = year + '-' + month + '-' + day; | |
emit(key, 1); | |
} | |
} | |
} |
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
function( keys, values ) { | |
return sum(values); | |
} |
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
{ | |
"_id": "0000f68e73f3521f3ee8b3b51e0101d7", | |
"_rev": "1-3732031452", | |
"user": "[email protected]", | |
"host": "pop-5", | |
"time": "2009/03/13 05:47:08 +0000", | |
"action": "LOGOUT", | |
"service": "pop3d", | |
"ip": "[10.0.0.1]", | |
"top": "0", | |
"retr": "0" | |
} |
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
function(doc) { | |
var months = ["January", "February", "March", "April", | |
"May", "June", "July", "August", | |
"September", "October", "November", "December"]; | |
if(doc.user && doc.service && doc.time && doc.action) { | |
if(doc.action == "LOGOUT" && parseInt(doc.retr) > 0) { | |
var date = new Date( doc.time ); | |
var year = date.getFullYear(); | |
var month = date.getMonth(); | |
var month_s = month.toString(); | |
if( month_s.length == 1 ) month_s = '0' + month_s; | |
var key = year + '-' + month_s + ' ' + months[ month - 1 ]; | |
emit(key, {user: doc.user, size: parseInt(doc.retr) }); | |
} | |
} | |
} |
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
function( keys, values, rereduce ) { | |
var output = {}; | |
if( !rereduce ) { | |
for each( var doc in values ) { | |
if( output[doc.user] ){ | |
output[doc.user]['count'] += 1; | |
output[doc.user]['size'] += doc.size; | |
} | |
else | |
{ | |
output[doc.user] = { 'count': 1, 'size': doc.size }; | |
} | |
} | |
} | |
else { | |
for( var i in values ) { | |
for( var j in values[i]) { | |
output[j] = values[i][j]; | |
} | |
} | |
} | |
return output; | |
} |
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
function(doc) { | |
var months = ["January", "February", "March", "April", | |
"May", "June", "July", "August", | |
"September", "October", "November", "December"]; | |
if(doc.user && doc.service && doc.time && doc.action) { | |
if(doc.action == "LOGOUT" && parseInt(doc.retr) > 0) { | |
var date = new Date( doc.time ); | |
var year = date.getFullYear(); | |
var month = date.getMonth(); | |
var month_s = month.toString(); | |
if( month_s.length == 1 ) month_s = '0' + month_s; | |
var key = year + '-' + month_s + ' ' + months[ month - 1 ]; | |
emit(key, 1); | |
} | |
} | |
} |
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
function( keys, values ) { | |
return sum(values); | |
} |
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
{ | |
"_id": "_design/usage", | |
"_rev": "11-4090663094", | |
"language": "javascript", | |
"views": { | |
"daily": { | |
"map": "function(doc) {\n if(doc.user && doc.service && doc.time && doc.action) {\n if(doc.action == \"LOGOUT\" && parseInt(doc.retr) > 0) {\n var date = new Date( doc.time );\n var year = date.getFullYear();\n var month = date.getMonth();\n if( month.toString().length == 1 ) month = '0' + month;\n var day = date.getDate();\n if( day.toString().length == 1 ) day = '0' + day;\n var key = year + '-' + month + '-' + day;\n emit(key, {user: doc.user, size: parseInt(doc.retr)});\n }\n }\n}", | |
"reduce": "function( keys, values, rereduce ) {\n\n var output = {};\n if( !rereduce ) {\n for each( var doc in values ) {\n if( output[doc.user] ){\n output[doc.user]['count'] += 1;\n output[doc.user]['size'] += doc.size;\n }\n else\n {\n output[doc.user] = { 'count': 1, 'size': doc.size };\n }\n }\n }\n else {\n for( var i in values ) {\n for( var j in values[i]) {\n output[j] = values[i][j];\n }\n }\n }\n return output;\n}" | |
}, | |
"days": { | |
"map": "function(doc) {\n if(doc.user && doc.service && doc.time && doc.action) {\n if(doc.action == \"LOGOUT\" && parseInt(doc.retr) > 0) {\n var date = new Date( doc.time );\n var year = date.getFullYear();\n var month = date.getMonth();\n if( month.toString().length == 1 ) month = '0' + month;\n var day = date.getDate();\n if( day.toString().length == 1 ) day = '0' + day;\n var key = year + '-' + month + '-' + day;\n emit(key, 1);\n }\n }\n}", | |
"reduce": "function( keys, values ) {\n return sum(values);\n}" | |
}, | |
"months": { | |
"map": "function(doc) {\n var months = [\"January\", \"February\", \"March\", \"April\", \n \"May\", \"June\", \"July\", \"August\",\n \"September\", \"October\", \"November\", \"December\"];\n\n if(doc.user && doc.service && doc.time && doc.action) {\n if(doc.action == \"LOGOUT\" && parseInt(doc.retr) > 0) {\n var date = new Date( doc.time );\n var year = date.getFullYear();\n var month = date.getMonth();\n var month_s = month.toString();\n if( month_s.length == 1 ) month_s = '0' + month_s;\n var key = year + '-' + month_s + ' ' + months[ month - 1 ];\n emit(key, 1);\n }\n }\n}", | |
"reduce": "function( keys, values ) {\n return sum(values);\n}" | |
}, | |
"monthly": { | |
"map": "function(doc) {\n var months = [\"January\", \"February\", \"March\", \"April\", \n \"May\", \"June\", \"July\", \"August\",\n \"September\", \"October\", \"November\", \"December\"];\n\n if(doc.user && doc.service && doc.time && doc.action) {\n if(doc.action == \"LOGOUT\" && parseInt(doc.retr) > 0) {\n var date = new Date( doc.time );\n var year = date.getFullYear();\n var month = date.getMonth();\n var month_s = month.toString();\n if( month_s.length == 1 ) month_s = '0' + month_s;\n var key = year + '-' + month_s + ' ' + months[ month - 1 ];\n emit(key, {user: doc.user, size: parseInt(doc.retr) });\n }\n }\n}", | |
"reduce": "function( keys, values, rereduce ) {\n\n var output = {};\n if( !rereduce ) {\n for each( var doc in values ) {\n if( output[doc.user] ){\n output[doc.user]['count'] += 1;\n output[doc.user]['size'] += doc.size;\n }\n else\n {\n output[doc.user] = { 'count': 1, 'size': doc.size };\n }\n }\n }\n else {\n for( var i in values ) {\n for( var j in values[i]) {\n output[j] = values[i][j];\n }\n }\n }\n return output;\n}" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment