Exemplo n.º 1
0
 def costs(self, v):
     to_db_add = []
     # Get the query obj
     session = Session()
     q = session.query(Costs)
     # Need the new instance here to avoid __setattr__ issues
     df = pd.DataFrame(v)
     for idx, row in df.iterrows():
         # Now invert the expanded dict back into a single JSONB column for storage
         res = q.filter(Costs.match_id == idx).first()
         if res:
             #update the JSON blob
             costs_new_or_updated = row.to_dict()
             for k, v in costs_new_or_updated.items():
                 if v is None:
                     continue
                 elif np.isnan(v):
                     v = None
                 res._cost[k] = v
             sqlalchemy.orm.attributes.flag_modified(res, '_cost')
             session.add(res)
             session.commit()
         else:
             row = row.to_dict()
             costs = row.pop('_costs', {})
             for k, v in row.items():
                 if np.isnan(v):
                     v = None
                 costs[k] = v
             cost = Costs(match_id=idx, _cost=costs)
             to_db_add.append(cost)
     if to_db_add:
         session.bulk_save_objects(to_db_add)
     session.commit()
Exemplo n.º 2
0
 def fundamental_matrix(self, v):
     session = Session()
     res = session.query(table_obj).\
            filter(table_obj.source == self.source['node_id']).\
            filter(table_obj.destination == self.destination['node_id']).first()
     if res:
         res.fundamental = v
     else:
         edge = Edges(source=self.source['node_id'],
                      destination=self.destination['node_id'],
                      fundamental = v)
         session.add(edge)
         session.commit()
Exemplo n.º 3
0
 def ring(self, ring):
     # Setters need a single session and so should not make use of the
     # syntax sugar _from_db
     session = Session()
     res = session.query(Edges).\
            filter(Edges.source == self.source['node_id']).\
            filter(Edges.destination == self.destination['node_id']).first()
     if res:
         res.ring = ring
     else:
         edge = Edges(source=self.source['node_id'],
                      destination=self.destination['node_id'],
                      ring=ring)
         session.add(edge)
         session.commit()
     return
Exemplo n.º 4
0
    def __init__(self, *args, parent=None, **kwargs):
        # If this is the first time that the image is seen, add it to the DB
        if parent is None:
            self.parent = Parent(config)
        else:
            self.parent = parent

        # Create a session to work in
        session = Session()
        # For now, just use the PATH to determine if the node/image is in the DB
        res = session.query(Images).filter(
            Images.path == kwargs['image_path']).first()
        exists = False
        if res:
            exists = True
            kwargs['node_id'] = res.id
        session.close()
        super(NetworkNode, self).__init__(*args, **kwargs)

        if exists is False:
            # Create the camera entry
            try:
                self._camera = create_camera(self.geodata)
                serialized_camera = self._camera.getModelState()
                cam = Cameras(camera=serialized_camera)
            except:
                cam = None
            kpspath = io_keypoints.create_output_path(self.geodata.file_name)

            # Create the keypoints entry
            kps = Keypoints(path=kpspath, nkeypoints=0)
            # Create the image
            i = Images(name=kwargs['image_name'],
                       path=kwargs['image_path'],
                       footprint_latlon=self.footprint,
                       cameras=cam,
                       keypoints=kps)
            session = Session()
            session.add(i)
            session.commit()
            session.close()
        self.job_status = defaultdict(dict)
Exemplo n.º 5
0
    def masks(self, v):
        def dict_check(input):
            for k, v in input.items():
                if isinstance(v, dict):
                    dict_check(v)
                elif v is None:
                    continue
                elif np.isnan(v):
                    input[k] = None

        df = pd.DataFrame(v)
        session = Session()
        res = session.query(Edges).\
                                filter(Edges.source == self.source['node_id']).\
                                filter(Edges.destination == self.destination['node_id']).first()
        if res:
            as_dict = df.to_dict()
            dict_check(as_dict)
            # Update the masks
            res.masks = as_dict
            session.add(res)
            session.commit()