Skip to content

Commit

Permalink
No differences!
Browse files Browse the repository at this point in the history
  • Loading branch information
atumscott committed Feb 16, 2023
1 parent d6ab2c1 commit 7b0998b
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions data-raw/test-journey2.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,40 @@ od = sf::read_sf("data-raw/od-test.geojson")
file.edit("R/journey.R")
# [17] "gradient_segment" "elevation_change" "gradient_smooth"


r_3 = r_2

cyclestreets:::json2sf_cs()

split_elevations = stringr::str_split(r_3$elevations, pattern = ",")

r_3$elevation_mean = sapply(split_elevations, function(x) mean(as.numeric(x)))
r_3$elevation_min = sapply(split_elevations, function(x) min(as.numeric(x)))
r_3$elevation_max = sapply(split_elevations, function(x) max(as.numeric(x)))
r_3$gradient_segment = (r_3$elevation_max - r_3$elevation_min) / r_3$distances
d_variable$elevation_change = (vals_variable$elevation_max -
vals_variable$elevation_min)

smooth_with_cutoffs(
r$gradient_segment,
r$elevation_change,
r$distances,
distance_cutoff,
gradient_cutoff,
n,
warnNA = warnNA
)

route_rolling_average <- function(x, n = 3) {
if(length(x) >= n) {
as.numeric(stats::filter(x, rep(1 / n, n), sides = 2))
} else {
x
}
# Generalise the function for shorter lines:
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)
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,
)
identical(r_3$gradient_segment, r_3$gradient_smooth)

r_3 = r_3[names(r_1)]

waldo::compare(r_1, r_3)

0 comments on commit 7b0998b

Please sign in to comment.