From 169bf77156eec11f3af221ec23eb09386a639cb0 Mon Sep 17 00:00:00 2001 From: WilliamSobczak Date: Sun, 4 Feb 2024 08:55:45 -0500 Subject: [PATCH 1/2] docs(README.md): updated speedtest-cli module dependency --- scripts/Internet Speed Checker/Readme.md | 4 ++-- scripts/Internet Speed Checker/requirements.txt | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 scripts/Internet Speed Checker/requirements.txt diff --git a/scripts/Internet Speed Checker/Readme.md b/scripts/Internet Speed Checker/Readme.md index 8c92e6c..477630f 100644 --- a/scripts/Internet Speed Checker/Readme.md +++ b/scripts/Internet Speed Checker/Readme.md @@ -5,9 +5,9 @@ This script will check your internet speed and with Download and Upload speed , ## ```How to use``` -1. Install the Speedtest Package using the following command: +1. Install dependencies (i.e., the Speedtest Package) using the following command: - `pip install speedtest` + 'pip install -r requirements.txt' Official Documentation: https://pypi.org/project/speedtest/ diff --git a/scripts/Internet Speed Checker/requirements.txt b/scripts/Internet Speed Checker/requirements.txt new file mode 100644 index 0000000..09cbe4d --- /dev/null +++ b/scripts/Internet Speed Checker/requirements.txt @@ -0,0 +1 @@ +speedtest-cli==2.1.3 From 0090f9543d4888a870dff84d774d43ba365ee5f9 Mon Sep 17 00:00:00 2001 From: WilliamSobczak Date: Sun, 4 Feb 2024 09:06:32 -0500 Subject: [PATCH 2/2] feat: enable multiple iterations and summary stats/graph of results --- scripts/Internet Speed Checker/main.py | 91 +++++++++++++------ .../Internet Speed Checker/requirements.txt | 1 + 2 files changed, 66 insertions(+), 26 deletions(-) diff --git a/scripts/Internet Speed Checker/main.py b/scripts/Internet Speed Checker/main.py index c63d322..9cf268f 100644 --- a/scripts/Internet Speed Checker/main.py +++ b/scripts/Internet Speed Checker/main.py @@ -1,37 +1,76 @@ -# Internet Speed Checker - import speedtest -import time -import os +import matplotlib.pyplot as plt +import pandas as pd + + +def run_speed_test(): + + download_speeds = [] + upload_speeds = [] + ping_values = [] + + # Run the speedtest while the user wants to continue running iterations + while True: + print('Internet Speed Checker') + + # Get the speed + s = speedtest.Speedtest() + s.get_best_server() + s.download() + s.upload() + results_dict = s.results.dict() + + # Append speeds and ping + download_speeds.append(results_dict['download'] / 1024 / 1024) + upload_speeds.append(results_dict['upload'] / 1024 / 1024) + ping_values.append(results_dict['ping']) + # Print the results + print(f"Iteration {len(download_speeds)}:") + print(f" Download Speed: {download_speeds[-1]:.2f} Mbit/s") + print(f" Upload Speed: {upload_speeds[-1]:.2f} Mbit/s") + print(f" Ping: {ping_values[-1]:.2f} ms") + print(f" ISP: {results_dict['client']['isp']}") -def main(): + # Ask the user whether they want to run another iteration + user_input = input("Do you want to run another iteration? (yes/no): ").lower() + if user_input != 'yes': + break - # Clear the screen - os.system('cls' if os.name == 'nt' else 'clear') + avg_download_speed = sum(download_speeds) / len(download_speeds) + avg_upload_speed = sum(upload_speeds) / len(upload_speeds) + avg_ping = sum(ping_values) / len(ping_values) - # Print the title - print('Internet Speed Checker') - # Print the current time - print(time.strftime('%H:%M:%S')) - print("Connecting to server...") + max_download_iteration = download_speeds.index(max(download_speeds)) + 1 + max_upload_iteration = upload_speeds.index(max(upload_speeds)) + 1 + min_ping_iteration = ping_values.index(min(ping_values)) + 1 - # Get the speed - s = speedtest.Speedtest() - s.get_best_server() - s.download() - s.upload() - results_dict = s.results.dict() + # Storing results + df = pd.DataFrame({ + 'Iteration': [i for i in range(1, len(download_speeds) + 1)], + 'Download Speed': download_speeds, + 'Upload Speed': upload_speeds, + 'Ping': ping_values + }) - # Print the results - print(f"Download: {results_dict['download'] / 1024 / 1024:.2f} Mbit/s") - print(f"Upload: {results_dict['upload'] / 1024 / 1024:.2f} Mbit/s") - print(f"Ping: {results_dict['ping']:.2f} ms") - print(f"ISP: {results_dict['client']['isp']}") + print("\nSummary:") + print(f" Average Download Speed: {avg_download_speed:.2f} Mbit/s") + print(f" Average Upload Speed: {avg_upload_speed:.2f} Mbit/s") + print(f" Average Ping: {avg_ping:.2f} ms") + print(f" Iteration with Highest Download Speed: Iteration {max_download_iteration}") + print(f" Iteration with Highest Upload Speed: Iteration {max_upload_iteration}") + print(f" Iteration with Lowest Ping: Iteration {min_ping_iteration}") - # Wait 5 seconds - time.sleep(5) + # Plot the results with integer x-axis labels + plt.plot(df['Iteration'], df['Download Speed'], label='Download Speed') + plt.plot(df['Iteration'], df['Upload Speed'], label='Upload Speed') + plt.plot(df['Iteration'], df['Ping'], label='Ping') + plt.xlabel('Iteration Number') + plt.ylabel('Speed/Ping (Mbit/s)') + plt.title('Internet Speed Test Results') + plt.legend() + plt.show() if __name__ == "__main__": - main() + run_speed_test() \ No newline at end of file diff --git a/scripts/Internet Speed Checker/requirements.txt b/scripts/Internet Speed Checker/requirements.txt index 09cbe4d..645eb5c 100644 --- a/scripts/Internet Speed Checker/requirements.txt +++ b/scripts/Internet Speed Checker/requirements.txt @@ -1 +1,2 @@ speedtest-cli==2.1.3 +matplotlib \ No newline at end of file