Skip to content

Instantly share code, notes, and snippets.

@danlangford
Created August 5, 2012 01:50
Show Gist options
  • Save danlangford/3261071 to your computer and use it in GitHub Desktop.
Save danlangford/3261071 to your computer and use it in GitHub Desktop.
some functions in working on
// gonna need underscore
// http://underscorejs.org/underscore-min.js
window.myObj = {
getNames :
function(group){ return _.pluck( _.filter(this.data, function(i){ return i.groups.indexOf(group)>=0; }), 'name' ) }
,
getGroups :
function(name){ return _.find(this.data, function(i){ return i.name===name.toUpperCase(); }).groups }
,
getRelationships :
function(name){ var g = this.getGroups(name); var tmp=[]; _.each(g, function(i){ tmp = tmp.concat( myObj.getNames(i) ) }); tmp=tmp.sort(); tmp = _.uniq(tmp, true); tmp.splice(tmp.indexOf(name.toUpperCase()),1); return tmp; }
,
search :
function(q){ return _.filter(this.data, function(i){ return i.name.indexOf(q.toUpperCase())>=0 })}
,
data : []
}
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://d3js.org/d3.v2.js"></script>
<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="my-object.js"></script>
<script>
$(function(){
$.getJSON('my-data.json', function(data){
window.myObj.data=data;
})
})
</script>
</head>
<body>
</body>
</html>
$ mongoimport --host <host:port> --db <db> --file ~/Downloads/data_fixed.json --collection nodes -u <user> -p
###
### quick double PIVOT. mongo mapReduce has some limitations
###
$ mongo --host <host:port> --db <db> -u <user> -p
> fe = function(i){
... db.groups.update({group:i.group},{$push:{names:i.name}},true,false);
... db.names.update({name:i.name},{$push:{groups:i.group}},true,false);
... };
> db.nodes.find({}).forEach(fe);
> exit
### come to find out NAMES collection was most compressed
$ mongoexport --host <host:port> --db <db> -o ~/Downloads/data_names_export.json --collection names -u <user> -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment