Пример #1
0
    def on_message(self,message):    
        print 'server received:', message

        # get name of floorplan and send back wall candidates
        if message.startswith('act_pos#'):
            lat,lon = message.split('#')[1].split('$')
            lat,lon = float(lat), float(lon)
            ### FAKY FAKY
            #lat,lon = ( 52.480658, 13.465260 )
            client_connections[self.id].act_pos = (lat,lon)
            print 'new act_pos', client_connections[self.id].act_pos

        if message.startswith('dst_pos#'):
            lat,lon = message.split('#')[1].split('$')
            lat,lon = float(lat), float(lon)
            client_connections[self.id].dst_pos = (lat,lon)
            print 'dst lat',lat,'lon',lon
    
            _number_of_bikes,_radius = 10, 0.5
            list_of_jobs = Interface.get_closest_bikes(db_connection, client_connections[self.id].act_pos[0],client_connections[self.id].act_pos[1],lat,lon, number_of_bikes = _number_of_bikes, radius = _radius)
            print 'list len',len(list_of_jobs)
            print 'act',client_connections[self.id].act_pos
            for _job in list_of_jobs:
                # possible _job.value, _job.position, _job.target
                client_connections[self.id].ws.write_message('bike_pos#'+str(_job.position.latitude)+'$'+str(_job.position.longitude)+'$'+str(_job.value))
                print 'bike_pos', client_connections[self.id].act_pos, 'dst_pos', client_connections[self.id].dst_pos, 'job to do',_job
                _job.print_job()