cityspeed - Main Driver, Data Collection

Calculates statistics on the driving travel time of cities.

When run as a script, will save statistics for all cities listed in settings.py to the data directory listed in settings.py (../data/ by default) in .json format. To use another settings file, pass it as the first command line argument:

python cityspeed.py /path/to/settings.py

You will need to edit settings.py to provide a Google Maps API Key and Referrer URL.

cityspeed(cities, api_key, referrer_url, from_query='elementary school', to_query='Starbucks', numpoints=32, data_dir='../data', sleep_secs=6.0, callback=<function print_callback at 0x31decf8>)

Orchestrates the process retrieving data about cities, computing and writing out statistics.

Implements some checkpoint-restart facilities for doing long runs. Basically, for each city:

  1. Get the “to” points from a file, else query map service
  2. Get the “from points from a file, else query map service
  3. Get the routes from all “from” points to all “to” points from a file, else query map service
  4. Compute statistics and save to a files in data directory.
Parameters:
  • cities (list of strings) – Cities for which to compute statistics
  • api_key (string) – Google Maps API key.
  • referrer_url (string) – URL of the site making the queries
  • from_query (string) – local search query used to get the from points
  • to_query (string) – local search query used to get the to points
  • numpoints (int) – Number of from and to points to use in each city
  • callback (func(string), or None) – Function you provide that gets called with a string containing status messages, or None.
  • data_dir (string) – Directory name in which to locate/save data.
Raises MapperError:
 

If no points or routes could be retrieved

compute_route_stats(routes, statskeepers={})

Compute statistics from route data.

Parameters:
  • routes (list of dict(string: numeric)) – List of dictionaries giving the meters, seconds, and steps for each route through a city.
  • statskeepers (dict(string: stats.Keeper)) – Compute additional statistics by providing a dictionary mapping the name of a statistic to a stats.Keeper subclass that knows how to compute it.
Returns:

Dictionary of statistics for the given routes.

Return type:

dict(string: numeric) with (at least) the following keys: numroutes, meters_avg, meters_std, seconds_avg, seconds_std, meters_per_sec_avg, meters_per_sec_std, steps_avg, steps_std, steps_per_meter_avg, steps_per_meter_std. ‘avg’ means average, ‘std’ means standard deviation.

You can add your own statistics by subclassing stats.Keeper and adding your class to statskeepers. The key you use will be appended to each of the five measured quantites (meters, seconds, steps, meters per second, and steps per meter) returned from compute_route_stats(), and it will map to the value returned by the get() method of your stats.Keeper.

Example: say you want to see medians. Define a Median(stats.Keeper) and pass the keyword argument statskeepers={'med': Median} to this function. Then the dictionary returned from this function will contain keys ‘meters_med’, ‘seconds_med’, etc., mapping to the medians of the samples.

print_callback(message)

Prints message to stdout.

For tracking the progress of long runs.

Indices and tables

Table Of Contents

Previous topic

CitySpeed - Road network efficiency via online mapping

Next topic

mapper - Geocoding, Local Search, Directions, Routes

This Page


Python Powered

Get CitySpeed at SourceForge.net. Fast, secure and Free Open Source software downloads