-
Notifications
You must be signed in to change notification settings - Fork 33
/
plot-access-by-time.R
executable file
·65 lines (54 loc) · 1.71 KB
/
plot-access-by-time.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# libs --------------------------------------------------------------------
library(magrittr)
library(ggplot2)
library(lubridate)
# load log ----------------------------------------------------------------
args <- commandArgs(TRUE)
filename <- "/home/liucj/tmp/stat-web-access/gscalite-2018-07-09.log"
filename <- args[1]
filename %>%
readr::read_delim(delim = " ", col_names = FALSE ) %>%
dplyr::rename(ip = X1, date = X2) %>%
dplyr::mutate(date = lubridate::dmy(date)) %>%
dplyr::distinct() %>%
dplyr::arrange(date) ->
log
span <- months(1)
span_seq <- "1 month"
# count by time span ------------------------------------------------------
span_count <- function(.x, .y = log, .s = span) {
.x_1 <- .x + .s
sum(.y$date >= .x & .y$date < .x_1)
}
seq(log$date[1], tail(log$date, 1), by = span_seq) %>%
tibble::as_tibble() %>%
dplyr::rename(date = value) %>%
dplyr::mutate(n = purrr::map_int(.x = date, .f = span_count, .y = log, .s = span)) %>%
dplyr::mutate(month = format.Date(date, "%Y-%m")) %>%
range_time
range_time %>%
ggplot(aes(date, y = n)) +
geom_point() +
geom_line() +
scale_x_date(date_breaks = span_seq, labels = scales::date_format("%Y-%m-%d")) +
theme_minimal() +
labs(
x = "Months",
y = "Access count"
) +
theme(
panel.grid = element_blank(),
axis.text.x = element_text(angle = 90, hjust = 1, vjust = -0.5),
axis.text = element_text(size = 22),
axis.title = element_text(size = 24),
axis.line = element_line(),
axis.ticks.y = element_line()
) ->
plot_time_seria
ggsave(
filename = paste(sub(pattern = ".log", "", filename),'time-seria.pdf', sep = "-"),
plot = plot_time_seria,
device = "pdf",
width = 5,
height = 5
)