Libaries and reading in data.

library(shiny)
library(shinydashboard)
## 
## Attaching package: 'shinydashboard'
## The following object is masked from 'package:graphics':
## 
##     box
library(ggplot2)
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
library(DT)
## 
## Attaching package: 'DT'
## The following objects are masked from 'package:shiny':
## 
##     dataTableOutput, renderDataTable
library(jpeg)
library(grid)
library(reshape2)
library(leaflet)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:lubridate':
## 
##     intersect, setdiff, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
ColNames<- c("FL_DATE","AIRLINE_ID","CARRIER","ORIGIN_AIRPORT_ID","ORIGIN","ORIGIN_CITY_NAME","ORIGIN_STATE_NM","DEST_AIRPORT_ID","DEST_CITY_NAME","DEST_STATE_NM","DEP_TIME","DEP_DELAY","DEP_DELAY_NEW","ARR_TIME","ARR_DELAY","ARR_DELAY_NEW","CANCELLED","CANCELLATION_CODE","DIVERTED","ACTUAL_ELAPSED_TIME","FLIGHTS","DISTANCE","CARRIER_DELAY","WEATHER_DELAY","NAS_DELAY","SECURITY_DELAY","LATE_AIRCRAFT_DELAY")
AprilData<- read.table(file = "April_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(AprilData)<- ColNames
AugustData<- read.table(file = "August_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(AugustData)<- ColNames
DecemberData<- read.table(file = "December_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(DecemberData)<- ColNames
FebuaryData<- read.table(file = "Febuary_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(FebuaryData)<- ColNames
JanuaryData<- read.table(file = "January_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(JanuaryData)<- ColNames
JuneData<- read.table(file = "June_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(JuneData)<- ColNames
JulyData<- read.table(file = "July_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(JulyData)<- ColNames
MarchData<- read.table(file = "March_flights.cleaned.csv", header = FALSE,sep = '\t')
names(MarchData)<- ColNames
MayData<- read.table(file = "May_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(MayData)<- ColNames
NovemberData<- read.table(file = "November_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(NovemberData)<- ColNames
OctoberData<- read.table(file = "October_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(OctoberData)<- ColNames
SeptebmerData<- read.table(file = "September_flights.cleaned.csv", header = FALSE,sep = '\t') 
names(SeptebmerData)<- ColNames

allData <- rbind(AprilData, AugustData, DecemberData, FebuaryData, JanuaryData, JuneData, JulyData, MarchData, MayData, NovemberData, OctoberData, SeptebmerData)
#temp = list.files(pattern="*.csv")
#allData2 <- lapply(temp, read.delim, header = FALSE)
#allData3 <- do.call(rbind, allData2)
tem3 <- AugustData

 tem3$ARR_TIME <- sprintf("%04d", tem3$ARR_TIME)
  tem3$ARR_TIME_new <- as.POSIXct(paste(tem3$FL_DATE, tem3$ARR_TIME), format = "%Y-%m-%d %H%M" )

  tem3$hour <- lubridate::hour( tem3$ARR_TIME_new)
  tem3$day <- lubridate::day( tem3$ARR_TIME_new)
  tem3$week <- lubridate::week( tem3$ARR_TIME_new)
  
# table showing the total number of departures and total number of arrivals for each hour of the day across that month (i.e. how many from 9am to 10am summed over every day of that month) For MDW  
MDW_arr_day_hour <- group_by(tem3,day,hour)  %>% select(DEST_AIRPORT_ID) %>% filter(DEST_AIRPORT_ID == 13232 ) %>% summarise(number_arrival=n())
## Adding missing grouping variables: `day`, `hour`
MDW_dep_day_hour <- group_by(tem3,day,hour)  %>% select(ORIGIN_AIRPORT_ID) %>% filter(ORIGIN_AIRPORT_ID == 13232 ) %>% summarise(number_arrival=n())
## Adding missing grouping variables: `day`, `hour`
# table showing the total number of departures and total number of arrivals for each day of the week across that month (i.e. how many on all of the mondays of that month)
MDW_arr_week_day <- group_by(tem3,week,day)  %>% select(DEST_AIRPORT_ID) %>% filter(DEST_AIRPORT_ID == 13232 ) %>% summarise(number_arrival=n())
## Adding missing grouping variables: `week`, `day`
MDW_dep_week_day <- group_by(tem3,week,day)  %>% select(ORIGIN_AIRPORT_ID) %>% filter(ORIGIN_AIRPORT_ID == 13232 ) %>% summarise(number_arrival=n())
## Adding missing grouping variables: `week`, `day`
# ORD
ORD_arr_day_hour <- group_by(tem3,day,hour)  %>% select(DEST_AIRPORT_ID) %>% filter(DEST_AIRPORT_ID == 13930 ) %>% summarise(number_arrival=n())
## Adding missing grouping variables: `day`, `hour`
ORD_dep_day_hour <- group_by(tem3,day,hour)  %>% select(ORIGIN_AIRPORT_ID) %>% filter(ORIGIN_AIRPORT_ID == 13930 ) %>% summarise(number_arrival=n())
## Adding missing grouping variables: `day`, `hour`
#ORD
ORD_arr_week_day <- group_by(tem3,week,day)  %>% select(DEST_AIRPORT_ID) %>% filter(DEST_AIRPORT_ID == 13930 ) %>% summarise(number_arrival=n())
## Adding missing grouping variables: `week`, `day`
ORD_dep_week_day <- group_by(tem3,week,day)  %>% select(ORIGIN_AIRPORT_ID) %>% filter(ORIGIN_AIRPORT_ID == 13930 ) %>% summarise(number_arrival=n())
## Adding missing grouping variables: `week`, `day`
#MDW table showing the total number of delays for each hour of the day across that month (i.e. how many from 9am to 10am summed over every day of that month) 

MDW_delay_day_hour <- group_by(tem3,day,hour)  %>% select(DEST_AIRPORT_ID,ORIGIN_AIRPORT_ID,ARR_DELAY,DEP_DELAY) %>% filter((ARR_DELAY>0 | DEP_DELAY >0)&&(ORIGIN_AIRPORT_ID==13232 | DEST_AIRPORT_ID == 13232) ) %>% summarise(number_arrival_delay=n())
## Adding missing grouping variables: `day`, `hour`
ORD_delay_day_hour <- group_by(tem3,day,hour)  %>% select(DEST_AIRPORT_ID,ORIGIN_AIRPORT_ID,ARR_DELAY,DEP_DELAY) %>% filter((ARR_DELAY>0 | DEP_DELAY >0)&&(ORIGIN_AIRPORT_ID==13930 | DEST_AIRPORT_ID == 13930) ) %>% 
  
summarise(number_arrival_delay=n())
## Adding missing grouping variables: `day`, `hour`
head(MDW_arr_day_hour)
head(ORD_arr_day_hour)
head(MDW_dep_day_hour)
head(ORD_dep_day_hour)
head(MDW_arr_week_day)
head(ORD_arr_week_day)
head(MDW_dep_week_day)
head(ORD_dep_week_day)
head(MDW_delay_day_hour)
head(ORD_delay_day_hour)