#############################################################################
# This script can be used to run the main analysis in `m-Main.R` locally.
# Parameters below can be adjusted to run all or some combinations of the parameters 
# used in the complete analysis.
#############################################################################

# Start with a clean environment ----
rm(list = ls())

# Configuration of parameter sets to be analyzed ----
locations       <- c("Toronto, Canada") # "Dubai, United Arab Emirates" "Rio_de_Janeiro, Brazil" "Rome, Italy" "Toronto, Canada"
sigma_betas     <- c(0)                 # (0 0.05)
IDs             <- 1:50                 # From 1 to 50
True_e_vals_Now <- c(-0.016)            # (-0.04 -0.02)
True_e_vals_Lag <- c(-0.027)            # (-0.04 -0.02)
rho_Ks          <- c(0.1)               # (0.1 0.16)
School_Terms    <- c(0)                 # (0 1)
rho_Means       <- c(0.5)
import_rates    <- c(1e-5)

grid <- expand.grid(
  location           = locations,
  sigma_betas_val    = sigma_betas,
  ID                 = IDs,
  True_e_Te_Now      = True_e_vals_Now,
  True_e_RH_Now      = True_e_vals_Now,
  True_e_Te_Lag      = True_e_vals_Lag,
  True_e_RH_Lag      = True_e_vals_Lag,
  rho_K              = rho_Ks,
  rho_Mean           = rho_Means,
  import_val         = import_rates,
  School_Term        = School_Terms,
  stringsAsFactors   = FALSE
)

# Loop running one full analysis for one parameter set, location and scenario ----
for (i in seq_len(nrow(grid))) {
  p <- grid[i, ]
  
  # Set environment variables to be used for the analysis
  do.call(Sys.setenv, as.list(p))
  if(i==1){cat("Starting with the first...\n")}
  source("m-Main_TWO_Deltas.R")
  if(i!=1){cat("Starting with the next...\n")}
  if(i==50){cat("All done!")}
}
