Add comments and variables for clarity.
[R/project-using-kafka-in-R.git] / predictWebsiteHits.R
1 library(fable)
2 library(tsibble)
3 library(lubridate)
4 library(ggplot2)
6 createPlot <- function(x){
7 x %>%
8   mutate(time = gsub("\\[|\\]", "", time),
9          time = dmy_hms(time),
10          datehour = floor_date(time, unit = "hour") 
11          ) %>%
12   filter(time > ymd_h("2018-08-22 12")) %>%
13   group_by(datehour) %>%
14   summarise(hits = n()) ->
15   apachelog_tidy
17 apachelog_tsbl <- as.tsibble(apachelog_tidy, index = datehour) 
18 apachelog_tsbl %>%
19   ARIMA(log(hits)) %>%
20   forecast(h=5) %>%
21   autoplot +
22   ggtitle("Forecasting website hits using apache log only") +
23   xlab("Date time")
24 }