Update speedtester.py

master
Nixellion 2020-06-27 23:35:12 +03:00
parent d8b5235502
commit e05f7ff029
1 changed files with 6 additions and 7 deletions

View File

@ -126,6 +126,7 @@ downloading = True # True for download, False for upload
threads = None threads = None
servers = [] servers = []
def reset_globals(): def reset_globals():
global wan_upload global wan_upload
global wan_download global wan_download
@ -141,6 +142,7 @@ def reset_globals():
speedtest_failed = False speedtest_failed = False
downloading = True downloading = True
def threaded_speedtest(): def threaded_speedtest():
global test_started global test_started
global downloading global downloading
@ -157,7 +159,6 @@ def threaded_speedtest():
downloading = False downloading = False
s.upload(threads=threads, pre_allocate=False) s.upload(threads=threads, pre_allocate=False)
results_dict = s.results.dict() results_dict = s.results.dict()
log.info( log.info(
f"Speedtest.net result: DOWN {mbits(results_dict['download'])} mbps; UP {mbits(results_dict['upload'])} mbps;") f"Speedtest.net result: DOWN {mbits(results_dict['download'])} mbps; UP {mbits(results_dict['upload'])} mbps;")
@ -220,13 +221,12 @@ def test_speed():
sws.join() sws.join()
if wan_download >= config['ros_doublecheck_speed']: if wan_download >= config['ros_doublecheck_speed']:
break break
else: elif i < tries - 1:
log.warning("Speed is below ros_doublecheck_speed limit, retrying in a few seconds.") log.warning("Speed is below ros_doublecheck_speed limit, retrying in a few seconds.")
time.sleep(10) time.sleep(10)
return return
def generate_database_reports(): def generate_database_reports():
dates, downloads, uploads = gather_data() dates, downloads, uploads = gather_data()
@ -234,12 +234,12 @@ def generate_database_reports():
generate_plot_image(dates, downloads, uploads) generate_plot_image(dates, downloads, uploads)
import sys import sys
from netutils import test_intertnet_connection from netutils import test_intertnet_connection
def on_fail_or_no_connection(): def on_fail_or_no_connection():
ros_fastrack_enable(False) ros_fastrack_enable(False)
entry = Entry() entry = Entry()
@ -252,6 +252,7 @@ def on_fail_or_no_connection():
log.warning("No internet connection! Exiting.") log.warning("No internet connection! Exiting.")
sys.exit() sys.exit()
if __name__ == "__main__": if __name__ == "__main__":
''' '''
This script will run a few speed tests, calculate average upload and download speeds and record them into database. This script will run a few speed tests, calculate average upload and download speeds and record them into database.
@ -268,8 +269,6 @@ if __name__ == "__main__":
# if not test_intertnet_connection(): # if not test_intertnet_connection():
# no_internet() # no_internet()
if config["ros_dynamic_speed"]: if config["ros_dynamic_speed"]:
ros_fastrack_enable(True) ros_fastrack_enable(True)
time.sleep(5) time.sleep(5)