-
Notifications
You must be signed in to change notification settings - Fork 0
/
_targets.R
191 lines (144 loc) · 4.83 KB
/
_targets.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
library(targets)
library(tarchetypes)
# This is an example _targets.R file. Every
# {targets} pipeline needs one.
# Use tar_script() to create _targets.R and tar_edit()
# to open it again for editing.
# Then, run tar_make() to run the pipeline
# and tar_read(summary) to view the results.
library(readr)
library(purrr)
library(qs)
# Set target-specific options such as packages.
tar_option_set(
packages = c(
"tidyverse", "data.table", "R.utils", "archive", "magrittr", "sf",
"ggspatial", "kableExtra"),
garbage_collection = TRUE,
format = "qs")
# Define custom functions and other global objects.
# This is where you write source(\"R/functions.R\")
# if you keep your functions in external scripts.
r_files <- c(
"R/data_handlers.R",
"R/summarize_events.R",
"R/UTAOD_comparison.R",
"R/prelim_comparison.R"
)
purrr::map(r_files, source)
######## List targets ##########################################################
data_targets <- tar_plan(
tar_target(EX, "data/wfrc_existing_events.csv.gz", format = "file"),
tar_target(A, "data/wfrc_A_events.csv.gz", format = "file"),
tar_target(B, "data/wfrc_B_events.csv.gz", format = "file"),
tar_target(C, "data/wfrc_C_events.csv.gz", format = "file"),
tar_target(D, "data/wfrc_D_events.csv.gz", format = "file"),
tar_target(EX_fleet, "data/rh_fleets/rhFleet_Existing.csv", format = "file"),
tar_target(A_fleet, "data/rh_fleets/rhFleet_A.csv", format = "file"),
tar_target(B_fleet, "data/rh_fleets/rhFleet_B.csv", format = "file"),
tar_target(C_fleet, "data/rh_fleets/rhFleet_C.csv", format = "file"),
tar_target(D_fleet, "data/rh_fleets/rhFleet_D.csv", format = "file"),
scenarios = list(
existing = data.table::fread(file = EX, select = event_cols),
A = data.table::fread(file = A, select = event_cols),
B = data.table::fread(file = B, select = event_cols),
C = data.table::fread(file = C, select = event_cols),
D = data.table::fread(file = D, select = event_cols)
),
fleets = list(
existing = read_ridehail_fleet(EX_fleet),
A = read_ridehail_fleet(A_fleet),
B = read_ridehail_fleet(B_fleet),
C = read_ridehail_fleet(C_fleet),
D = read_ridehail_fleet(D_fleet)
),
fleet_sizes = get_fleet_sizes(fleets),
#Names and types of cols to keep for events files
event_cols = c(
# TODO: read this from file
person = "character",
time = "numeric",
type = "character",
actType = "character",
tourPurpose = "character",
arrivalTime = "integer",
departureTime = "integer",
legMode = "character",
mode = "character",
currentTourMode = "character",
vehicleType = "character",
vehicle = "character",
numPassengers = "integer",
startX = "numeric",
startY = "numeric",
location = "integer",
links = "character",
linkTravelTime = "character",
length = "numeric",
reason = "character"
),
#### UTA On Demand ##########################
#Get UTA On Demand pilot program info
tar_target(UTAOD, "data/UTAODpilotinfo.csv", format = "file"),
#months for which the observed data is good
good_months = c("JAN", "FEB", "MAR"),
UTA = readr::read_csv(UTAOD) %>%
filter(Month %in% good_months) %>%
pivot_uta(),
)
analysis_targets <- tar_plan(
#### Ridehail events #######################
ridehail_modes = c("ride_hail",
"ride_hail_pooled",
"ride_hail_transit"),
total_riders = purrr::map(
scenarios,
get_tot_rh_passengers),
rh_trips = purrr::map(
scenarios,
get_ridehail_trips,
ridehail_modes),
utilization = purrr::map2(
total_riders, fleets,
get_rh_utilization),
average_wait_times = purrr::map(
scenarios,
get_avg_rh_wait_time),
# ridehail_to_transit = c(number, percent, am, pm)
)
viz_targets <- tar_plan(
existing_comparison = compare_existing(
UTA, total_riders$existing,
utilization$existing,
average_wait_times$existing),
ridership_comparison = compare_riders(
total_riders),
utilization_comparison = compare_utilization(
utilization,
fleet_sizes),
wait_time_comparison = compare_wait_times(
average_wait_times),
# Combine all comparisons for easy loading/viewing
all_comparisons = list(
"Existing comparison" = existing_comparison,
"Ridership comparison" = ridership_comparison,
"Utilization comparison" = utilization_comparison,
"Wait time comparison" = wait_time_comparison
)
)
render_targets <- tar_plan(
# report = bookdown::render_book(
# input = ".", output_yaml = "_output.yml", config_file = "_bookdown.yml")
)
########### Run all targets ####################################################
tar_plan(
data_targets,
analysis_targets,
viz_targets,
render_targets
)
# # Run all targets
# tar_plan(
# data = data_targets,
# book = book_targets
# )