Browse Source

Leaflet proto on all requests

master
Maxime Wack 6 years ago
parent
commit
c9bd7b83f0
1 changed files with 15 additions and 0 deletions
  1. +15
    -0
      geoip.R

+ 15
- 0
geoip.R View File

@@ -1,6 +1,8 @@
library(tidyverse)
library(RSQLite)
library(ipapi)
library(leaflet)

# sqlite3 access.db
# create table access(ip, null1, user, timestamp, zone, req, status, size, referer, agent, null2);
# .separator " "
@@ -36,3 +38,16 @@ if (length(ips) > 0)
dbConnect(SQLite(), "access.db") %>%
dbWriteTable("geoip", geoip, append = T)
}

src_sqlite("access.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) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addMarkers(~lon, ~lat, clusterOptions = markerClusterOptions())

Loading…
Cancel
Save