def gmaps_sites(request): """ Return a json object with node dicts. { nodes: [ { name: '', url: '', lng: 0.0, lat: 0.0 }, ], edges: [] } """ sites = nc.get_nodes_by_type(nc.graphdb.manager, 'Site') site_list = [] for site in sites: try: site = { 'name': site['name'], 'url': helpers.get_node_url(site['handle_id']), 'lng': float(str(site.get('longitude', 0))), 'lat': float(str(site.get('latitude', 0))) } except KeyError: continue site_list.append(site) response = HttpResponse(content_type='application/json') json.dump({'nodes': site_list, 'edges': []}, response) return response
def delete_node(request, slug, handle_id): """ Removes the node and all its relationships. """ redirect_url = '/{}'.format(slug) nh, node = helpers.get_nh_node(handle_id) if nh.node_type.get_label() == 'Unit': part_of = node.get_part_of() if part_of.get('Part_of'): redirect_url = helpers.get_node_url(part_of.get('Part_of')[0]['node'].handle_id) try: # Redirect to parent if deleted node was a child node parent = node.get_parent().get('Has', []) if parent: redirect_url = helpers.get_node_url(parent[0]['node'].handle_id) except AttributeError: pass helpers.delete_node(request.user, node.handle_id) return redirect(redirect_url)
def gmaps_optical_nodes(request): """ Return a json object with dicts of optical node and cables. { nodes: [ { name: '', url: '', lng: 0.0, lat: 0.0 }, ], edges: [ { name: '', url: '', end_points: [{lng: 0.0, lat: 0.0,},] } ] """ # Cypher query to get all cables with cable type fiber that are connected # to two optical node. q = """ MATCH (cable:Cable) WHERE cable.cable_type = "Dark Fiber" MATCH (cable)-[Connected_to]->(port) WITH cable, port MATCH (port)<-[:Has*0..]-(equipment) WHERE (equipment:Optical_Node) AND NOT equipment.type =~ "(?i).*tss.*" WITH cable, port, equipment MATCH p2=(equipment)-[:Located_in]->()<-[:Has*0..]-(loc) WHERE (loc:Site) RETURN cable, equipment, loc """ result = nc.query_to_list(nc.graphdb.manager, q) nodes = {} edges = {} for item in result: node = { 'name': item['equipment']['name'], 'url': helpers.get_node_url(item['equipment']['handle_id']), 'lng': float(str(item['loc'].get('longitude', 0))), 'lat': float(str(item['loc'].get('latitude', 0))) } coords = { 'lng': float(str(item['loc'].get('longitude', 0))), 'lat': float(str(item['loc'].get('latitude', 0))) } edge = { 'name': item['cable']['name'], 'url': helpers.get_node_url(item['cable']['handle_id']), 'end_points': [coords] } nodes[item['equipment']['name']] = node if item['cable']['name'] in edges: edges[item['cable']['name']]['end_points'].append(coords) else: edges[item['cable']['name']] = edge response = HttpResponse(content_type='application/json') json.dump({ 'nodes': list(nodes.values()), 'edges': list(edges.values()) }, response) return response