コード例 #1
0
ファイル: conduits.py プロジェクト: fossabot/noc
 def get_data(self, request, object):
     ducts = []
     # Get spatial object
     try:
         gd = GeoData.objects.get(object=str(object.id))
     except GeoData.DoesNotExist:
         gd = None
     # Get all conduits
     conduits = defaultdict(list)
     for c, remote, _ in object.get_genderless_connections("conduits"):
         conduit, _ = c.p2p_get_other(object)
         for cc, t, _ in conduit.get_genderless_connections("conduits"):
             if t != object:
                 conduits[t] += [{
                     "id": str(conduit.id),
                     "n": int(conduit.name),
                     "x": cc.data["plan"]["x"],
                     "y": cc.data["plan"]["y"],
                     "d": 100,  # remote.data.get("...."),
                     "status": True  # remote.data....
                 }]
     # Get neighbor ducts
     for c, remote, _ in object.get_genderless_connections("ducts"):
         map_distance = None
         br = None
         sbr = None
         if gd:
             try:
                 rgd = GeoData.objects.get(object=str(remote.id))
                 map_distance = distance(gd.data, rgd.data)
                 br = bearing(gd.data, rgd.data)
                 sbr = bearing_sym(gd.data, rgd.data)
             except GeoData.DoesNotExist:
                 pass
         cd = conduits[remote]
         ducts += [{
             "connection_id": str(c.id),
             "target_id": str(remote.id),
             "target_name": remote.name,
             "target_model_name": remote.model.name,
             "map_distance": map_distance,
             "project_distance": c.data.get("project_distance"),
             "n_conduits": len(cd),
             "conduits": cd,
             "bearing": br,
             "s_bearing": sbr
         }]
     return {"id": str(object.id), "name": object.name, "ducts": ducts}
コード例 #2
0
ファイル: conduits.py プロジェクト: skripkar/noc
 def get_data(self, request, object):
     ducts = []
     # Get all conduits
     conduits = defaultdict(list)
     for c, remote, _ in object.get_genderless_connections("conduits"):
         conduit, _ = c.p2p_get_other(object)
         for cc, t, _ in conduit.get_genderless_connections("conduits"):
             if t != object:
                 conduits[t] += [{
                     "id": str(conduit.id),
                     "n": int(conduit.name),
                     "x": cc.data["plan"]["x"],
                     "y": cc.data["plan"]["y"],
                     "d": 100,  # remote.data.get("...."),
                     "status": True  # remote.data....
                 }]
     # Get neighbor ducts
     for c, remote, _ in object.get_genderless_connections("ducts"):
         map_distance = None
         br = None
         sbr = None
         if object.point and remote.point:
             map_distance = distance(object.point, remote.point)
             br = bearing(object.point, remote.point)
             sbr = bearing_sym(object.data, remote.data)
         cd = conduits[remote]
         ducts += [{
             "connection_id": str(c.id),
             "target_id": str(remote.id),
             "target_name": remote.name,
             "target_model_name": remote.model.name,
             "map_distance": map_distance,
             "project_distance": c.data.get("project_distance"),
             "n_conduits": len(cd),
             "conduits": cd,
             "bearing": br,
             "s_bearing": sbr
         }]
     return {
         "id": str(object.id),
         "name": object.name,
         "ducts": ducts
     }
コード例 #3
0
ファイル: conduits.py プロジェクト: fossabot/noc
 def api_get_neighbors(self, request, id):
     o = self.app.get_object_or_404(Object, id=id)
     try:
         og = GeoData.objects.get(object=str(o.id))
     except GeoData.DoesNotExist:
         return []
     layers = map.get_conduits_layers()
     connected = set(
         str(ro.id) for _, ro, _ in o.get_genderless_connections("ducts"))
     if self.is_single_connection(o) and connected:
         # Connection limits exceed
         return []
     r = []
     for g in GeoData.objects.filter(
             layer__in=layers,
             data__distance_lte=(og.data, D(
                 m=self.MAX_CONDUIT_LENGTH))).exclude(object=id).distance(
                     og.data).order_by("distance"):
         # Check object has no connection with this one
         if g.object in connected:
             continue
         ro = Object.objects.filter(id=g.object).first()
         if not ro:
             continue
         # Exclude already connected cable entries
         if (self.is_single_connection(ro)
                 and len(ro.get_genderless_connections("ducts"))):
             continue
         # Feed data
         d = distance(og.data, g.data)
         sbr = bearing_sym(og.data, g.data)
         r += [{
             "id": str(g.object),
             "label": "%s (%s, %dm)" % (ro.name, sbr, d),
             "s_bearing": sbr,
             "map_distance": d,
             "name": ro.name
         }]
     return r
コード例 #4
0
 def api_get_neighbors(self, request, id):
     o = self.app.get_object_or_404(Object, id=id)
     if not o.point:
         return []
     layers = list(map.get_conduits_layers())
     connected = set(
         str(ro.id) for _, ro, _ in o.get_genderless_connections("ducts"))
     if self.is_single_connection(o) and connected:
         # Connection limits exceed
         return []
     r = []
     for ro in Object.objects.filter(
             id__ne=id,
             layer__in=layers,
             point__near=o.point,
             point__max_distance=self.MAX_CONDUIT_LENGTH,
     ):
         #  )).distance(o.point).order_by("distance"):
         # Check object has no connection with this one
         if ro in connected:
             continue
         # Exclude already connected cable entries
         if self.is_single_connection(ro) and len(
                 ro.get_genderless_connections("ducts")):
             continue
         # Feed data
         d = distance(o.point, ro.point)
         sbr = bearing_sym(o.point, ro.point)
         r += [{
             "id": str(ro.id),
             "label": "%s (%s, %dm)" % (ro.name, sbr, d),
             "s_bearing": sbr,
             "map_distance": d,
             "name": ro.name,
         }]
     return r