# Script to generate folders that will contain images, one for each seat.
# Script should only be needed to run once.

# Load the booth data:
years <- c(1993, 1996, 1998, 2001, 2004, 2007, 2010)
for (cal_year in years) {
  print(sprintf("Loading data, %d", cal_year))
  seatboothfile_str <- sprintf("booths_data/%d.csv", cal_year)
  boothfile_str <- sprintf("booths_summing_dups/%d.csv", cal_year)
  if (cal_year == years[1]) {
    seatbooth.data <- read.csv(file=seatboothfile_str, header=T, sep=",")
    seatbooth.data$Year <- cal_year
  } else {
    temp.data <- read.csv(file=seatboothfile_str, header=T, sep=",")
    temp.data$Year <- cal_year
    seatbooth.data <- merge(seatbooth.data, temp.data, all=T)
    rm(temp.data)
  }
}
rm(temp.data)

# Convert factors to strings:
i <- sapply(seatbooth.data, is.factor)
seatbooth.data[i] <- lapply(seatbooth.data[i], as.character)

# Remove hyphens from "Kingsford-Smith":
seatbooth.data$Seat[which(seatbooth.data$Seat == "Kingsford-Smith")] <- "Kingsford Smith"

seats <- unique(seatbooth.data$Seat)

for(seat in seats) {
  # Uncomment the shell calls to actually make the folders.
  
  shell_str <- sprintf("mkdir images\\\"%s\"", seat)
  shell(shell_str)
  shell_str <- sprintf("mkdir shapefiles\\seats\\\"%s\"", seat)
  shell(shell_str)
}
