speedtest icon indicating copy to clipboard operation
speedtest copied to clipboard

Calculate download time from file size

Open k5cents opened this issue 4 years ago • 3 comments

It might be handy if this package implemented some functions to take a file size and download speed and calculate the time needed to download.

Remembering how to go from MB to Mbps to seconds, etc is confusing.

# check file head size
tx_url <- "https://www.ethics.state.tx.us/data/search/cf/TEC_CF_CSV.zip"
tx_head <- httr::HEAD(url = tx_url)
(tx_length <- fs::as_fs_bytes(httr::headers(tx_head)[["content-length"]]))
#> 541M
# test download speed
config <- speedtest::spd_config()
servers <- speedtest::spd_servers(config = config)
closest_servers <- speedtest::spd_closest_servers(servers, config = config)
speed <- speedtest::spd_download_test(closest_servers[1, ], config = config)
speed[, 11:15]
#> # A tibble: 1 x 5
#>     min  mean median   max    sd
#>   <dbl> <dbl>  <dbl> <dbl> <dbl>
#> 1  6.55  34.6   38.2  61.2  19.4
# seconds to download
((as.numeric(tx_length)/1e+6) / (speed$median / 8))
#> [1] 118.6992

Created on 2020-02-27 by the reprex package (v0.3.0)

k5cents avatar Feb 27 '20 17:02 k5cents

I'm pinging @briandconnelly to this as I recall hearing something abt an official speedtest R pkg coming out and wld prbly PR into that for this functionality vs maintain this pkg.

hrbrmstr avatar Feb 27 '20 19:02 hrbrmstr

Good news / bad news. We do have an official R package for Speedtest that's done and ready to go. The bad news is that it hasn't cleared legal yet, and I don't have an estimate for when it will.

image

In the meantime (and not to discourage use/development of @hrbrmstr's package!), I will mention that the official CLI tool does offer configurable units (e.g., Mbps, kiB/s, etc.) so you don't have to do any conversion, and its output is easy to import into R.

briandconnelly avatar Feb 27 '20 23:02 briandconnelly

speedtest -f json FTW!

Imagonna add support for the CLI (i.e. calling it from R and handling the output) and then make this estimator @kiernann requested.

I'll prbly rename the pkg as well to avoid confusion with the legit one that will eventually come out.

hrbrmstr avatar Feb 28 '20 12:02 hrbrmstr