Exemplo n.º 1
0
 def  __init__(self, observation_database="observations.db", error_bound=1.0):
     """        
     """
     
     if not os.path.exists(observation_database):
         raise Exception("Observation file doesn't exist: %s" % observation_database)
     
     self.error_bound = error_bound
     self.observations = CanonicalObservationDatabase(observation_database)
Exemplo n.º 2
0
class LocationEngineMatch(object):
    """
    """
        
    def  __init__(self, observation_database="observations.db", error_bound=1.0):
        """        
        """
        
        if not os.path.exists(observation_database):
            raise Exception("Observation file doesn't exist: %s" % observation_database)
        
        self.error_bound = error_bound
        self.observations = CanonicalObservationDatabase(observation_database)
        

    def coordinates(self, distances):
        """
        """
        
        possible_matches = self.observations.possible_locations(distances, self.error_bound)
        
        if not possible_matches:
            return 0.0, 0.0
        
        sum_x, sum_y = 0.0, 0.0
        for x, y in possible_matches:
            sum_x += x
            sum_y += y
        
        n = len(possible_matches)
        
        x = sum_x / n
        y = sum_y / n
        
        logging.debug("Found centroid of % d possible matches: (%.2f, %.2f)" % (n, x, y))
        
        return x, y
Exemplo n.º 3
0
    else:
        log_file = None
    logging.basicConfig(filename=log_file, level=options.log_level,
                        format='%(asctime)s %(levelname)s %(message)s',
                        filemode='w')

    config = Config()
    if os.path.exists(options.config):
        config.load_file(options.config)

    experiment = load_experiment(options.experiment)
    grid_size = 0.25

    if os.path.exists(options.observation_database):
        sys.exit("Observation database (%s) already exists" % options.observation_database)
    observations = CanonicalObservationDatabase(options.observation_database)
    observations.populate_observation_grid(config.min_x, config.max_x, config.min_y, config.max_y, grid_size)

    
    for anchor_id, (x, y) in config.anchors.items():
        observations.add_anchor(anchor_id, x, y)
          
    count = 0
    sql = "SELECT anchor_id, tag_id, distance, timestamp FROM distance_reading ORDER BY timestamp"
    for anchor_id, tag_id, distance, timestamp in experiment.query(sql):
        
        # Find a nearby observation (there should be exactly one, or four equidistant)
        try:
            x, y = experiment.ground_truth(tag_id, timestamp)
        except:
            logging.debug("Skipping observation without ground truth.")
Exemplo n.º 4
0
    options, args = option_parser.parse_args()
        
    # Start logging.
    if options.log_file:
        log_file = os.path.join(working_dir, options.log_file)
    else:
        log_file = None
    logging.basicConfig(filename=log_file, level=options.log_level,
                        format='%(asctime)s %(levelname)s %(message)s',
                        filemode='w')

    config = Config()
    backend_api = config.load_rtls()
    arena_id = 1
    
    observations = CanonicalObservationDatabase(options.observation_database)
    
    distances_by_anchor_observation = {}
    
    # Keep some arrays, in arbitrary (but identical) order
    d  = [] # ground truth distance
    m  = [] # median observed distance
    D  = [] # distance arrays
    er = [] # errors (m - d)
    a  = [] # anchor IDs
    l  = [] # observation locations
    
    images = {}
    
    anchors = observations.anchors()
    for anchor_id, (ax, ay) in anchors.items():