From 0032f18632d49d73c51a20b106d59c0ab3b24428 Mon Sep 17 00:00:00 2001 From: Dhirendra Singh Date: Thu, 11 Mar 2021 09:41:16 +1100 Subject: [PATCH] More restructuring in prep for #4 --- R/makeExamplePopulation.R | 11 +++++++++-- R/setup.R | 19 +++++++++++++------ tests/testthat/testSetup.R | 10 +++++++++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/R/makeExamplePopulation.R b/R/makeExamplePopulation.R index 4b99cb6..554dd9f 100644 --- a/R/makeExamplePopulation.R +++ b/R/makeExamplePopulation.R @@ -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', diff --git a/R/setup.R b/R/setup.R index b5bdee9..2cb2a1c 100644 --- a/R/setup.R +++ b/R/setup.R @@ -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')) @@ -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) @@ -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) diff --git a/tests/testthat/testSetup.R b/tests/testthat/testSetup.R index cbe0103..9c0e334 100644 --- a/tests/testthat/testSetup.R +++ b/tests/testthat/testSetup.R @@ -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(