Skip to content

How to add a new city

mark padgham edited this page Apr 18, 2018 · 7 revisions

main steps

Adding new cities to the package currently requires the following steps:

  1. Add city to R/utils.R/convert_city_names.
  2. Add entry to R/database-stats.R/bike_demographic_data.
  3. Write a routine to access the data files in R/bikedata-files.R, including adding entry in get_bike_files().
  4. Update R/storebikedata.R/get_bike_cities and ../get_flist_city to automatically recognise the new files by their names.
  5. Potentially change R/date-time-functions.R/convert_dates_to_filenames.
  6. If the city has separate station data, either provided with the trip data or otherwise, then add city-specific function to R/stations.R, and list the station in the main loop of R/store_bikedata where it says, "import stations to station table". If the station data are included within the trip data, then add city to list in R/utils.R/data_has_stations.
  7. Examine the raw data files and ensure that the field (column) names all appear in the appropriate places in data-raw/sysdata.Rmd, or insert new ones. If new ones are inserted, then the whole script needs to be run to update the internal package data. If any new column names describe a different field to one that already exists, then individual city codes need to be entered, as for "la" and "mn" at the end of that script.

The data should be automatically parsed by the current C++ routines. This automatic parsing should only fail if files do not maintain the same structure throughout, as happens for a few cities in which patterns of quotation change. These require city-specific routines to be coded, which is far more laborious.

data provided as uncompressed csv files

These cases need additional modifications to the R/store-bikedata.R routines, following the pattern for other cities with raw .csv files.

test data

Test data for each new city also need to be created. This can be done at a later stage, but is done with this script:

bike_write_test_data (tempdir ())
bikedb <- file.path (getwd (), "testdb.sqlite")│
store_bikedata (data_dir = tempdir (), bikedb = bikedb)
index_bikedata_db (bikedb = bikedb)

Then the bikedb is moved manually to /inst/data.

Clone this wiki locally