Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

374 use tar map to reduce duplicated code #547

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ npt_net_qgis
scottraffic/
*.geojson
osm_os/
nptscot.github.io/
179 changes: 45 additions & 134 deletions _targets.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ pkgs = get_pkgs()


tar_option_set(
controller = crew::crew_controller_local(workers = 1),
controller = crew::crew_controller_local(workers = 4),
memory = "transient",
garbage_collection = TRUE,
storage = "worker",
retrieval = "worker",
packages = pkgs,
format = "rds" # default storage format
format = "rds", # default storage format
# See https://books.ropensci.org/targets/performance.html#memory:
garbage_collection = 1 # collect garbage after each target
)

# Targets -----------------------------------------------------------------
Expand Down Expand Up @@ -214,184 +216,93 @@ list(
}),

# School routing ----------------------------------------------------------

tar_target(rs_school_fastest, {
rs = get_routes(
od = od_school |> slice_max(n = parameters$max_to_route, order_by = all, with_ties = FALSE),
plans = "fastest",
purpose = "school",
folder = region_folder,
date = parameters$date_routing,
segments = "both"
)
rs
}),
tar_target(done_school_fastest, {
length(rs_school_fastest) # Hack for scheduling
}),
tar_target(rs_school_quietest, {
length(done_school_fastest)
rs = get_routes(
od = od_school |> slice_max(n = parameters$max_to_route, order_by = all, with_ties = FALSE),
plans = "quietest",
purpose = "school",
folder = region_folder,
date = parameters$date_routing,
segments = "both"
)
rs
}),
tar_target(done_school_quietest, {
length(rs_school_quietest) # Hack for scheduling
}),

# Balanced:
tar_target(rs_school_balanced, {
length(done_school_quietest)
rs = get_routes(
od = od_school |> slice_max(n = parameters$max_to_route, order_by = all, with_ties = FALSE),
plans = "balanced",
purpose = "school",
folder = region_folder,
date = parameters$date_routing,
segments = "both"
)
rs
}),
tar_target(done_school_balanced, {
length(rs_school_balanced) # Hack for scheduling
}),
tar_target(rs_school_ebike, {
length(done_school_quietest)
rs = get_routes(
od = od_school |> slice_max(n = parameters$max_to_route, order_by = all, with_ties = FALSE),
plans = "ebike",
purpose = "school",
folder = region_folder,
date = parameters$date_routing,
segments = "both"
)
rs
}),
tar_target(done_school_ebike, {
length(rs_school_ebike) # Hack for scheduling
}),
tar_target(plans, {
parameters$plans
}),

tar_target(rs_school, {
get_routes(
od = od_school |> slice_max(n = parameters$max_to_route, order_by = all, with_ties = FALSE),
plans = plans,
purpose = "school",
folder = region_folder,
date = parameters$date_routing,
segments = "both")
},
pattern = map(plans),
iteration = "list"
)

,

# Commute routing ---------------------------------------------------------

tar_target(rs_commute_fastest, {
length(done_school_ebike) # Do school routing first
rs = get_routes(
tar_target(rs_commute, {
get_routes(
od = od_commute_subset,
plans = "fastest",
purpose = "commute",
folder = region_folder,
date = parameters$date_routing,
segments = "both"
)
rs
}),
tar_target(done_commute_fastest, {
length(rs_commute_fastest) # Hack for scheduling
}),
tar_target(rs_commute_balanced, {
length(done_commute_fastest)
rs = get_routes(
od = od_commute_subset,
plans = "balanced",
purpose = "commute",
folder = region_folder,
date = parameters$date_routing,
segments = "both"
)
rs
}),
tar_target(done_commute_balanced, {
length(rs_commute_balanced) # Hack for scheduling
}),
tar_target(rs_commute_quietest, {
length(done_commute_fastest)
rs = get_routes(
od = od_commute_subset,
plans = "quietest",
plans = plans,
purpose = "commute",
folder = region_folder,
date = parameters$date_routing,
segments = "both"
)
rs
}),
tar_target(done_commute_quietest, {
length(rs_commute_quietest) # Hack for scheduling
}),
tar_target(rs_commute_ebike, {
length(done_commute_quietest)
rs = get_routes(
od = od_commute_subset,
plans = "ebike",
purpose = "commute",
folder = region_folder,
date = parameters$date_routing,
segments = "both"
)
rs
}),
tar_target(done_commute_ebike, {
length(rs_commute_ebike) # Hack for scheduling
}),
},
pattern = map(plans),
iteration = "list"
),

# Commute routing post-processing -----------------------------------------

tar_target(r_commute_fastest, {
rs_commute_fastest[[1]]$routes
rs_commute[[1]][[1]]$routes
}),
tar_target(r_commute_quietest, {
rs_commute_quietest[[1]]$routes
rs_commute[[3]][[1]]$routes
}),
tar_target(r_commute_ebike, {
rs_commute_ebike[[1]]$routes
rs_commute[[4]][[1]]$routes
}),
tar_target(r_commute_balanced, {
rs_commute_balanced[[1]]$routes
rs_commute[[2]][[1]]$routes
}),
tar_target(rnet_gq_commute_fastest, {
segments2rnet(rs_commute_fastest[[1]]$segments)
segments2rnet(rs_commute[[1]][[1]]$segments)
}),
tar_target(rnet_gq_commute_quietest, {
segments2rnet(rs_commute_quietest[[1]]$segments)
segments2rnet(rs_commute[[3]][[1]]$segments)
}),
tar_target(rnet_gq_commute_ebike, {
segments2rnet(rs_commute_ebike[[1]]$segments)
segments2rnet(rs_commute[[4]][[1]]$segments)
}),
tar_target(rnet_gq_commute_balanced, {
segments2rnet(rs_commute_balanced[[1]]$segments)
segments2rnet(rs_commute[[2]][[1]]$segments)
}),

# School routing post-processing -----------------------------------------

tar_target(r_school_fastest, {
rs_school_fastest[[1]]$routes
rs_school[[1]][[1]]$routes
}),
tar_target(r_school_quietest, {
rs_school_quietest[[1]]$routes
rs_school[[3]][[1]]$routes
}),
tar_target(r_school_ebike, {
rs_school_ebike[[1]]$routes
rs_school[[4]][[1]]$routes
}),
tar_target(r_school_balanced, {
rs_school_balanced[[1]]$routes
rs_school[[2]][[1]]$routes
}),
tar_target(rnet_gq_school_fastest, {
segments2rnet(rs_school_fastest[[1]]$segments)
segments2rnet(rs_school[[1]][[1]]$segments)
}),
tar_target(rnet_gq_school_quietest, {
segments2rnet(rs_school_quietest[[1]]$segments)
segments2rnet(rs_school[[3]][[1]]$segments)
}),
tar_target(rnet_gq_school_ebike, {
segments2rnet(rs_school_ebike[[1]]$segments)
segments2rnet(rs_school[[4]][[1]]$segments)
}),
tar_target(rnet_gq_school_balanced, {
segments2rnet(rs_school_balanced[[1]]$segments)
segments2rnet(rs_school[[2]][[1]]$segments)
}),

# Commute Uptake ----------------------------------------------------------
Expand Down