paritybit.ca

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 5c22dbd870f55e46d3dc9321c9991d301be60a95
parent bf6fefedd1d99b232d27c8c8bc8b0fe558b7110b
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Wed, 16 Feb 2022 03:15:08 -0500

Make file transfer time calculator tool

Diffstat:
Mcontent/projects.md | 1+
Acontent/projects/file-transfer-time-calculator.md | 208+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 209 insertions(+), 0 deletions(-)

diff --git a/content/projects.md b/content/projects.md @@ -47,6 +47,7 @@ on [my Bandcamp wishlist](https://bandcamp.com/jbauer001/wishlist). Thanks! ## Web-Based Utilities <ul> + <li><a href="projects/file-transfer-time-calculator">File Transfer Time Calculator</a></li> <li><a href="projects/time-duration-calculator">Time Duration Calculator</a></li> <li><a href="projects/morrowind-character-roller">Morrowind Character Roller</a></li> <li class="sublist-header">Dungeons & Dragons diff --git a/content/projects/file-transfer-time-calculator.md b/content/projects/file-transfer-time-calculator.md @@ -0,0 +1,208 @@ +Title: File Transfer Time Calculator +Summary: Quickly calculate how long a given file transfer will take. + +# [%title] + +<noscript>It seems that the current browser you are using does not support +JavaScript or it has been disabled. JavaScript is required for this applet to +function.</noscript> + +Input the size of the file and your transfer speed to calculate how long it will +take to transfer the file. + +<p><strong>Result:</strong> <span id="result-field">0 Days, 0 Hours, 0 Minutes, 0 Seconds</span></p> + +<form> + <input id="size" type="number" min="0" placeholder="0.00" arial-label="Data Size"/> + <select id="size-magnitude" aria-label="Magnitude of Size"> + <option value="B">B</option> + <option value="KB">KB</option> + <option value="KiB">KiB</option> + <option value="MB">MB</option> + <option value="MiB">MiB</option> + <option value="GB" selected>GB</option> + <option value="GiB">GiB</option> + <option value="TB">TB</option> + <option value="TiB">TiB</option> + <option value="PB">PB</option> + <option value="PiB">PiB</option> + </select> + <input id="speed" type="number" min="0" placeholder="0.00" aria-label="Transfer Speed"/> + <select id="speed-magnitude" aria-label="Magnitude of Speed"> + <option value="Bps">B/s</option> + <option value="bps">b/s</option> + <option value="KBps">KB/s</option> + <option value="Kbps">Kb/s</option> + <option value="MBps">MB/s</option> + <option value="Mbps" selected>Mb/s</option> + <option value="GBps">GB/s</option> + <option value="Gbps">Gb/s</option> + <option value="TBps">TB/s</option> + <option value="Tbps">Tb/s</option> + </select> + <button type="button" onClick=calculate()>Calculate</button> +</form> + +Or select from common device speeds: + +USB: +<button type="button" id="usb10" onClick=setSpeed(this)>USB 1.0</button> +<button type="button" id="usb20" onClick=setSpeed(this)>USB 2.0</button> +<button type="button" id="usb30" onClick=setSpeed(this)>USB 3.0</button> +<button type="button" id="usb31" onClick=setSpeed(this)>USB 3.1</button> +<button type="button" id="usb32" onClick=setSpeed(this)>USB 3.2</button> +<button type="button" id="usb4" onClick=setSpeed(this)>USB4</button> + +SATA: +<button type="button" id="sata1" onClick=setSpeed(this)>SATA I</button> +<button type="button" id="sata2" onClick=setSpeed(this)>SATA II</button> +<button type="button" id="sata3" onClick=setSpeed(this)>SATA III</button> + +Ethernet: +<button type="button" id="classic" onClick=setSpeed(this)>Classic</button> +<button type="button" id="fast" onClick=setSpeed(this)>Fast</button> +<button type="button" id="gigabit" onClick=setSpeed(this)>Gigabit</button> + +<script> +function setSpeed(clickedButton) { + let button = clickedButton.id; + console.log(button); + let speedElement = document.getElementById("speed"); + let speedMagnitude = document.getElementById("speed-magnitude"); + switch(button) { + case 'usb10': + speedElement.value = "12"; + speedMagnitude.value = "Mbps"; + break; + case 'usb20': + speedElement.value = "480"; + speedMagnitude.value = "Mbps"; + break; + case 'usb30': + speedElement.value = "5"; + speedMagnitude.value = "Gbps"; + break; + case 'usb31': + speedElement.value = "10"; + speedMagnitude.value = "Gbps"; + break; + case 'usb32': + speedElement.value = "20"; + speedMagnitude.value = "Gbps"; + break; + case 'usb4': + speedElement.value = "40"; + speedMagnitude.value = "Gbps"; + break; + case 'sata1': + speedElement.value = "150"; + speedMagnitude.value = "Gbps"; + break; + case 'sata2': + speedElement.value = "300"; + speedMagnitude.value = "Gbps"; + break; + case 'sata3': + speedElement.value = "600"; + speedMagnitude.value = "Gbps"; + break; + case 'classic': + speedElement.value = "10"; + speedMagnitude.value = "Mbps"; + break; + case 'fast': + speedElement.value = "100"; + speedMagnitude.value = "Mbps"; + break; + case 'gigabit': + speedElement.value = "1"; + speedMagnitude.value = "Gbps"; + break; + } +} +function calculate() { + let size = document.getElementById("size").value; + let speed = document.getElementById("speed").value; + let sizeMag = document.getElementById("size-magnitude").value; + let speedMag = document.getElementById("speed-magnitude").value; + + if (size <= 0 || speed <= 0) { + alert("Please enter a valid number greater than 0!"); + return; + } + + // Normalize to Bytes + switch(sizeMag) { + case 'KB': + size *= 1000; + break; + case 'MB': + size *= 1000 * 1000; + break; + case 'GB': + size *= 1000 * 1000 * 1000; + break; + case 'TB': + size *= 1000 * 1000 * 1000 * 1000; + break; + case 'TB': + size *= 1000 * 1000 * 1000 * 1000 * 1000; + break; + case 'KiB': + size *= 1024; + break; + case 'MiB': + size *= 1024 * 1024; + break; + case 'GiB': + size *= 1024 * 1024 * 1024; + break; + case 'TiB': + size *= 1024 * 1024 * 1024 * 1024; + break; + case 'PiB': + size *= 1024 * 1024 * 1024 * 1024 * 1024; + break; + } + + // Normalize to Bytes/s + switch(speedMag) { + case 'KBps': + speed *= 1000; + break; + case 'MBps': + speed *= 1000 * 1000; + break; + case 'GBps': + speed *= 1000 * 1000 * 1000; + break; + case 'TBps': + speed *= 1000 * 1000 * 1000 * 1000; + break; + case 'bps': + speed *= (1000)/8; + break; + case 'Kbps': + speed *= 1000/8; + break; + case 'Mbps': + speed *= (1000 * 1000)/8; + break; + case 'Gbps': + speed *= (1000 * 1000 * 1000)/8; + break; + case 'Tbps': + speed *= (1000 * 1000 * 1000 * 1000)/8; + break; + } + + let seconds = size / speed; + let d = Math.floor(seconds / (3600 * 24)); + let h = Math.floor(seconds % (3600 * 24) / 3600); + let m = Math.floor(seconds % 3600 / 60); + let s = seconds % 60; + + resultString = d + " Days, " + h + " Hours, " + m + " Minutes, " + s.toFixed(4) + " Seconds"; + document.getElementById("result-field").innerHTML = resultString; +} +</script>