]> git.vanrenterghem.biz Git - R/project-using-kafka-in-R.git/blobdiff - predictWebsiteHits.R
Create forecast.
[R/project-using-kafka-in-R.git] / predictWebsiteHits.R
index 4c2d65ccd7966743999f5659c5c0972668581c45..2a0d66e2e6f96b429a07495d91a92ce5bcb27aba 100644 (file)
@@ -2,17 +2,28 @@ library(jsonlite)
 library(fable)
 library(tsibble)
 library(lubridate)
 library(fable)
 library(tsibble)
 library(lubridate)
+library(ggplot2)
 
 
-logfile <- file("data/photos.vanrenterghem.biz.access.kvp.log")
+logfile <- file("data/photos.vanrenterghem.biz.access.kvp.log.1")
 
 apachelog <- stream_in(logfile)
 
 #apachelog$time <- gsub("\\[|\\]", "", apachelog$time)
 apachelog %>%
   mutate(time = gsub("\\[|\\]", "", time),
 
 apachelog <- stream_in(logfile)
 
 #apachelog$time <- gsub("\\[|\\]", "", apachelog$time)
 apachelog %>%
   mutate(time = gsub("\\[|\\]", "", time),
-           time = dmy_hms(time)) %>%
-  group_by(time) %>%
+         time = dmy_hms(time),
+         datehour = floor_date(time, unit = "hour") 
+         ) %>%
+  filter(time > ymd_h("2018-08-22 12")) %>%
+  group_by(datehour) %>%
   summarise(hits = n()) ->
   summarise(hits = n()) ->
-  apachelog
+  apachelog_tidy
+
+apachelog_tsbl <- as.tsibble(apachelog_tidy, index = datehour) 
+apachelog_tsbl %>%
+  ARIMA(log(hits)) %>%
+  forecast(h=5) %>%
+  autoplot +
+  ggtitle("Forecasting website hits using apache log only") +
+  xlab("Date time")
 
 
-as.tsibble(apachelog, index = time)