Remove service addresses, add graph letters (#15513).
[tor-metrics-tasks.git] / task-4776 / advbw-cdf.R
blobc5969279088af3622de24aec205477360ddb46b7
1 library("RPostgreSQL")
2 library("DBI")
3 library("ggplot2")
4 library("proto")
5 library("grid")
6 library("reshape")
7 library("plyr")
8 library("digest")
10 db = "tordir"
11 dbuser = "metrics"
12 dbpassword= "password"
14 plot_advbw_cdf <- function(datetime, path, xlimit, dpi) {
15   drv <- dbDriver("PostgreSQL")
16   con <- dbConnect(drv, user = dbuser, password = dbpassword, dbname = db)
17   q <- paste("SELECT LEAST(descriptor.bandwidthavg, ",
18              "descriptor.bandwidthburst, ",
19              "descriptor.bandwidthobserved) AS advbw ",
20              "FROM statusentry ",
21              "RIGHT JOIN descriptor ",
22              "ON statusentry.descriptor = descriptor.descriptor ",
23              "WHERE statusentry.validafter = '", datetime, "' ",
24              "ORDER BY 1", sep = "")
25   rs <- dbSendQuery(con, q)
26   u <- fetch(rs, n = -1)
27   dbDisconnect(con)
28   dbUnloadDriver(drv)
29   ggplot(u, aes(x = sort(advbw / 1024),
30     y = (1:length(advbw)) / length(advbw))) +
31   geom_line(size = 1) +
32   scale_x_continuous(name = "\nAdvertised bandwidth in KiB/s",
33     limit = c(0, xlimit)) +
34   scale_y_continuous(formatter = "percent",
35     name = "Fraction of relays with that bandwidth or less\n") +
36   opts(title = paste(datetime, "\n", sep = ""))
37   ggsave(filename = path, width = 8, height = 5, dpi = as.numeric(dpi))
39 plot_advbw_cdf('2011-02-03 12:00:00', 'advbw-cdf-2011-02-03-12-00-00.png',
40   1024, 72)
41 plot_advbw_cdf('2011-03-03 12:00:00', 'advbw-cdf-2011-03-03-12-00-00.png',
42   1024, 72)
43 plot_advbw_cdf('2011-04-03 12:00:00', 'advbw-cdf-2011-04-03-12-00-00.png',
44   1024, 72)
45 plot_advbw_cdf('2011-05-03 12:00:00', 'advbw-cdf-2011-05-03-12-00-00.png',
46   1024, 72)
47 plot_advbw_cdf('2011-06-03 12:00:00', 'advbw-cdf-2011-06-03-12-00-00.png',
48   1024, 72)
49 plot_advbw_cdf('2011-07-03 12:00:00', 'advbw-cdf-2011-07-03-12-00-00.png',
50   1024, 72)
51 plot_advbw_cdf('2011-08-03 12:00:00', 'advbw-cdf-2011-08-03-12-00-00.png',
52   1024, 72)
53 plot_advbw_cdf('2011-09-03 12:00:00', 'advbw-cdf-2011-09-03-12-00-00.png',
54   1024, 72)
55 plot_advbw_cdf('2011-10-03 12:00:00', 'advbw-cdf-2011-10-03-12-00-00.png',
56   1024, 72)
57 plot_advbw_cdf('2011-11-03 12:00:00', 'advbw-cdf-2011-11-03-12-00-00.png',
58   1024, 72)
59 plot_advbw_cdf('2011-12-03 12:00:00', 'advbw-cdf-2011-12-03-12-00-00.png',
60   1024, 72)
61 plot_advbw_cdf('2012-01-03 12:00:00', 'advbw-cdf-2012-01-03-12-00-00.png',
62   1024, 72)