I have the following code where I am migrating a relational database to neo4j. I made a node for each latitude and longitude sensor and a distinct node for every rainfall recorded in my database.
db = GraphDatabase("http://localhost:7474",username="neo4j", password="12345")
conn = psycopg2.connect("\
dbname='bdTrmmTest'\
user='postgres'\
host='127.0.0.1'\
password='1234'\
");
c = conn.cursor()
c.execute("SELECT latitude, longitude, gid FROM pontos")
records = c.fetchall() #pega todos os resultados do select e armazena em uma tupla
#cria todos os sensores os latitude e longitute
sensorlatlong = db.labels.create("Latitude/Longitude")
for i in records:
s = db.nodes.create(latitude=i[0],longitutde=i[1])
sensorlatlong.add(s)
#cria os nos de precipitacao
e.execute("SELECT precipitacaoh, gidgeo_fk FROM historico GROUP BY precipitacaoh")
records2 = e.fetchall()
sensorprecip = db.labels.create("Precipitacao")
for i in records:
s2 = db.nodes.create(precipitacao=i[0])
sensorprecip.add(s2)
#cria as relacoes entre precipitacao e sensor latitude e longitude
Now I want every latitude and longitude sensor that marked any of these precipitations, have a MARCOU relationship with every precipitation node that it has marked.
I'm thinking of making a loop like:
#cria as relacoes entre precipitacao e sensor latitude e longitude
for i in records:
for j in records2:
if(i[2] == j[1]):
s.relationships.create("MARCOU",s2)
But I do not know if it's right, and the database is too big. Any suggestion?