From 4baa93ffcdfcd96361dd0d36d7ad5538acf530ce Mon Sep 17 00:00:00 2001 From: Maxime Wack Date: Wed, 17 Jan 2018 18:04:42 +0000 Subject: [PATCH] Map prototype --- geoip.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/geoip.R b/geoip.R index 7b151b9..3cf7b9a 100644 --- a/geoip.R +++ b/geoip.R @@ -38,15 +38,15 @@ if (length(ips) > 0) dbWriteTable(conn = db, name = "geoip", value = ., append = T) } -src_sqlite("access.db") %>% +db %>% tbl("access") %>% - collect %>% - left_join(geoip, by = c("ip" = "query")) %>% - select(-null1, -user, -zone, -size, -null2, -as, -countryCode, -org, -region, -regionName, -status.y, -timezone, -zip, -isp) %>% - mutate(timestamp = timestamp %>% str_sub(2) %>% as.POSIXct(format = "%d/%b/%Y:%H:%M:%S"), - req = req %>% str_replace("(HEAD|GET|POST) ", ""), - req = req %>% str_replace("/(.*?/).*", "\\1")) -> geoaccess - -leaflet(data = geoaccess) %>% + left_join(db %>% tbl("geoip")) %>% + collect -> geoaccess + +geoaccess %>% + filter(status != 404, + !agent %>% str_detect("bot")) %>% + distinct(ip, lon, lat) %>% + leaflet %>% addProviderTiles(providers$CartoDB.Positron) %>% addMarkers(~lon, ~lat, clusterOptions = markerClusterOptions())