Example #1
0
 def put(self, node_id):        
     node = None
     nodes = Node.query.all()    # @UndefinedVariable
     for x in nodes:
         if x.rid == node_id:
             node = x
     if node:
         args = self.reqparse.parse_args()
         lat = args['lat']
         lon = args['lon']
         for goal in node.goals:
             if str(goal.location.lat) == str(lat) and str(goal.location.lon) == str(lon):
                 db.session.delete(goal)
                 db.session.commit()
                 publish_events(reqType="goalComplete", rid=node_id)
                 break
         
         return {
                 'result': {
                            'node': node.name,
                            'nid': node.id,
                            'id': node.rid,                                
                            'msg': 'Goal Successfully Removed' 
                            }
                 }
Example #2
0
 def put(self):
     args = self.reqparse.parse_args()        
     node = None
     nodes = Node.query.all()    # @UndefinedVariable
     node_id = args['rid']
     for x in nodes:
         if x.rid == node_id:
             node = x
     if node:
             return {
                 'result': {
                            'nid': node.id,
                            'id': node.rid,                                
                            'msg': 'Robot with that id already exists!' 
                            }
                 }
     else:
         new_ip = args['ip']
         new_lat = args['lat']
         new_lon = args['lon']
         new_leader_rid = args['leader']
         new_name = args['name']
         new_leader = 0
         if new_leader_rid != 0:
             for x in nodes:
                 if x.id == new_leader_rid:
                     new_leader = x.id
         
         
         #new node has passed validation, add to db
         location = Location(lat=new_lat, lon=new_lon)
         db.session.add(location)  # @UndefinedVariable
         node = Node(name=new_name, leader_id=new_leader, location=location, rid=node_id, ip=new_ip)
         db.session.add(node)  # @UndefinedVariable
         db.session.commit()  # @UndefinedVariable
         publish_events(reqType="newNode", rid=node_id)
          
         return {
                 'result': {
                            'node': node.name,
                            'nid': node.id,
                            'id': node.rid,                                
                            'msg': 'Node Added' 
                            }
                 }
Example #3
0
    def put(self, node_id):        
        node = None
        nodes = Node.query.all()    # @UndefinedVariable
        for x in nodes:
            if x.id == node_id:
                node = x
        if node:
            args = self.reqparse.parse_args()
            data = args['jps']
            #print "JumpPoints: " + data
            jp_data = json.loads(data)
            
            node_jumppoints = node.jumppoints
            
            for node_jp in node.jumppoints:
                db.session.delete(node_jp)
                
            for jp in jp_data:
                
                new_jp = JumpPoint()

                lat = float(jp['lat'])
                lon = float(jp['lng'])
                location = Location(lat=lat, lon=lon)
                db.session.add(location)  # @UndefinedVariable
                
                new_jp.location = location
                new_jp.position = len(node.jumppoints) + 1
                        
                node.jumppoints.append(new_jp)
            db.session.commit()
            publish_events(reqType="nodeJumpPoints", rid=node_id)
            return {
                    'result': {
                               'node': node.name,
                               'nid': node.id,
                               'id': node.rid, 
                               'msg': 'Test' 
                               }
                    }
Example #4
0
 def put(self, node_id):        
     node = None
     nodes = Node.query.all()    # @UndefinedVariable
     for x in nodes:
         if x.rid == node_id:
             node = x
     if node:
         args = self.reqparse.parse_args()
         lat = args['lat']
         lon = args['lon']
         speed = args['speed']
         dir = args['dir']
         #print "Location: lat=" + str(lat) + " lon=" + str(lon)
         #if speed is not None:
         #    print "   - speed= " + str(speed)
         #if dir is not None:
         #    print "   - dir= " + str(dir)
         
                   
         node.location.lat = float(lat)
         node.location.lon = float(lon)
         if speed is not None:
             node.location.speed = float(speed)
         if dir is not None:    
             node.location.dir = float(dir)
         db.session.commit()
         publish_events(reqType="nodeLocation", rid=node_id)
         
         return {
                 'result': {
                            'node': node.name,
                            'nid': node.id,
                            'id': node.rid,
                            'lat': node.location.lat, 
                            'lon': node.location.lon, 
                            'msg': 'New location correctly set' 
                            }
                 }
Example #5
0
 def put(self):            
     args = self.reqparse.parse_args()
     data = args['obstacles']
     ob_data = json.loads(data)
     print "Obstacles" + data
     newObCount = 0
     for ob in ob_data:  
                               
         lat = float(ob['lat'])
         lon = float(ob['lon'])
         obExists = False
         existingLocation = Location.query.filter_by(lat=lat,lon=lon).first() # @UndefinedVariable
         if existingLocation is not None:
             # something is already at this location. see if it is an obstacle
             existingObstacle = Obstacle.query.filter_by(loc_id=existingLocation.id).first() # @UndefinedVariable
             if existingObstacle is not None:
                 obExists = True
         
         # create new obstacle only if one doesn't already exist
         if not obExists:
             newOb = Obstacle()
             newLocation = Location(lat=lat, lon=lon)
             db.session.add(newLocation)  # @UndefinedVariable
             db.session.commit()
             newOb.location = newLocation
             db.session.add(newOb)  # @UndefinedVariable
             newObCount = newObCount + 1
             publish_events(reqType="newObstacle", lat=lat, lon=lon)
             
     db.session.commit()
                 
     return {
             'result': {                           
                        'msg': str(newObCount) + " obstacles created." 
                        }
             }