-
Notifications
You must be signed in to change notification settings - Fork 1
/
load_results.R
53 lines (45 loc) · 1.57 KB
/
load_results.R
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
source("R/loaders.R")
source("R/summarizers.R")
source("R/utilities.R")
source("config.R")
load_results <- function(prefix, load_boundaries=TRUE, summarize=TRUE) {
util_test_conn(prefix)
conn <- util_conn(prefix)
on.exit(DBI::dbDisconnect(conn))
tables <- c(
"owners", "companies", "officers", "metacorps_cosine", "parcels_point",
"metacorps_network", "sites", "sites_to_owners", "addresses")
if (load_boundaries) {
tables <- c(
tables,
c("zips", "munis", "tracts", "block_groups")
)
}
tables_exist <- util_check_for_tables(
conn,
tables
)
if (!tables_exist) {
stop(glue::glue("VALIDATION: Tables don't seem to exist on '{prefix}' database."))
} else {
util_log_message(glue::glue("VALIDATION: Loading tables from '{prefix}' database."), header=TRUE)
for(t in tables) {
util_log_message(glue::glue("INPUT/OUTPUT: Loading {t} from '{prefix}' database."))
assign(t, load_postgis_read(conn, t), envir = .GlobalEnv)
}
}
invisible(NULL)
if (summarize) {
util_log_message("PROCESSING: Summarizing metacorps and officers.")
own_summary <- sites_to_owners |>
summ_sites_to_owners(owners, sites)
metacorps_cosine <<- own_summary |>
summ_site_group("cosine_group", metacorps_cosine)
metacorps_network <<- own_summary |>
summ_site_group("network_group", metacorps_network)
metacorps_network <<- metacorps_network |>
summ_metacorps_network_companies(companies)
officers <<- officers |>
summ_officers_innetwork_companies(metacorps_network)
}
}