Skip to content

Instantly share code, notes, and snippets.

@aaryaa
Last active January 20, 2016 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaryaa/9734893798c79f2de70d to your computer and use it in GitHub Desktop.
Save aaryaa/9734893798c79f2de70d to your computer and use it in GitHub Desktop.
"Tracking your home address with the help of your home devices" an application of Internet of Things
= "Tracking your home address with the help of your home devices" an application of Internet of Things
:neo4j-version: 2.3.0
:author: Sujeet Pandey
:twitter: @sujeetpandey1
// I am a IoT enthusiast and also love R. So fro this graphgist challenge i came up with an idea that include use of both R and IoT.So my aim is to track home addresses with the help of the devices connected to it using graph-based search.So i have a Home where all the devices as well as memeber of the home is connected and some devices are registered with some member of the house.So from the unique address of your device this graphgist give all the details about the device,belongs to whom and what is the address of home to which it belongs.
// https://cloud.githubusercontent.com/assets/8536304/12242008/81880648-b8bc-11e5-81f8-645f469b0edb.png
My R script for this graph gist
[source,cypher]
----
library(RNeo4j)
graph=startGraph("http://localhost:7474/db/data")
h1=createNode(graph,"HOME",name="bigboss",address="18th cross,rajivgandhi nagar,bomannahalli,bangalore,India,560068")
h2=createNode(graph,"HOME",name="tim",address="flat no.124,perl of paradise building,bomannahalli,bangalore,India,560068")
h3=createNode(graph,"HOME",name="bijay nivas",address="vill:uparhali,bijoynagar,guwahati,India,781122")
h4=createNode(graph,"HOME",name="bipin bhawan",address="vill:bharoob,daudnagar,patna,India,800001")
h5=createNode(graph,"HOME",name="shanti palace",address="vill:sakurabad,jahanabad,patna,India,800001")
d1=createNode(graph,"DEVICE",name="car",address="BL-A1-1000")
d2=createNode(graph,"DEVICE",name="bike",address="BL-B1-1000")
d3=createNode(graph,"DEVICE",name="bulb",address="BU1")
d4=createNode(graph,"DEVICE",name="bulb",address="BU2")
d5=createNode(graph,"DEVICE",name="bulb",address="BU3")
d6=createNode(graph,"DEVICE",name="air conditioner",address="AC1")
d7=createNode(graph,"DEVICE",name="fan",address="FA1")
d8=createNode(graph,"DEVICE",name="fan",address="FA2")
d9=createNode(graph,"DEVICE",name="tv",address="TV1")
d10=createNode(graph,"DEVICE",name="washing machine",address="WM1")
d11=createNode(graph,"DEVICE",name="bulb",address="BU4")
d12=createNode(graph,"DEVICE",name="bulb",address="BU5")
d13=createNode(graph,"DEVICE",name="bulb",address="BU6")
d14=createNode(graph,"DEVICE",name="fan",address="FA3")
d15=createNode(graph,"DEVICE",name="fan",address="FA4")
d16=createNode(graph,"DEVICE",name="car",address="BL-A2-1000")
d17=createNode(graph,"DEVICE",name="bike",address="BL-B2-1000")
d18=createNode(graph,"DEVICE",name="bulb",address="BU7")
d19=createNode(graph,"DEVICE",name="bulb",address="BU8")
d20=createNode(graph,"DEVICE",name="fan",address="FA5")
d21=createNode(graph,"DEVICE",name="AC",address="AC2")
d22=createNode(graph,"DEVICE",name="freeze",address="FR1")
d23=createNode(graph,"DEVICE",name="tv",address="TV2")
d24=createNode(graph,"DEVICE",name="bulb",address="BU9")
d25=createNode(graph,"DEVICE",name="fan",address="FA6")
d26=createNode(graph,"DEVICE",name="fan",address="FA7")
d27=createNode(graph,"DEVICE",name="tv",address="TV3")
d28=createNode(graph,"DEVICE",name="freeze",address="FR2")
d29=createNode(graph,"DEVICE",name="bike",address="BL-B3-1000")
d30=createNode(graph,"DEVICE",name="car",address="BL-A3-1000")
d31=createNode(graph,"DEVICE",name="bulb",address="BU10")
d32=createNode(graph,"DEVICE",name="bulb",address="BU11")
d33=createNode(graph,"DEVICE",name="bulb",address="BU12")
d34=createNode(graph,"DEVICE",name="freeze",address="FR3")
d35=createNode(graph,"DEVICE",name="fan",address="FA8")
sujeet=createNode(graph,"PERSON",name="sujeet pandey",email="sujeetpandey502@gmail.com",mobile="8792179152")
prashant=createNode(graph,"PERSON",name="prashant kumar",email="theprashantk@gmail.com",mobile="8822704628")
avnish=createNode(graph,"PERSON",name="avnish raj",email="avnish.raj@gmail.com",mobile="8743526189")
jhoni=createNode(graph,"PERSON",name="jhoni nath",email="jhoni.nath@gmail.com",mobile="8792134561")
deepak=createNode(graph,"PERSON",name="deepak kumar",email="deepak.kumar@gmail.com",mobile="8792134560")
rumit=createNode(graph,"PERSON",name="rumit verma",email="rumit.verma@gmail.com",mobile="8792179153")
debu =createNode(graph,"PERSON",name="debprata dey",email="deb.dey@gmail.com",mobile="8822704620")
saurav=createNode(graph,"PERSON",name="saurav kant",email="saurav.kant@gmail.com",mobile="8743526188")
raju=createNode(graph,"PERSON",name="raju yadav",email="raju.yadav@gmail.com",mobile="8792134562")
samim=createNode(graph,"PERSON",name="samim ahmed",email="samim.ahmed@gmail.com",mobile="8792134563")
sumit=createNode(graph,"PERSON",name="sumit pandey",email="sumit.pandey@gmail.com",mobile="8792134564")
bijay=createNode(graph,"PERSON",name="bijay pandey",email="bijay.pandey@gmail.com",mobile="9864273353")
pinki=createNode(graph,"PERSON",name="priyanka pandey",email="pinky@gmail.com",mobile="9706643588")
abhay=createNode(graph,"PERSON",name="abhay kumar",email="abhay@gmail.com",mobile="9706643580")
john=createNode(graph,"PERSON",name="john wills",email="john@gmail.com",mobile="9706643543")
createRel(d1,"Registered_with",sujeet)
createRel(d1,"Device_of",h1)
createRel(sujeet,"Member",h1)
createRel(d2,"Registered_with",avnish )
createRel(d2,"Device_of",h1)
createRel(prashant,"Owner",h1)
createRel(avnish,"Member",h1)
createRel(d3,"Device_of",h1)
createRel(d4,"Device_of",h1)
createRel(d5,"Device_of",h1)
createRel(d6,"Device_of",h1)
createRel(d7,"Device_of",h1)
createRel(d8,"Device_of",h1)
createRel(d9,"Device_of",h1)
createRel(d10,"Device_of",h1)
createRel(jhoni,"Member",h1)
createRel(deepak,"Member",h1)
createRel(deepak,"Friend",sujeet)
createRel(sujeet,"Friend",prashant)
createRel(prashant,"Friend",jhoni)
createRel(jhoni,"Friend",avnish)
createRel(avnish,"Friend",deepak)
createRel(debu,"Owner",h2)
createRel(rumit,"Member",h2)
createRel(saurav,"Member",h2)
createRel(raju,"Member",h2)
createRel(samim,"Member",h2)
createRel(rumit,"Friend",debu)
createRel(debu,"Friend",saurav)
createRel(saurav,"Friend",raju)
createRel(raju ,"Friend",samim)
createRel(samim,"Friend",rumit)
createRel(d11,"Device_of",h2)
createRel(d12,"Device_of",h2)
createRel(d13,"Device_of",h2)
createRel(d14,"Device_of",h2)
createRel(d15,"Device_of",h2)
createRel(bijay,"Owner",h3)
createRel(sumit,"Member",h3)
createRel(pinki,"Member",h3)
createRel(d16,"Registered_with",bijay)
createRel(d17,"Registered_with",sumit)
createRel(d16,"Device_of",h3)
createRel(d17,"Device_of",h3)
createRel(d18,"Device_of",h3)
createRel(d19,"Device_of",h3)
createRel(d20,"Device_of",h3)
createRel(d21,"Device_of",h3)
createRel(d22,"Device_of",h3)
createRel(d23,"Device_of",h3)
createRel(abhay,"Owner",h4)
createRel(d24,"Device_of",h4)
createRel(d25,"Device_of",h4)
createRel(d26,"Device_of",h4)
createRel(d27,"Device_of",h4)
createRel(d28,"Device_of",h4)
createRel(d29,"Device_of",h4)
createRel(john,"Owner",h5)
createRel(d30,"Registered_with",john)
createRel(d30,"Device_of",h5)
createRel(d31,"Device_of",h5)
createRel(d32,"Device_of",h5)
createRel(d33,"Device_of",h5)
createRel(d34,"Device_of",h5)
createRel(d35,"Device_of",h5)
browse(graph)
----
// Gives the total count of nodes which have a device_of relationship
[source,cypher]
----
match (n)-[r:Device_of]-() return n,count(n);
----
// To know the name of the owner of a device by device address
[source,cypher]
----
match(c:DEVICE{address:'BL-A1-1000'})-[:Registered_with]->(r:PERSON) return c.name as device,r.name as person ,r.mobile as mobile
----
//To know the name and address of the person that is owner of the device
[source,cypher]
----
match(c:DEVICE{address:'BL-A1-1000'})-[:Registered_with]->(r:PERSON)-[:Member]->(s:HOME) return r.name as person,r.mobile as mobile,r.email as email, s.name as home,s.address as address
----
//To know the memebr of home
[source,cypher]
----
match(f:PERSON)-[:Owner|Member]->(e:HOME{name:'bigboss'}) return f.name as person,f.mobile as mobile,f.email as email,e.name as home,e.address as address
----
//to know total number of devices conected to a home with all details
[source,cypher]
----
match(f:DEVICE)-[:Device_of]->(e:HOME{name:'bigboss'}) return f.name as device,f.address as address,e.name as home,e.address as homeaddress
----
//to know the total number of device in a home
[source,cypher]
----
match(f:DEVICE)-[:Device_of]->(e:HOME{name:'bigboss'}) return count(f)
----
//to know the adress of home to which device belongs:
[source,cypher]
----
match(f:DEVICE{address:'BU8'})-[:Device_of]->(e:HOME) return e.name as home,e.address as address
----
@aaryaa
Copy link
Author

aaryaa commented Jan 11, 2016

graphgist

snapshot of the graphgist model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment