Skip to content

Commit

Permalink
Start on cyclestreets#46
Browse files Browse the repository at this point in the history
  • Loading branch information
atumscott committed Feb 16, 2023
1 parent 7b0998b commit 63c1651
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions R/journey2.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,35 @@ make_handle <- function(x){
return(handle)
}

get_values = function(v, fun) {
sapply(v, function(x) fun(as.numeric(x)))
}

extract_values = function(x) stringr::str_split(x, pattern = ",")
get_mean = function(v) get_values(v, fun = mean)
get_sum = function(v) get_values(v, fun = sum)
get_min = function(v) get_values(v, fun = min)
get_max = function(v) get_values(v, fun = max)

add_columns = function(r) {


elevations_list = extract_values(r_3$elevations)

r_3$elevations
r_3$elevation_min = get_min(elevations_list)
r_3$elevation_max = get_max(elevations_list)
distances_list = extract_values(r_3$distances)
r_3$segment_length = get_sum(distances_list)
r_3$elevation_change = r_3$elevation_max - r_3$elevation_min
r_3$gradient_segment = r_3$elevation_change / r_3$segment_length
r_3$gradient_smooth = cyclestreets::smooth_with_cutoffs(
r_3$gradient_segment,
r_3$elevation_change,
r_3$segment_length,
distance_cutoff = 50,
gradient_cutoff = 0.1,
n = 3,
)
}

0 comments on commit 63c1651

Please sign in to comment.