Verified Commit 90bf48db authored by hrbrmstr's avatar hrbrmstr 馃泴
Browse files

cli

parent 38718d89
......@@ -16,3 +16,5 @@
^Makefile$
^appveyor\.yml$
^cran-comments\.md$
^CRAN-RELEASE$
This package was submitted to CRAN on 2019-07-24.
Once it is accepted, delete this file and tag the release (commit 38718d8910).
Package: speedtest
Type: Package
Title: Tools to Test and Compare Internet Bandwidth Speeds
Version: 0.2.0
Date: 2019-07-24
Version: 0.3.0
Date: 2020-03-19
Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is",
role = c("aut", "cre"), comment = c(ORCID =
"0000-0001-5670-2640")), person("Bryce", "Mecum",
......@@ -28,4 +28,4 @@ Encoding: UTF-8
Imports: httr, stats, curl, purrr, dplyr, xml2, utils,
pingr, urltools, jsonlite, crayon, tibble, cli,
magrittr
RoxygenNote: 6.1.1
RoxygenNote: 7.0.2
# Generated by roxygen2: do not edit by hand
S3method(print,speedtest_cli_result)
export("%>%")
export(install_speedtest_cli)
export(nice_speed)
export(spd_best_servers)
export(spd_closest_servers)
......@@ -10,6 +12,7 @@ export(spd_download_test)
export(spd_servers)
export(spd_test)
export(spd_upload_test)
export(speedtest_cli)
import(cli)
import(crayon)
import(httr)
......@@ -26,8 +29,10 @@ importFrom(dplyr,summarise)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")
importFrom(pingr,ping)
importFrom(scales,label_number_si)
importFrom(stats,median)
importFrom(stats,sd)
importFrom(tibble,tibble)
importFrom(urltools,domain)
importFrom(utils,browseURL)
importFrom(utils,globalVariables)
#' Provides instructions for installing the official speedtest CLI application
#'
#' @export
install_speedtest_cli <- function() {
utils::browseURL("https://www.speedtest.net/apps/cli")
warning(
"You will need to run speedtest once manually so you ",
"can accept the Ookla license. Failure to do so will ",
"result in errors generated by the use of speedtest_cli().",
call. = FALSE
)
}
\ No newline at end of file
#' Perform an official Ookla Speed Test via their command line tools
#'
#' @export
speedtest_cli <- function(progress = TRUE) {
spdtst <- Sys.which(c("speedtest", "speedtest.exe"))
spdtst <- spdtst[spdtst != ""]
if (length(spdtst) == 0) {
stop(
"speedtest cli executable not found. ",
"Use install_speedtest_cli() to install it.",
call. = FALSE
)
}
progress <- if (progress[1]) "yes" else "no"
progress <- sprintf("--progress=%s", progress)
args <- c(progress, "--format=jsonl")
system2(
spdtst,
args = args,
TRUE
) -> res
res <- lapply(res, jsonlite::fromJSON)
download <- list()
upload <- list()
result <- list()
for (.x in res) {
if (.x$type == "download") {
download <- append(download, list(.x))
} else if (.x$type == "upload") {
upload <- append(upload, list(.x))
} else {
result <- append(result, list(.x))
}
}
list(
download = dplyr::bind_rows(lapply(download, dplyr::as_tibble)),
upload = dplyr::bind_rows(lapply(upload, dplyr::as_tibble)),
result = result
) -> res
class(res) <- c("speedtest_cli_result")
res
}
#' @rdname speedtest_cli
#' @param x `speedtest_cli_result` object
#' @param browse if `TRUE`, open a browser window with the results
#' @param ... ignored
#' @export
print.speedtest_cli_result <- function(x, browse = FALSE, ...) {
fmt <- scales::label_number_si(accuracy = 0.001, unit = "")
cat(
"Provider: ", x$result[[7]]$isp, "\n",
" Ping: ", x$result[[7]]$ping$latency, " ms\n",
"Download: ", fmt(x$result[[7]]$download$bytes), "\n",
" Upload: ", fmt(x$result[[7]]$upload$bytes), "\n",
" URL: ", x$result[[7]]$result$url,
sep = ""
)
if (browse) utils::browseURL(x$result[[7]]$result$url)
}
......@@ -11,7 +11,7 @@
#' @docType package
#' @author Bob Rudis (bob@@rud.is)
#' @import purrr xml2 httr cli crayon
#' @importFrom utils globalVariables
#' @importFrom utils globalVariables browseURL
#' @importFrom tibble tibble
#' @importFrom dplyr left_join arrange filter select summarise mutate
#' @importFrom jsonlite fromJSON
......@@ -19,4 +19,5 @@
#' @importFrom pingr ping
#' @importFrom urltools domain
#' @importFrom stats median sd
#' @importFrom scales label_number_si
"_PACKAGE"
......@@ -32,6 +32,8 @@ for testing and performing speed/bandwidth tests.
The following functions are implemented:
- `install_speedtest_cli`: Provides instructions for installing the
official speedtest CLI application
- `nice_speed`: Convert a test speed, in Mbits/s, to its string
representation along with appropriate units for the magnitude of the
test speed
......@@ -47,6 +49,8 @@ The following functions are implemented:
- `spd_servers`: Retrieve a list of SpeedTest servers
- `spd_test`: Test your internet speed/bandwidth
- `spd_upload_test`: Perform an upload speed/bandwidth test
- `speedtest_cli`: Perform an official Ookla Speed Test via their
command line tools
## Make a CLI utility
......@@ -83,7 +87,7 @@ we shld鈥 kinda thing. Ones with exclamation marks are essentials.
## Installation
``` r
install.packages("speedtest", repos = "https://cinc.rud.is")
install.packages("speedtest", repos = c("https://cinc.rud.is", "https://cloud.r-project.org/"))
# or
remotes::install_git("https://git.rud.is/hrbrmstr/speedtest.git")
# or
......@@ -110,7 +114,7 @@ library(tidyverse)
# current verison
packageVersion("speedtest")
## [1] '0.2.0'
## [1] '0.3.0'
```
### Download Speed
......@@ -129,27 +133,27 @@ only_the_best_severs <- spd_best_servers(closest_servers, config)
glimpse(spd_download_test(closest_servers[1,], config=config))
## Observations: 1
## Variables: 15
## $ url <chr> "http://oak-speedtest.otelco.com:8080/speedtest/upload.php"
## $ lat <dbl> 43.6614
## $ lng <dbl> -70.2558
## $ name <chr> "Portland, ME"
## $ url <chr> "http://speedtest.peregrinenetworks.net:8080/speedtest/upload.php"
## $ lat <dbl> 42.9956
## $ lng <dbl> -71.4548
## $ name <chr> "Manchester, NH"
## $ country <chr> "United States"
## $ cc <chr> "US"
## $ sponsor <chr> "Otelco"
## $ id <chr> "1037"
## $ host <chr> "oak-speedtest.otelco.com:8080"
## $ url2 <chr> "http://66.181.127.42/speedtest/upload.php"
## $ min <dbl> 12.16723
## $ mean <dbl> 14.91807
## $ median <dbl> 14.57376
## $ max <dbl> 17.30854
## $ sd <dbl> 1.736132
## $ sponsor <chr> "Peregrine Networks"
## $ id <chr> "30644"
## $ host <chr> "speedtest.peregrinenetworks.net:8080"
## $ url2 <chr> NA
## $ min <dbl> 17.00748
## $ mean <dbl> 63.20918
## $ median <dbl> 66.31945
## $ max <dbl> 81.70783
## $ sd <dbl> 18.60229
glimpse(spd_download_test(only_the_best_severs[1,], config=config))
## Observations: 1
## Variables: 17
## $ total_time <dbl> 0.075129
## $ retrieval_time <dbl> 2.8e-05
## $ total_time <dbl> 0.082232
## $ retrieval_time <dbl> 3.2e-05
## $ url <chr> "http://stosat-ndhm-01.sys.comcast.net:8080/speedtest/upload.php"
## $ lat <dbl> 42.3578
## $ lng <dbl> -71.0617
......@@ -160,11 +164,11 @@ glimpse(spd_download_test(only_the_best_severs[1,], config=config))
## $ id <chr> "1774"
## $ host <chr> "stosat-ndhm-01.sys.comcast.net:8080"
## $ url2 <chr> "http://a-stosat-ndhm-01.sys.comcast.net/speedtest/upload.php"
## $ min <dbl> 14.49186
## $ mean <dbl> 17.68452
## $ median <dbl> 16.75617
## $ max <dbl> 24.3737
## $ sd <dbl> 2.987197
## $ min <dbl> 10.76603
## $ mean <dbl> 38.85852
## $ median <dbl> 39.13755
## $ max <dbl> 70.70089
## $ sd <dbl> 20.80209
```
### Individual upload tests
......@@ -173,8 +177,8 @@ glimpse(spd_download_test(only_the_best_severs[1,], config=config))
glimpse(spd_upload_test(only_the_best_severs[1,], config=config))
## Observations: 1
## Variables: 17
## $ total_time <dbl> 0.075129
## $ retrieval_time <dbl> 2.8e-05
## $ total_time <dbl> 0.082232
## $ retrieval_time <dbl> 3.2e-05
## $ url <chr> "http://stosat-ndhm-01.sys.comcast.net:8080/speedtest/upload.php"
## $ lat <dbl> 42.3578
## $ lng <dbl> -71.0617
......@@ -185,30 +189,30 @@ glimpse(spd_upload_test(only_the_best_severs[1,], config=config))
## $ id <chr> "1774"
## $ host <chr> "stosat-ndhm-01.sys.comcast.net:8080"
## $ url2 <chr> "http://a-stosat-ndhm-01.sys.comcast.net/speedtest/upload.php"
## $ min <dbl> 9.951216
## $ mean <dbl> 20.33949
## $ median <dbl> 22.11265
## $ max <dbl> 23.4545
## $ sd <dbl> 5.148238
## $ min <dbl> 8.765322
## $ mean <dbl> 18.67036
## $ median <dbl> 20.3484
## $ max <dbl> 23.0133
## $ sd <dbl> 5.342232
glimpse(spd_upload_test(closest_servers[1,], config=config))
## Observations: 1
## Variables: 15
## $ url <chr> "http://oak-speedtest.otelco.com:8080/speedtest/upload.php"
## $ lat <dbl> 43.6614
## $ lng <dbl> -70.2558
## $ name <chr> "Portland, ME"
## $ url <chr> "http://speedtest.peregrinenetworks.net:8080/speedtest/upload.php"
## $ lat <dbl> 42.9956
## $ lng <dbl> -71.4548
## $ name <chr> "Manchester, NH"
## $ country <chr> "United States"
## $ cc <chr> "US"
## $ sponsor <chr> "Otelco"
## $ id <chr> "1037"
## $ host <chr> "oak-speedtest.otelco.com:8080"
## $ url2 <chr> "http://66.181.127.42/speedtest/upload.php"
## $ min <dbl> 5.646166
## $ mean <dbl> 16.96393
## $ median <dbl> 19.76833
## $ max <dbl> 22.18757
## $ sd <dbl> 6.542608
## $ sponsor <chr> "Peregrine Networks"
## $ id <chr> "30644"
## $ host <chr> "speedtest.peregrinenetworks.net:8080"
## $ url2 <chr> NA
## $ min <dbl> 5.640102
## $ mean <dbl> 18.29085
## $ median <dbl> 20.99412
## $ max <dbl> 21.7017
## $ sd <dbl> 6.299546
```
### Moar download tests
......@@ -241,17 +245,17 @@ bind_rows(
select(to_compare, sponsor, name, country, host, type)
## # A tibble: 9 x 5
## sponsor name country host type
## <chr> <chr> <chr> <chr> <chr>
## 1 Otelco Portland, ME United States oak-speedtest.otelco.com:8080 closest
## 2 netBlazr Somerville, MA United States speed0.xcelx.net:8080 closest
## 3 Comcast Boston, MA United States stosat-ndhm-01.sys.comcast.net:8080 closest
## 4 Comcast Boston, MA United States stosat-ndhm-01.sys.comcast.net:8080 best
## 5 netBlazr Somerville, MA United States speed0.xcelx.net:8080 best
## 6 BELD Broadband Braintree, MA United States wotan.beld.net:8080 best
## 7 LLC Trans Analitika Novaya Usman Russian Federation speedtest-1.cnetvrn.ru:8080 random
## 8 VEGA Kharkiv Kharkiv Ukraine speedtest.vega.com.ua:8080 random
## 9 Oxylion S.A Katowice Poland speedtest-kat-01.oxylion.net.pl:8080 random
## sponsor name country host type
## <chr> <chr> <chr> <chr> <chr>
## 1 Peregrine Networks Manchester, NH United States speedtest.peregrinenetworks.net:8080 closest
## 2 Otelco Portland, ME United States oak-speedtest.otelco.com:8080 closest
## 3 netBlazr Somerville, MA United States speed0.xcelx.net:8080 closest
## 4 Comcast Boston, MA United States stosat-ndhm-01.sys.comcast.net:8080 best
## 5 netBlazr Somerville, MA United States speed0.xcelx.net:8080 best
## 6 Peregrine Networks Manchester, NH United States speedtest.peregrinenetworks.net:8080 best
## 7 Studenten Net Twente Enschede Netherlands ookla.snt.utwente.nl:8080 random
## 8 MIIT Kiev Ukraine speedtest.miit.ua:8080 random
## 9 Netcity Kielce Poland speedtest.netcity.pl:8080 random
map_df(1:nrow(to_compare), ~{
spd_download_test(to_compare[.x,], config=config, summarise=FALSE, timeout=30)
......@@ -286,14 +290,14 @@ bind_rows(
select(to_compare, sponsor, name, country, host, type)
## # A tibble: 6 x 5
## sponsor name country host type
## <chr> <chr> <chr> <chr> <chr>
## 1 Otelco Portland, ME United States oak-speedtest.otelco.com:8080 closest
## 2 netBlazr Somerville, MA United States speed0.xcelx.net:8080 closest
## 3 Comcast Boston, MA United States stosat-ndhm-01.sys.comcast.net:8080 closest
## 4 Comcast Boston, MA United States stosat-ndhm-01.sys.comcast.net:8080 best
## 5 netBlazr Somerville, MA United States speed0.xcelx.net:8080 best
## 6 BELD Broadband Braintree, MA United States wotan.beld.net:8080 best
## sponsor name country host type
## <chr> <chr> <chr> <chr> <chr>
## 1 Peregrine Networks Manchester, NH United States speedtest.peregrinenetworks.net:8080 closest
## 2 Otelco Portland, ME United States oak-speedtest.otelco.com:8080 closest
## 3 netBlazr Somerville, MA United States speed0.xcelx.net:8080 closest
## 4 Comcast Boston, MA United States stosat-ndhm-01.sys.comcast.net:8080 best
## 5 netBlazr Somerville, MA United States speed0.xcelx.net:8080 best
## 6 Peregrine Networks Manchester, NH United States speedtest.peregrinenetworks.net:8080 best
map_df(1:nrow(to_compare), ~{
spd_upload_test(to_compare[.x,], config=config, summarise=FALSE, timeout=30)
......@@ -316,9 +320,9 @@ ggplot(ul_results_full, aes(x="Upload Test", y=bw)) +
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 13 | 0.87 | 226 | 0.73 | 68 | 0.53 | 180 | 0.74 |
| Rmd | 1 | 0.07 | 64 | 0.21 | 51 | 0.40 | 62 | 0.26 |
| make | 1 | 0.07 | 20 | 0.06 | 9 | 0.07 | 0 | 0.00 |
| R | 15 | 0.88 | 286 | 0.77 | 90 | 0.60 | 192 | 0.76 |
| Rmd | 1 | 0.06 | 64 | 0.17 | 51 | 0.34 | 62 | 0.24 |
| make | 1 | 0.06 | 20 | 0.05 | 9 | 0.06 | 0 | 0.00 |
## Code of Conduct
......
......@@ -12,3 +12,5 @@ purrr
dplyr
stringr
forcats
bit
bit64
## Test environments
* local OS X install, R 3.6.1
* ubuntu 14.04 (on travis-ci), R 3.6.1
* win-builder (devel and release)
## R CMD check results
0 errors | 0 warnings | 1 note
* This is a new release.
--------------------
Nothing was flagged in winbuilder(s) so shld hopefully
work on the CRAN pre-test infra.
There is one live test requiring network connectivbity to
retrieve a config from speedtest & verify the results.
I can remove that if desired.
man/figures/README-moar-dl-tests-1.png

24.9 KB | W: | H:

man/figures/README-moar-dl-tests-1.png

31.6 KB | W: | H:

man/figures/README-moar-dl-tests-1.png
man/figures/README-moar-dl-tests-1.png
man/figures/README-moar-dl-tests-1.png
man/figures/README-moar-dl-tests-1.png
  • 2-up
  • Swipe
  • Onion skin
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/install-speedtest-cli.R
\name{install_speedtest_cli}
\alias{install_speedtest_cli}
\title{Provides instructions for installing the official speedtest CLI application}
\usage{
install_speedtest_cli()
}
\description{
Provides instructions for installing the official speedtest CLI application
}
......@@ -4,8 +4,13 @@
\alias{spd_download_test}
\title{Perform a download speed/bandwidth test}
\usage{
spd_download_test(server, config = NULL, summarise = TRUE,
timeout = 60, .progress = "dplyr")
spd_download_test(
server,
config = NULL,
summarise = TRUE,
timeout = 60,
.progress = "dplyr"
)
}
\arguments{
\item{server}{a data frame row from one of the functions that retrieves or
......
......@@ -13,7 +13,7 @@ performs download & upload tests and returs the best result.
\details{
Make a command-line alias or executable with:
\code{Rscript --quiet -e 'speedtest::spd_test()'}
\verb{Rscript --quiet -e 'speedtest::spd_test()'}
}
\examples{
\dontrun{
......
......@@ -4,8 +4,13 @@
\alias{spd_upload_test}
\title{Perform an upload speed/bandwidth test}
\usage{
spd_upload_test(server, config = NULL, summarise = TRUE,
timeout = 60, .progress = "dplyr")
spd_upload_test(
server,
config = NULL,
summarise = TRUE,
timeout = 60,
.progress = "dplyr"
)
}
\arguments{
\item{server}{a data frame row from one of the functions that retrieves or
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/speedtest-cli.R
\name{speedtest_cli}
\alias{speedtest_cli}
\alias{print.speedtest_cli_result}
\title{Perform an official Ookla Speed Test via their command line tools}
\usage{
speedtest_cli(progress = TRUE)
\method{print}{speedtest_cli_result}(x, browse = FALSE, ...)
}
\arguments{
\item{x}{`speedtest_cli_result` object}
\item{browse}{if `TRUE`, open a browser window with the results}
\item{...}{ignored}
}
\description{
Perform an official Ookla Speed Test via their command line tools
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment