コード例 #1
0
def spawnLocation(location, meters=60):
    """Creates a new location within random meters of provided location.
    Returns: a new location.
    """   
    _trace=TRACE+"spawnLocation() "
    logging.info(_trace)
    lat, lon = utils.parseGeoPt(location)
    logging.info(_trace+'lat = '+lat)
    logging.info(_trace+'lon = '+lon)
    
    # Randomly determine distance of new lat/lon
    ran_lat_meters = utils.roll(meters, 1)
    ran_lon_meters = utils.roll(meters, 1)
    logging.info(_trace+'ran_lat_meters = '+str(ran_lat_meters))
    logging.info(_trace+'ran_lon_meters = '+str(ran_lon_meters))
        
    lat_meters = ran_lat_meters*.00001
    lon_meters = ran_lon_meters*.00001
    logging.info(_trace+'lat_meters = '+str(lat_meters))
    logging.info(_trace+'lon_meters = '+str(lon_meters))

    # Randomly determine direction of new lat/lon
    pos_lat_vector = random.choice([True, False])
    pos_lon_vector = random.choice([True, False])
    logging.info(_trace+'pos_lat_vector = '+str(pos_lat_vector))
    logging.info(_trace+'pos_lon_vector = '+str(pos_lon_vector))
        
    lat = utils.strToIntOrFloat(lat)
    lon = utils.strToIntOrFloat(lon)
    new_lat = lat
    new_lon = lon
    if pos_lat_vector == False:
        new_lat = lat - lat_meters  
        logging.info(_trace+'False new_lat = '+str(new_lat))
    
    else:
        new_lat = lat + lat_meters              
        logging.info(_trace+'True new_lat = '+str(new_lat))
        
    if pos_lon_vector == False:
        new_lon = lon - lon_meters
        logging.info(_trace+'False new_lon = '+str(new_lon))    
    
    else:
        new_lon = lon + lon_meters
        logging.info(_trace+'True new_lon = '+str(new_lon))
                        
    new_location = db.GeoPt(str(new_lat), str(new_lon))
    return new_location
コード例 #2
0
 def post(self):  
     _trace = TRACE+'CharacterHandler.post() '
     logging.info(_trace)
     user = users.get_current_user()
     key = self.request.get('template')
     name = self.request.get('name')
     template = db.get(key)
     if template is not None:
         _player = character.createPlayerFromTemplate(template, name, user)
         lat = self.request.get('lat')
         lon = self.request.get('lon')
         location = db.GeoPt(utils.strToIntOrFloat(lat), 
                             utils.strToIntOrFloat(lon))
         
         _party = party.createJSONParty(_player, location)            
         
     self.redirect('/mobile/character/'+str(_player.key()))