Skip to content

Commit

Permalink
Creating separate distributions for activity creation per group; #4
Browse files Browse the repository at this point in the history
  • Loading branch information
dhixsingh committed Mar 12, 2021
1 parent 0032f18 commit 761d7a1
Show file tree
Hide file tree
Showing 27 changed files with 2,212 additions and 20 deletions.
31 changes: 26 additions & 5 deletions R/setup.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
# Function to pre-process some data; need only be run once
demand_setup_groups<-function(groups,
setupDir,
vista18TripsCsv,
out_weekday_activities_csv_gz_prefix,
out_weekend_activities_csv_gz_prefix,
out_weekday_activities_time_bins_csv_gz_prefix,
out_weekend_activities_time_bins_csv_gz_prefix,
out_weekday_activities_end_time_dist_by_start_bins_csv_gz_prefix
) {
for (gid in groups) {
demand_setup(
setupDir,
vista18TripsCsv,
paste0(setupDir,"/",out_weekday_activities_csv_gz_prefix,gid,".csv.gz"),
paste0(setupDir,"/",out_weekend_activities_csv_gz_prefix,gid,".csv.gz"),
paste0(setupDir,"/",out_weekday_activities_time_bins_csv_gz_prefix,gid,".csv.gz"),
paste0(setupDir,"/",out_weekend_activities_time_bins_csv_gz_prefix,gid,".csv.gz"),
paste0(setupDir,"/",out_weekday_activities_end_time_dist_by_start_bins_csv_gz_prefix,gid,".csv.gz")
)
}
}

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
out_weekday_activities_end_time_dist_by_start_bins_csv_gz
) {
# example parameter values
# setupDir <- '../output/1.setup'
Expand All @@ -14,7 +35,7 @@ demand_setup<-function(setupDir,
# 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')
# out_weekday_activities_end_time_dist_by_start_bins_csv_gz <- 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
Expand Down Expand Up @@ -42,8 +63,8 @@ demand_setup<-function(setupDir,

# Write out the activity end time probabilities for each start time bin
in_activities_csv_gz<-out_weekday_activities_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)
echo(paste0('Extracting VISTA weekday activities end times distributions for each start time bin into ',out_weekday_activities_end_time_dist_by_start_bins_csv_gz,'\n'))
extract_and_write_activities_end_time_dist_by_start_bins(in_activities_csv_gz, out_weekday_activities_end_time_dist_by_start_bins_csv_gz, binsize)

echo('Setup complete\n')
return(TRUE)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
36 changes: 21 additions & 15 deletions tests/testthat/testSetup.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,33 @@ test_that("VISTA 2012-18 trips pre-processing works", {
outdir<-'../actual/1.setup'
dir.create(outdir, showWarnings = FALSE, recursive=TRUE)
capture_output(
demand_setup(
demand_setup_groups(
getGroupIds('../data/vistaCohorts.csv.gz'),
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'
'vista_2012_18_extracted_activities_weekday_',
'vista_2012_18_extracted_activities_weekend_',
'vista_2012_18_extracted_activities_weekday_time_bins_',
'vista_2012_18_extracted_activities_weekend_time_bins_',
'vista_2012_18_extracted_activities_weekday_end_dist_for_start_bins_'
)
)

files<-c(
'vista_2012_18_extracted_activities_weekday.csv.gz',
'vista_2012_18_extracted_activities_weekday_end_dist_for_start_bins.csv.gz',
'vista_2012_18_extracted_activities_weekday_time_bins.csv.gz',
'vista_2012_18_extracted_activities_weekend.csv.gz',
'vista_2012_18_extracted_activities_weekend_time_bins.csv.gz'
files_prefix<-c(
'vista_2012_18_extracted_activities_weekday_',
'vista_2012_18_extracted_activities_weekday_end_dist_for_start_bins_',
'vista_2012_18_extracted_activities_weekday_time_bins_',
'vista_2012_18_extracted_activities_weekend_',
'vista_2012_18_extracted_activities_weekend_time_bins_'
)
for (file in files) {
expect_true(file.exists(paste0('../actual/1.setup/', file)))
expect_true(md5sum(paste0('../actual/1.setup/', file)) == md5sum(paste0('../expected/1.setup/', file)))

groups<-getGroupIds('../data/vistaCohorts.csv.gz')
for (gid in groups) {
for (prefix in files_prefix) {
file<-paste0(prefix,gid,".csv.gz")
expect_true(file.exists(paste0('../actual/1.setup/',file)))
expect_true(md5sum(paste0('../actual/1.setup/', file)) == md5sum(paste0('../expected/1.setup/', file)))
}
}
})

0 comments on commit 761d7a1

Please sign in to comment.