-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_closed_shops_from_cube.R
More file actions
57 lines (44 loc) · 2.01 KB
/
Copy pathremove_closed_shops_from_cube.R
File metadata and controls
57 lines (44 loc) · 2.01 KB
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
# removes values from travel time cube if destinations are closed
# in this case, destinations are supermarkets
# clear env
rm(list = ls())
# inputs
walk_matrix_all <- read.table("walk_matrix_45.csv", header = TRUE, row.names = 1, sep = ",", check.names = FALSE) # DAs to supermarkets
store_hours <- read.table("super_hours_update_99.csv", header = TRUE, row.names = 1, sep = ",", check.names = FALSE) # supermarket hours
# for each minute in an hour
minute_list = c(0:59)
for (minute in minute_list) {
# departure time starting
day <- "Saturday"
day_num <- 9
hour <- 12 # 0 to 23 starting hour
# minute <- 0 # 0 to 59 as in loop
shop_time <- 20 # min shopping time in minutes
# grab column names for the day we're lookin' at
open_field_1 <- paste(day, "_Open", sep='')
close_field_1 <- paste(day, "_Close", sep='')
open_field_2 <- paste(day, "_Open_2", sep='')
close_field_2 <- paste(day, "_Close_2", sep='')
# out_matrix
out_matrix <- walk_matrix_all
# time of arrival to store
get_there_time <- ((out_matrix / 60) / 60)
get_there_time[get_there_time == 0] <- NA
get_there_time <- get_there_time + hour + minute / 60
# min time of departure from store
leave_there_time <- get_there_time + (shop_time / 60)
# grab boolean matrices if store is open when you get there and have time to shop
open_bool_matrix_1 <- t(t(get_there_time) > (store_hours[,open_field_1]))
open_bool_matrix_2 <- t(t(get_there_time) > (store_hours[,open_field_2]))
close_bool_matrix_1 <- t(t(leave_there_time) < (store_hours[,close_field_1]))
close_bool_matrix_2 <- t(t(leave_there_time) < (store_hours[,close_field_2]))
first_set <- open_bool_matrix_1 & close_bool_matrix_1
second_set <- open_bool_matrix_2 & close_bool_matrix_2
total_truth <- first_set | second_set
# output matrix and write
out_matrix <- out_matrix * total_truth
out_matrix[out_matrix == 0] <- NA
file_name <- paste("saturday_12_1/walk", day, day_num, hour, minute, ".csv", sep='_')
write.csv(out_matrix, file = file_name)
}
rm(list = ls())