Skip to content
Extraits de code Groupes Projets
Valider 24dc58d9 rédigé par Maxime DESMARCHELIER's avatar Maxime DESMARCHELIER
Parcourir les fichiers

Add software-graph endpoint

Add database method : getNodes / getRelations
parent 0e391188
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -51,3 +51,14 @@ class Neo4j:
# [node._properties.get('name') for node in results.graph().nodes]
else:
return []
def get_relations(self):
with self.driver.session() as session:
results = session.run("MATCH p = (a)-[r]->(b) RETURN a.name as source,b.name as target, r as relation_type")
return results.data()
def get_nodes(self):
with self.driver.session() as session:
results = session.run("MATCH (a) return Id(a) as key, a.name as name")
return results.data()
import json
import os
import random
from fastapi import FastAPI
from pydantic import BaseModel
......@@ -51,6 +52,40 @@ async def software():
return {"softwares": json.loads(json.dumps(results))}
@app.get("/software-graph")
async def software():
nodes = driver.get_nodes()
jnodes = json.loads(json.dumps(nodes))
relations = driver.get_relations()
jrelations = json.loads(json.dumps(relations))
jsondata = {"nodes": jnodes, "edges": jrelations}
def findNodeIdWithName(nodes, name):
for node in nodes:
if node["name"] == name:
return node["key"]
return 0
for idx, relation in enumerate(jsondata["edges"]):
relation['key'] = str(idx)
relation['attributes'] = {}
relation['attributes']['label'] = relation['relation_type'][1]
relation['source'] = findNodeIdWithName(jsondata["nodes"], relation["source"])
relation['target'] = findNodeIdWithName(jsondata["nodes"], relation["target"])
del relation['relation_type']
for node in jsondata["nodes"]:
node['attributes'] = {}
node['attributes']['label'] = node['name']
node['attributes']['x'] = random.random()
node['attributes']['y'] = random.random()
node['attributes']['size'] = 22
del node['name']
return jsondata
@app.post("/software-search")
async def software_search(search: SoftwareSearch):
print(search.software1, search.software2)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter