Skip to content

Commit

Permalink
adding neovigator
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jan 10, 2012
1 parent 6de7d6d commit 28f404d
Show file tree
Hide file tree
Showing 28 changed files with 7,439 additions and 8 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source 'http://rubygems.org'
gem 'sinatra'
gem 'neography'
gem 'haml'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ GEM
remote: http://rubygems.org/
specs:
crack (0.1.8)
haml (3.1.4)
httparty (0.7.8)
crack (= 0.1.8)
json (1.6.4)
Expand All @@ -27,5 +28,6 @@ PLATFORMS
ruby

DEPENDENCIES
haml
neography
sinatra
85 changes: 77 additions & 8 deletions neoflix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,82 @@ def ratedEdge = g.addEdge(g.idx(Tokens.T.v)[[userId:components[0].toInteger()]].
create_graph(neo)
end

# Begin Neovigator

def link_to(url, text=url, opts={})
attributes = ""
opts.each { |key,value| attributes << key.to_s << "=\"" << value << "\" "}
"<a href=\"#{url}\" #{attributes}>#{text}</a>"
end

def neighbours
{"order" => "depth first",
"uniqueness" => "none",
"return filter" => {"language" => "builtin", "name" => "all_but_start_node"},
"depth" => 1}
end

def node_id(node)
case node
when Hash
node["self"].split('/').last
when String
node.split('/').last
else
node
end
end

def get_properties(node)
properties = "<ul>"
node["data"].each_pair do |key, value|
properties << "<li><b>#{key}:</b> #{value}</li>"
end
properties + "</ul>"
end

get '/resources/show' do
content_type :json

node = neo.get_node(params[:id])
connections = neo.traverse(node, "fullpath", neighbours)
incoming = Hash.new{|h, k| h[k] = []}
outgoing = Hash.new{|h, k| h[k] = []}
nodes = Hash.new
attributes = Array.new

connections.each do |c|
c["nodes"].each do |n|
nodes[n["self"]] = n["data"]
end
rel = c["relationships"][0]

if rel["end"] == node["self"]
incoming["Incoming:#{rel["type"]}"] << {:values => nodes[rel["start"]].merge({:id => node_id(rel["start"]) }) }
else
outgoing["Outgoing:#{rel["type"]}"] << {:values => nodes[rel["end"]].merge({:id => node_id(rel["end"]) }) }
end
end

incoming.merge(outgoing).each_pair do |key, value|
attributes << {:id => key.split(':').last, :name => key, :values => value.collect{|v| v[:values]} }
end

attributes = [{"name" => "No Relationships","name" => "No Relationships","values" => [{"id" => "#{params[:id]}","name" => "No Relationships "}]}] if attributes.empty?

@node = {:details_html => "<h2>Neo ID: #{node_id(node)}</h2>\n<p class='summary'>\n#{get_properties(node)}</p>\n",
:data => {:attributes => attributes,
:name => node["data"]["name"],
:id => node_id(node)}
}

@node.to_json

end

# End Neovigator

get '/' do
puts "Indices: " + neo.execute_script("g.indices;").to_s + " should be [""AUTOMATIC[vertices:Vertex][autoIndexKeys:null]""]"
puts "Vertices: " + neo.execute_script("g.V.count();").to_s + " should be 9962"
puts "Edges: " + neo.execute_script("g.E.count();").to_s + " should be 1012657"
puts "Movies: " + neo.execute_script("g.idx('vertices')[[type:'Movie']].count();").to_s + " should be 3883"
puts "Genera: " + neo.execute_script("g.idx('vertices')[[type:'Genera']].count();").to_s + " should be 18"
puts "Users: " + neo.execute_script("g.idx('vertices')[[type:'User']].count();").to_s + " should be 6040"
puts "Occupations: " + neo.execute_script("g.idx('vertices')[[type:'Occupation']].count();").to_s + " should be 21"
puts "Genera: " + neo.execute_script("g.idx('vertices')[[type:'Genera']].map();").to_s + " should be 18"
@neoid = params["neoid"]
haml :index
end
241 changes: 241 additions & 0 deletions public/css/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
@font-face {
font-family: "GraublauWeb";
src: url(/fonts/GraublauWeb.otf) format("truetype");
}
@font-face {
font-family: "GraublauWeb";
font-weight: bold;
src: url(/fonts/GraublauWebBold.otf) format("truetype");
}

header, section, nav { display:block; }

.left {
float: left;
}

.right {
float: right;
}

a {
color: #000;
text-decoration: none;
}

a:hover {
color: #000;
/*border-bottom: 2px solid #000;*/
}

header {
margin: 0;
padding: 5px;
position: absolute;
top: 5px;
left: 0px;
right: 0px;
}

header section#title {
float: left;
margin-top: 5px;
}

header section#title p {
margin: 0;
padding: 0;
margin-left: 10px;
font-family: GraublauWeb, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size:12px;
line-height:1.4;
}

header section#search {
float: right;
padding: 12px;
margin-right: 0px;
}

html {
overflow-x: hidden;
}

html,body {
margin:0px;
padding:0px;
color: #555;

font-family: GraublauWeb, "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size-adjust:none;
font-stretch:normal;
font-style:normal;
font-variant:normal;
font-weight:normal;
line-height:normal;
background: #eaefe0;
}



xs {
color: #a68d49;
}

body {
padding:5px;
}

header h1 {
font-family: GraublauWeb, "Helvetica Neue", Helvetica, Arial, sans-serif;
width: 200px;
color: black;
font-weight: bold;
margin: 0px;
font-size:30px;
padding: 0px;
margin-left: 10px;
}

h2 {
font-size: 19px;
color: #000;
border-bottom: 1px solid #000;
}

h3 {
font-size: 15px;
color: #000;
border-bottom: 1px solid #000;
}

section#content {
display: none;
position: absolute;
top: 200px;
bottom: 200px;
left: 0px;
right: 0px;
margin-top: 5px;
margin: auto;
width: 400px;
}

aside {
font-size: 12px;
position: absolute;
right: 17px;
top: 80px;
bottom: 50px;
width: 290px;
padding: 10px;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border: 1px solid #c1c1c1;
line-height: 1.5em;
background: #fff;
opacity: 0.9;
overflow: auto;
}

p.summary img {
float: left;
margin-right: 5px;
margin-bottom: 5px;
}

ul.links {
list-style: none;
margin: 0;
padding: 0;
border: none;
}

ul.links li {
margin: 0;
margin-bottom: 3px;
}

ul.links li:hover {
margin-bottom: 2px;
border-bottom: 1px solid #000;
}

ul.links li a {
width: auto;
}

section#infovis {
display: none;
height:550px;
overflow: hidden;
background-color:#F4F4F4;
}

.hidden {
display:none;
}

#browser_not_supported {
font-family: GraublauWeb, "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: auto;
line-height: 2em;
font-size: 15px;
display: none;
}

/* Clearing */
.clearfix:after, #frame:after, .navigation:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
.clearfix, #frame, .navigation {display: inline-block;}
* html .clearfix, * html #frame, * html .navigation {height: 1%;}
.clearfix, #frame, .navigation {display: block;}
.clear {clear: both;}


/*
-----------------------------------------
Search Box
-----------------------------------------
*/

#neo-suggest {
border: 1px solid #c1c1c1;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
opacity: 0.9;
border-radius: 5px;
padding: 5px;
width: 300px;
font-family: GraublauWeb, "Helvetica Neue", Helvetica, Arial, sans-serif;
text-align: right;
font-size: 13px;
color: #555;
}

#search .ghost-input {
color: #99a;
}

#search .focused {
color: #878699;
font-style: normal;
}

.neo-reset a {
text-decoration: none;
border: 0;
}

.neo-reset a:hover {
text-decoration: none;
border: 0;
}


Binary file added public/favicon.ico
Binary file not shown.
Loading

0 comments on commit 28f404d

Please sign in to comment.