Skip to content

Commit

Permalink
adding visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Aug 16, 2012
1 parent ab02d16 commit e4b3000
Show file tree
Hide file tree
Showing 11 changed files with 7,179 additions and 79 deletions.
12 changes: 6 additions & 6 deletions README.md
@@ -1,16 +1,16 @@
neosocial
NeoSocial
=========

Example application to connect to one of the social networks
Example application to connect Neo4j to Facebook using the Neography Gem.


Pre-Requisites
--------------

You will need to get a Facebook Consumer Key and Secret on https://developers.facebook.com/apps
Select the "user_likes", "user_location", "friend_likes", "friend_location" permissions.
You will need Neo4j in order for your database.
You will need Redis in order to use Sidekiq for background jobs.
* You will need to get a Facebook Consumer Key and Secret on https://developers.facebook.com/apps
* Select the "user_likes", "user_location", "friend_likes", "friend_location" permissions.
* You will need Neo4j in order for your database.
* You will need Redis in order to use Sidekiq for background jobs.

Installation
----------------
Expand Down
2 changes: 1 addition & 1 deletion lib/neosocial/models/thing.rb
Expand Up @@ -3,7 +3,7 @@ class Thing
attr_accessor :uid, :name

def initialize(node)
@neo_id = node["self"].split('/').last
@neo_id = node["self"].split('/').last.to_i
@uid = node["data"]["uid"]
@name = node["data"]["name"]
end
Expand Down
15 changes: 12 additions & 3 deletions lib/neosocial/models/user.rb
Expand Up @@ -3,7 +3,7 @@ class User
attr_accessor :uid, :name, :image_url, :location, :token

def initialize(node)
@neo_id = node["self"].split('/').last
@neo_id = node["self"].split('/').last.to_i
@uid = node["data"]["uid"]
@name = node["data"]["name"]
@image_url = node["data"]["img_url"]
Expand Down Expand Up @@ -88,10 +88,10 @@ def friends
end

def friends_count
cypher = "START me = node(#{@neo_id})
cypher = "START me = node({neo_id})
MATCH me -[:friends]-> friend
RETURN COUNT(friend)"
results = $neo_server.execute_query(cypher)
results = $neo_server.execute_query(cypher, {:id => @neo_id})

if results["data"][0]
results["data"][0][0]
Expand All @@ -101,4 +101,13 @@ def friends_count

end

def friend_matrix
cypher = "START me = node({id})
MATCH me -[:friends]-> friends -[:friends]-> fof
WHERE fof <> me
RETURN friends.name, collect(fof.name)
ORDER BY COUNT(fof) "
$neo_server.execute_query(cypher, {:id => @neo_id})["data"]
end

end
10 changes: 10 additions & 0 deletions neosocial_app.rb
Expand Up @@ -60,6 +60,16 @@ class App < Sinatra::Base
haml :'thing/index'
end

get '/user/:id/visualization' do
@user = user(params[:id])
haml :'user/visualization'
end

get '/visualization' do
@user = current_user
@user.friend_matrix.map{|fm| {"name" => fm[0], "follows" => fm[1]} }.to_json
end

# Things
get '/thing/:id' do
@thing = Thing.get_by_id(params[:id])
Expand Down
3 changes: 3 additions & 0 deletions public/css/style.css
Expand Up @@ -25,3 +25,6 @@ footer li {
display: inline-block;
}

path.chord {
fill-opacity: .67;
}
70 changes: 1 addition & 69 deletions public/js/app.js
@@ -1,70 +1,2 @@
$('.dropdown-toggle').dropdown();
$(".alert").alert();
$('.typeahead').typeahead();


$("#cities").typeahead({
source: function(typeahead, query) {
if(this.ajax_call)
this.ajax_call.abort();
this.ajax_call = $.ajax({
dataType : 'json',
data: {
q: query
},
url: $("#cities").data('source'),
success: function(data) {
typeahead.process(data);
}
});
},
property: 'name',
onselect: function (obj) {
$("#city_id").val(obj.id)
console.log(obj);
}
});

$("#regions").typeahead({
source: function(typeahead, query) {
if(this.ajax_call)
this.ajax_call.abort();
this.ajax_call = $.ajax({
dataType : 'json',
data: {
q: query
},
url: $("#regions").data('source'),
success: function(data) {
typeahead.process(data);
}
});
},
property: 'name',
onselect: function (obj) {
$("#region_id").val(obj.id)
console.log(obj);
}
});

$("#countries").typeahead({
source: function(typeahead, query) {
if(this.ajax_call)
this.ajax_call.abort();
this.ajax_call = $.ajax({
dataType : 'json',
data: {
q: query
},
url: $("#countries").data('source'),
success: function(data) {
typeahead.process(data);
}
});
},
property: 'name',
onselect: function (obj) {
$("#country_id").val(obj.id)
console.log(obj);
}
});
$(".alert").alert();

0 comments on commit e4b3000

Please sign in to comment.