Example #1
0
    # Then customise based on the config file.
    try:
        config.load_file(options.config, working_dir)
    except ConfigError, e:
        print "Configuration error:", e.msg
        sys.exit()

    # Finally, customise based on command line arguments
    if options.port:
        config.lat_server_port = options.port
    if options.hostname:
        config.lat_server_hostname = options.hostname
            
    # Try to load the LAT backend server.
    try:
        lat_server = LatServer(config.lat_server_hostname, config.lat_server_port)
        lat_server.connect()
    except:
        sys.exit("Error connecting to LAT backend server at %s:%d" % (config.lat_server_hostname, config.lat_server_port))

    # Load the experiment database
    experiment_filename = os.path.join(working_dir, options.experiment)
    experiment = load_experiment(experiment_filename)
    if experiment == None:
        sys.exit("Error loading experiment: %s" % experiment_filename)

    if options.experiment_id:
        replay_experiment(experiment, options.experiment_id, lat_server, options.tag_offset)
    else:
        list_location_module_ids(experiment)
    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()
    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):
        
Example #3
0
        

if __name__ == "__main__":
    
    ##############################
    # Command line options.
    ##############################
   
    usage = "usage: %prog [options] database1 database2..."
    parser = OptionParser(usage=usage)
    parser.add_option("-c", "--combined", dest="combined", default="combined.db",
                      help="The sqlite database file for the combined database.", metavar="FILE")

    options, args = parser.parse_args()

    try:
        combined = new_experiment(options.combined)
    except Exception, e:
        sys.exit("Error loading combined database: %s" % str(e))
    
    existing = []
    for filename in args:
        database = load_experiment(filename)
        if database:
            existing.append(database)
        else:
            logging.error("Error loading database: %s" % filename)
            
    
    combine(combined, existing)