Verified Commit 47f1f4a0 authored by hrbrmstr's avatar hrbrmstr 馃泴
Browse files

general cleanup

parent a2a22872
......@@ -5,8 +5,14 @@
^README\.*html$
^NOTES\.*Rmd$
^NOTES\.*html$
^README\.gfm*$
^README_cache$
^\.codecov\.yml$
^README_files$
^doc$
^CONDUCT\.md$
^imgs$
\ No newline at end of file
^imgs$
^LICENSE\.md$
^Makefile$
^appveyor\.yml$
language: r
warnings_are_errors: true
sudo: required
language: R
cache: packages
r:
- oldrel
- release
- devel
apt_packages:
- libv8-dev
- xclip
env:
global:
- CRAN: http://cran.rstudio.com
after_success:
- Rscript -e 'covr::codecov()'
notifications:
email:
- bob@rud.is
irc:
channels:
- "104.236.112.222#builds"
nick: travisci
- Rscript -e 'covr::codecov()'
\ No newline at end of file
Package: speedtest
Type: Package
Title: Tools to Test and Compare Internet Bandwidth Speeds
Version: 0.1.0
Date: 2017-11-09
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5670-2640")),
person("Bryce", "Mecum", email = "petridish@gmail.com", role = "ctb",
comment = c(ORCID = "0000-0002-0381-3766")),
person("Garrett", "Mooney", email = "gmooney@mail.bradley.edu", role = "ctb")
)
Author: Bob Rudis (bob@rud.is)
Version: 0.2.0
Date: 2019-07-24
Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is",
role = c("aut", "cre"), comment = c(ORCID =
"0000-0001-5670-2640")), person("Bryce", "Mecum",
email = "petridish@gmail.com", role = "ctb", comment
= c(ORCID = "0000-0002-0381-3766")),
person("Garrett", "Mooney", email =
"gmooney@mail.bradley.edu", role = "ctb") )
Maintainer: Bob Rudis <bob@rud.is>
Description: The 'Ookla' 'Speedtest' site <http://beta.speedtest.net/about> provides
interactive and programmatic services to test and compare bandwidth speeds from
a source node on the Internet to thousands of test servers. Tools are provided
to obtain test server lists, identify target servers for testing and performing
speed/bandwidth tests.
URL: https://github.com/hrbrmstr/speedtest
BugReports: https://github.com/hrbrmstr/speedtest/issues
License: AGPL
Suggests:
testthat,
covr
Depends:
R (>= 3.2.0)
Description: The 'Ookla' 'Speedtest' site
<http://beta.speedtest.net/about> provides
interactive and programmatic services to test and
compare bandwidth speeds from a source node on the
Internet to thousands of test servers. Tools are
provided to obtain test server lists, identify target
servers for testing and performing speed/bandwidth
tests.
URL: https://gitlab.com/hrbrmstr/speedtest
BugReports: https://gitlab.com/hrbrmstr/speedtest/issues
License: MIT + file LICENSE
Suggests: covr, tinytest
Depends: R (>= 3.2.0)
Encoding: UTF-8
Imports:
curl,
purrr,
dplyr,
xml2,
utils,
pingr,
urltools,
jsonlite,
crayon,
cli
RoxygenNote: 6.0.1
Imports: httr, stats, curl, purrr, dplyr, xml2, utils,
pingr, urltools, jsonlite, crayon, tibble, cli,
magrittr
RoxygenNote: 6.1.1
YEAR: 2019
COPYRIGHT HOLDER: Bob Rudis
# MIT License
Copyright (c) 2019 Bob Rudis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Generated by roxygen2: do not edit by hand
export("%>%")
export(nice_speed)
export(spd_best_servers)
export(spd_closest_servers)
export(spd_compute_bandwidth)
......@@ -16,13 +18,16 @@ import(xml2)
importFrom(curl,curl_fetch_multi)
importFrom(curl,multi_run)
importFrom(dplyr,arrange)
importFrom(dplyr,data_frame)
importFrom(dplyr,filter)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")
importFrom(pingr,ping)
importFrom(stats,median)
importFrom(stats,sd)
importFrom(tibble,tibble)
importFrom(urltools,domain)
importFrom(utils,globalVariables)
0.2.0
* Updated pkg infrastructure (non-salient to operations)
* Now passes CRAN checks
* Updated user agent
* Ensured primary URLs for speedtest resources are HTTPS
* Swiched to {tinytest}
0.1.0
* Initial release
.base_raw <- charToRaw('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ')
.speedtest_ua <- "Mozilla/5.0 (Compatibe; r-speedtest/1.0; https://github.com/hrbrmstr/speedtest)"
.speedtest_ua <- "Mozilla/5.0 (Compatible; r-speedtest/1.0; https://gitlab.com/hrbrmstr/speedtest)"
utils::globalVariables(
c("total", "latency_url", "test_result", "ping_time", "total_time", "retrieval_time",
"bw", "size", "secs"))
\ No newline at end of file
c(
"total", "latency_url", "test_result", "ping_time", "total_time",
"retrieval_time", "bw", "size", "secs", "id"
)
)
sGET <- purrr::safely(httr::GET)
sPOST <- purrr::safely(httr::POST)
......@@ -41,8 +41,9 @@ spd_best_servers <- function(servers=NULL, config=NULL, max=10) {
curl::multi_run()
purrr::map_df(.lat_dat, ~{
data_frame(
tibble(
latency_url = .x$url,
# TODO add some code to let this be a thing
# ping_time = mean(pingr::ping(urltools::domain(.x$url)), na.rm=TRUE)/1000,
total_time = .x$times["total"],
retrieval_time = .x$times[6] - .x$times[5],
......
......@@ -7,7 +7,10 @@
#' }
spd_config <- function() {
res <- httr::GET("http://www.speedtest.net/speedtest-config.php")
httr::GET(
url = "https://www.speedtest.net/speedtest-config.php",
httr::user_agent(.speedtest_ua)
) -> res
httr::stop_for_status(res)
......
......@@ -11,15 +11,18 @@
#' }
spd_servers <- function(config=NULL) {
res <- httr::GET("https://www.speedtest.net/speedtest-servers-static.php")
httr::GET(
url = "https://www.speedtest.net/speedtest-servers-static.php",
httr::user_agent(.speedtest_ua)
) -> res
httr::stop_for_status(res)
if (is.null(config)) config <- spd_config()
httr::content(res, as="text", encoding="UTF-8") %>%
read_xml() %>%
xml2::xml_find_all(xpath="//settings/servers/server") %>%
httr::content(res, as = "text", encoding = "UTF-8") %>%
xml2::read_xml() %>%
xml2::xml_find_all(xpath = "//settings/servers/server") %>%
purrr::map_df(~{
list(
url = xml2::xml_attr(.x, "url") %||% NA_character_,
......
#' Tools to Test and Compare Internet Bandwidth Speeds
#'
#' The 'Ookla' 'Speedtest' site <http://beta.speedtest.net/about> provides
#' The 'Ookla' 'Speedtest' site <https://beta.speedtest.net/about> provides
#' interactive and programmatic services to test and compare bandwidth speeds
#' from a source node on the Internet to thousands of test servers. Tools are
#' provided to obtain test server lists, identify target servers for testing and
......@@ -12,9 +12,11 @@
#' @author Bob Rudis (bob@@rud.is)
#' @import purrr xml2 httr cli crayon
#' @importFrom utils globalVariables
#' @importFrom dplyr left_join arrange filter data_frame select summarise mutate
#' @importFrom tibble tibble
#' @importFrom dplyr left_join arrange filter select summarise mutate
#' @importFrom jsonlite fromJSON
#' @importFrom curl curl_fetch_multi multi_run
#' @importFrom pingr ping
#' @importFrom urltools domain
NULL
#' @importFrom stats median sd
"_PACKAGE"
......@@ -22,15 +22,17 @@ spd_test <- function() {
cat(cyan("Determining best server...\n"))
servers <- spd_closest_servers(servers, config)
# best <- servers
# best <- servers
best <- spd_best_servers(servers, config, max=3)
cat(green("Initiating test from ") %+% white(config$client$isp) %+% green(" (") %+%
white(config$client$ip) %+% green(") to ") %+% white(best$sponsor[1]) %+%
green(" (") %+% white(best$name[1]) %+% green(")\n\n"))
cat(
green("Initiating test from ") %+% white(config$client$isp) %+% green(" (") %+%
white(config$client$ip) %+% green(") to ") %+% white(best$sponsor[1]) %+%
green(" (") %+% white(best$name[1]) %+% green(")\n\n")
)
cat(white$bold("Analyzing download speed"))
down <- spd_download_test(best, config, FALSE, timeout=5, .progress="dots")
down <- spd_download_test(best, config, FALSE, timeout = 5, .progress = "dots")
cat(green("Download: ") %+% white$bold(nice_speed(max(down$bw))) %+% "\n")
......
......@@ -25,7 +25,8 @@
#' @note speed/bandwidth values are in Mbits/s; these tests consume bandwidth so
#' if you're on a metered connection, you may incur charges.
#' @export
spd_upload_test <- function(server, config=NULL, summarise=TRUE, timeout=60, .progress="dplyr") {
spd_upload_test <- function(server, config = NULL, summarise = TRUE, timeout=60,
.progress = "dplyr") {
if (nrow(server) > 1) server <- server[1,]
......@@ -55,9 +56,14 @@ spd_upload_test <- function(server, config=NULL, summarise=TRUE, timeout=60, .pr
if (.progress == 'dots') cat("\n", sep="")
if (summarise) {
out <- dplyr::summarise(out, min=min(bw, na.rm=TRUE), mean=mean(bw, na.rm=TRUE),
median=median(bw, na.rm=TRUE), max=max(bw, na.rm=TRUE),
sd=sd(bw, na.rm=TRUE))
dplyr::summarise(
out,
min = min(bw, na.rm = TRUE),
mean = mean(bw, na.rm = TRUE),
median = median(bw, na.rm = TRUE),
max = max(bw, na.rm = TRUE),
sd = sd(bw, na.rm = TRUE)
) -> out
}
out$id <- server$id
......
sGET <- purrr::safely(httr::GET)
sPOST <- purrr::safely(httr::POST)
.download_one <- function(url, timeout) {
sGET(
url = url,
httr::add_headers(
`Referer` = "http://c.speedtest.net/flash/speedtest.swf",
`Referer` = "https://c.speedtest.net/flash/speedtest.swf",
`Cache-Control` = "no-cache" # try to bust transparent proxy caches
),
httr::user_agent(.speedtest_ua),
httr::timeout(timeout),
query=list(ts=as.numeric(Sys.time())) # try to bust transparent proxy caches
query = list(ts = as.numeric(Sys.time())) # try to bust transparent proxy caches
)
}
......@@ -19,15 +15,15 @@ sPOST <- purrr::safely(httr::POST)
sPOST(
url = url,
httr::add_headers(
`Referer` = "http://c.speedtest.net/flash/speedtest.swf",
`Referer` = "https://c.speedtest.net/flash/speedtest.swf",
`Connection` = "Keep-Alive",
`Cache-Control` = "no-cache" # try to bust transparent proxy caches
),
encode="form",
body=dat,
body = dat,
httr::user_agent(.speedtest_ua),
httr::timeout(timeout),
query=list(ts=as.numeric(Sys.time())) # try to bust transparent proxy caches
query = list(ts = as.numeric(Sys.time())) # try to bust transparent proxy caches
)
}
......@@ -38,6 +34,7 @@ sPOST <- purrr::safely(httr::POST)
#' - Only chooses between Kbit/s, Mbit/s, and Gbit/s
#'
#' @param number numeric The speed to be converted
#' @export
#' @return character The character representation of the speed
nice_speed <- function(number) {
if (number < 1) {
......
---
title: "speedtest"
output:
github_document:
html_preview: true
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
```{r include=FALSE}
knitr::opts_chunk$set(cache=TRUE, message=FALSE, warning=FALSE, error=FALSE, fig.retina=2)
```{r pkg-knitr-opts, include=FALSE}
hrbrpkghelpr::global_opts()
```
```{r badges, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::stinking_badges()
```
# speedtest
Tools to Test and Compare Internet Bandwidth Speeds
## Description
The 'Ookla' 'Speedtest' site <http://beta.speedtest.net/about> provides
interactive and programmatic services to test and compare bandwidth speeds from
a source node on the Internet to thousands of test servers. Tools are provided
to obtain test server lists, identify target servers for testing and performing
speed/bandwidth tests.
The 'Ookla' 'Speedtest' site <http://beta.speedtest.net/about> provides interactive and programmatic services to test and compare bandwidth speeds from a source node on the Internet to thousands of test servers. Tools are provided to obtain test server lists, identify target servers for testing and performing speed/bandwidth tests.
## What's Inside The Tin
The following functions are implemented:
- `spd_best_servers`: Find "best" servers (latency-wise) from master server list
- `spd_closest_servers`: Find "closest" servers (geography-wise) from master server list
- `spd_compute_bandwidth`: Compute bandwidth from bytes transferred and time taken
- `spd_config`: Retrieve client configuration information for the speedtest
- `spd_download_test`: Perform a download speed/bandwidth test
- `spd_servers`: Retrieve a list of SpeedTest servers
- `spd_upload_test`: Perform an upload speed/bandwidth test
- `spd_test`: Test your internet speed/bandwidth
```{r ingredients, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::describe_ingredients()
```
## Make a CLI utility
......@@ -38,7 +36,7 @@ While you can run `spd_test()` from an R console, it was desgined to be an easil
which will look something like:
![](imgs/spdtst.gif)
![](man/figures/spdtst.gif)
## TODO
......@@ -56,17 +54,13 @@ Folks interested in contributing can take a look at the TODOs and pick as many a
## Installation
```{r eval=FALSE}
devtools::install_github("hrbrmstr/speedtest")
```
```{r}
options(width=120)
```{r install-ex, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::install_block()
```
## Usage
```{r cache=FALSE}
```{r libs, cache=FALSE}
library(speedtest)
library(stringi)
library(hrbrthemes)
......@@ -79,7 +73,7 @@ packageVersion("speedtest")
### Download Speed
```{r}
```{r dl-speeed, cache=TRUE}
config <- spd_config()
servers <- spd_servers(config=config)
......@@ -89,7 +83,7 @@ only_the_best_severs <- spd_best_servers(closest_servers, config)
### Individual download tests
```{r}
```{r individ-dl, cache=TRUE}
glimpse(spd_download_test(closest_servers[1,], config=config))
glimpse(spd_download_test(only_the_best_severs[1,], config=config))
......@@ -97,7 +91,7 @@ glimpse(spd_download_test(only_the_best_severs[1,], config=config))
### Individual upload tests
```{r}
```{r individ-up, cache=TRUE}
glimpse(spd_upload_test(only_the_best_severs[1,], config=config))
glimpse(spd_upload_test(closest_servers[1,], config=config))
......@@ -107,7 +101,7 @@ glimpse(spd_upload_test(closest_servers[1,], config=config))
Choose closest, "best" and randomly (there can be, and are, some dups as a result for best/closest), run the test and chart the results. This will show just how disparate the results are from these core/crude tests. Most of the test servers compensate when they present the results. Newer, "socket"-based tests are more accurate but there are no free/hidden exposed APIs yet for most of them.
```{r}
```{r moar-dl-tests, cache=TRUE}
set.seed(8675309)
bind_rows(
......@@ -127,15 +121,11 @@ bind_rows(
ungroup() -> to_compare
select(to_compare, sponsor, name, country, host, type)
```
```{r}
map_df(1:nrow(to_compare), ~{
spd_download_test(to_compare[.x,], config=config, summarise=FALSE, timeout=30)
}) -> dl_results_full
```
```{r}
mutate(dl_results_full, type=stri_trans_totitle(type)) %>%
ggplot(aes(type, bw, fill=type)) +
geom_quasirandom(aes(size=size, color=type), width=0.15, shape=21, stroke=0.25) +
......@@ -153,7 +143,7 @@ mutate(dl_results_full, type=stri_trans_totitle(type)) %>%
Choose closest and "best" and filter duplicates out since we're really trying to measure here vs show the disparity:
```{r}
```{r moar-ul-tests, cache=TRUE}
bind_rows(
closest_servers[1:3,] %>% mutate(type="closest"),
only_the_best_severs[1:3,] %>% mutate(type="best")
......@@ -165,9 +155,7 @@ select(to_compare, sponsor, name, country, host, type)
map_df(1:nrow(to_compare), ~{
spd_upload_test(to_compare[.x,], config=config, summarise=FALSE, timeout=30)
}) -> ul_results_full
```
```{r}
ggplot(ul_results_full, aes(x="Upload Test", y=bw)) +
geom_quasirandom(aes(size=size, fill="col"), width=0.1, shape=21, stroke=0.25, color="#2b2b2b") +
scale_y_continuous(expand=c(0,0.5)) +
......@@ -181,10 +169,10 @@ ggplot(ul_results_full, aes(x="Upload Test", y=bw)) +
## speedtest Metrics
```{r echo=FALSE}
```{r cloc, echo=FALSE}
cloc::cloc_pkg_md()
```
## Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms.
\ No newline at end of file
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
\ No newline at end of file
speedtest
================
Tools to Test and Compare Internet Bandwidth Speeds
## Description
The 鈥極okla鈥 鈥楽peedtest鈥 site <http://beta.speedtest.net/about> provides
interactive and programmatic services to test and compare bandwidth
speeds from a source node on the Internet to thousands of test servers.
Tools are provided to obtain test server lists, identify target servers
for testing and performing speed/bandwidth tests.
## What鈥檚 Inside The Tin
The following functions are implemented:
- `spd_best_servers`: Find 鈥渂est鈥 servers (latency-wise) from master
server list
- `spd_closest_servers`: Find 鈥渃losest鈥 servers (geography-wise) from
master server list
- `spd_compute_bandwidth`: Compute bandwidth from bytes transferred
and time taken
- `spd_config`: Retrieve client configuration information for the
speedtest
- `spd_download_test`: Perform a download speed/bandwidth test
- `spd_servers`: Retrieve a list of SpeedTest servers
- `spd_upload_test`: Perform an upload speed/bandwidth test
- `spd_test`: Test your internet speed/bandwidth
## Make a CLI utility
While you can run `spd_test()` from an R console, it was desgined to be
an easily wrapped into a `bash` (et al) alias or put into a small batch
script. Or, you can just type out the following if you鈥檙e
fleet-of-finger/have dexterous digits:
Rscript --quiet -e 'speedtest::spd_test()'
which will look something like:
![](imgs/spdtst.gif)
## TODO
Folks interested in contributing can take a look at the TODOs and pick
as many as you like\! Ones with question marks are truly a 鈥淚 dunno if
we shld鈥 kinda thing. Ones with exclamation marks are essentials.
- \[ \] Cache config in memory at startup vs pass around to functions?
- \[ \] Figure out how to use beta sockets hidden API vs the old Flash
API?
- \[ \] Ensure the efficacy of relying on the cURL timings for speed
measures for the Flash API
- \[ \] Figure out best way to capture the results for post-processing
- \[ \] Upload results to speedtest (tis only fair)\!
- \[ \] Incorporate more network or host measures for better
statistical determination of the best target\!
- \[ \] `autoplot` support\!
- \[ \] RStudio Add-in
- \[ \] Shiny app?
## Installation
``` r
devtools::install_github("hrbrmstr/speedtest")
```
``` r