From 9f067ee9896364e5cbfdd3096857531340e2f09a Mon Sep 17 00:00:00 2001 From: Sweaty Handshake Date: Sun, 3 Nov 2024 23:48:48 +0000 Subject: [PATCH] Linting --- .../spatial/spatial-environment-traffic.R | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/etl/scripts-ccao-data-warehouse-us-east-1/spatial/spatial-environment-traffic.R b/etl/scripts-ccao-data-warehouse-us-east-1/spatial/spatial-environment-traffic.R index b8e7e52ca..854e6bd91 100644 --- a/etl/scripts-ccao-data-warehouse-us-east-1/spatial/spatial-environment-traffic.R +++ b/etl/scripts-ccao-data-warehouse-us-east-1/spatial/spatial-environment-traffic.R @@ -105,8 +105,9 @@ walk(parquet_files, \(file_key) { shapefile_data <- shapefile_data %>% select(all_of(existing_columns)) %>% mutate( - road_type = if ("FCNAME" %in% colnames(.)) FCNAME - else if ("FC_NAME" %in% colnames(.)) FC_NAME else NA, + road_type = if ("FCNAME" %in% colnames(.)) { + FCNAME + } else if ("FC_NAME" %in% colnames(.)) FC_NAME else NA, lanes = if ("LNS" %in% colnames(.)) LNS else NA, surface_type = if ("SURF_TYP" %in% colnames(.)) SURF_TYP else NA, surface_width = if ("SURF_WTH" %in% colnames(.)) SURF_WTH else NA, @@ -118,7 +119,11 @@ walk(parquet_files, \(file_key) { road_name = if ("ROAD_NAME" %in% colnames(.)) ROAD_NAME else NA, distress_with = if ("DTRESS_WTH" %in% colnames(.)) DTRESS_WTH else NA, distress_opposing = if ("DTRESS_OPP" %in% - colnames(.)) DTRESS_OPP else NA, + colnames(.)) { + DTRESS_OPP + } else { + NA + }, speed_limit = if ("SP_LIM" %in% colnames(.)) SP_LIM else NA, inventory_id = if ("INVENTORY" %in% colnames(.)) INVENTORY else NA ) %>% @@ -161,8 +166,10 @@ walk(parquet_files, \(file_key) { mutate(across(-geometry, ~ replace(., . %in% c(0, "0000"), NA))) %>% mutate(surface_year = ifelse(surface_year == 9999, NA, surface_year)) %>% # Group by the characteristics that we want - group_by(road_name, speed_limit, lanes, - surface_type, daily_traffic, year, road_type) %>% + group_by( + road_name, speed_limit, lanes, + surface_type, daily_traffic, year, road_type + ) %>% # Create a union of the streets based on the summarized features summarize(geometry = st_union(geometry), .groups = "drop") %>% mutate(geometry_3435 = st_transform(geometry, 3435)) %>% @@ -185,7 +192,7 @@ walk(parquet_files, \(file_key) { ) }) ) %>% - filter(polygon_1 != polygon_2) # Remove self-matches + filter(polygon_1 != polygon_2) # Remove self-matches # Add polygon IDs and relevant columns for merging data_with_ids <- data %>% mutate(polygon_id = row_number()) %>% @@ -228,13 +235,17 @@ walk(parquet_files, \(file_key) { left_join(averages, by = c("polygon_id" = "polygon_1")) %>% mutate( daily_traffic = if_else(is.na(daily_traffic), average_daily_traffic, - daily_traffic), + daily_traffic + ), speed_limit = if_else(is.na(speed_limit), average_speed_limit, - speed_limit), + speed_limit + ), lanes = if_else(is.na(lanes), average_lanes, lanes) ) %>% - select(-c(average_daily_traffic, average_speed_limit, - average_lanes, polygon_id)) + select(-c( + average_daily_traffic, average_speed_limit, + average_lanes, polygon_id + )) return(shapefile_data_final) } @@ -276,4 +287,3 @@ walk(parquet_files, \(file_key) { print(paste(file_key, "cleaned and uploaded.")) } }, .progress = TRUE) -