Skip to content

Commit

Permalink
More restructuring in prep for #4
Browse files Browse the repository at this point in the history
  • Loading branch information
dhixsingh committed Mar 10, 2021
1 parent 6c2e804 commit 0032f18
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
11 changes: 9 additions & 2 deletions R/makeExamplePopulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,15 @@ makeExamplePopulation<-function(samplePercent, numPlans, do.steps=c(T,T,T,T,T,T,
'vista_2012_18_extracted_group_weekday_',
'vista_2012_18_extracted_trips_weekday_'
)
demand_setup('../output/1.setup',
'../data/VISTA_12_18_CSV.zip.dir/T_VISTA1218_V1.csv')
demand_setup(
'../output/1.setup',
'../data/VISTA_12_18_CSV.zip.dir/T_VISTA1218_V1.csv',
'../output/1.setup/vista_2012_18_extracted_activities_weekday.csv.gz',
'../output/1.setup/vista_2012_18_extracted_activities_weekend.csv.gz',
'../output/1.setup/vista_2012_18_extracted_activities_weekday_time_bins.csv.gz',
'../output/1.setup/vista_2012_18_extracted_activities_weekend_time_bins.csv.gz',
'../output/1.setup/vista_2012_18_extracted_activities_weekday_end_dist_for_start_bins.csv.gz'
)
locations_setup(
'../output/1.setup',
'../data/distanceMatrix.rds',
Expand Down
19 changes: 13 additions & 6 deletions R/setup.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# Function to pre-process some data; need only be run once
demand_setup<-function(setupDir, vista18TripsCsv) {
demand_setup<-function(setupDir,
vista18TripsCsv,
out_weekday_activities_csv_gz,
out_weekend_activities_csv_gz,
out_weekday_activities_time_bins_csv_gz,
out_weekend_activities_time_bins_csv_gz,
out_csv
) {
# example parameter values
# setupDir <- '../output/1.setup'
# vista18TripsCsv <- '../data/VISTA_12_18_CSV.zip.dir/T_VISTA1218_V1.csv'
# out_weekday_activities_csv_gz <- paste0(setupDir,'/vista_2012_18_extracted_activities_weekday.csv.gz')
# out_weekend_activities_csv_gz <- paste0(setupDir,'/vista_2012_18_extracted_activities_weekend.csv.gz')
# out_weekday_activities_time_bins_csv_gz<-paste0(setupDir,'/vista_2012_18_extracted_activities_weekday_time_bins.csv.gz')
# out_weekend_activities_time_bins_csv_gz<-paste0(setupDir,'/vista_2012_18_extracted_activities_weekend_time_bins.csv.gz')
# out_csv <- paste0(setupDir,'/vista_2012_18_extracted_activities_weekday_end_dist_for_start_bins.csv.gz')

# Extract VISTA activities and save separately into weekday and weekend activities
vista_csv <- vista18TripsCsv
out_weekday_activities_csv_gz <- paste0(setupDir,'/vista_2012_18_extracted_activities_weekday.csv.gz')
out_weekend_activities_csv_gz <- paste0(setupDir,'/vista_2012_18_extracted_activities_weekend.csv.gz')
echo(paste0('Extracting VISTA weekday/end activities from ', vista_csv, ' (can take a while)\n'))
extract_and_write_activities_from(vista_csv, out_weekday_activities_csv_gz, out_weekend_activities_csv_gz)
echo(paste0('Wrote ', out_weekday_activities_csv_gz, ' and ', out_weekend_activities_csv_gz,'\n'))
Expand All @@ -22,8 +32,6 @@ demand_setup<-function(setupDir, vista18TripsCsv) {
# Write out the activity probabilities by time bins
binsize<-48 # 30-min bins
echo(paste0('Extracting VISTA weekday/end activities times into ',binsize,' bins (can take a while)\n'))
out_weekday_activities_time_bins_csv_gz<-paste0(setupDir,'/vista_2012_18_extracted_activities_weekday_time_bins.csv.gz')
out_weekend_activities_time_bins_csv_gz<-paste0(setupDir,'/vista_2012_18_extracted_activities_weekend_time_bins.csv.gz')
in_activities_csv_gz<-out_weekday_activities_csv_gz
out_csv_gz<-out_weekday_activities_time_bins_csv_gz
extract_and_write_activities_time_bins(in_activities_csv_gz, out_csv_gz, binsize)
Expand All @@ -34,7 +42,6 @@ demand_setup<-function(setupDir, vista18TripsCsv) {

# Write out the activity end time probabilities for each start time bin
in_activities_csv_gz<-out_weekday_activities_csv_gz
out_csv <- paste0(setupDir,'/vista_2012_18_extracted_activities_weekday_end_dist_for_start_bins.csv.gz')
echo(paste0('Extracting VISTA weekday activities end times distributions for each start time bin into ',out_csv,'\n'))
extract_and_write_activities_end_time_dist_by_start_bins(in_activities_csv_gz, out_csv, binsize)

Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/testSetup.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ test_that("VISTA 2012-18 trips pre-processing works", {
outdir<-'../actual/1.setup'
dir.create(outdir, showWarnings = FALSE, recursive=TRUE)
capture_output(
demand_setup(outdir, '../data/T_VISTA1218_V1.sample.csv')
demand_setup(
outdir,
'../data/T_VISTA1218_V1.sample.csv',
'../actual/1.setup/vista_2012_18_extracted_activities_weekday.csv.gz',
'../actual/1.setup/vista_2012_18_extracted_activities_weekend.csv.gz',
'../actual/1.setup/vista_2012_18_extracted_activities_weekday_time_bins.csv.gz',
'../actual/1.setup/vista_2012_18_extracted_activities_weekend_time_bins.csv.gz',
'../actual/1.setup/vista_2012_18_extracted_activities_weekday_end_dist_for_start_bins.csv.gz'
)
)

files<-c(
Expand Down

0 comments on commit 0032f18

Please sign in to comment.