Accuracy problems with Pyspeedtest

116
December 23, 2017, at 08:39 AM

I'm trying to build a program that uses pyspeedtest to track my internet speeds throughout the day. At this point, I've got a basic logger that will log the ping, download, and upload speeds. I have the program looping through the speedtest 10 times and getting the average speed. That said, my average results whenever I run this are usually about:

ping: 48ms
download speed: 20-30 Mbps
upload speed: 9-11 Mbps

When I use speedtest.net, I get something like this:

ping: 43 - 50 ms
download speed: 80-110 Mbps
upload speed: 10-15 Mbps

I pay for high speed internet and think that the speedtest.net results are more in line with what service I might be receiving but I'm not sure. Am I doing something wrong in my code (below) to get inaccurate results:

import pyspeedtest
import log
MESSAGE = """\n
    Results:
    Pings = {}
    Downloads = {}
    Uploads = {}
    Averages = Ping: {} ms; Download: {} Mbps; Upload: {} Mbps\n
"""
SPEED = pyspeedtest.SpeedTest()
BITS_PER_MEGABIT = 1000000
ROUNDS_PER_TEST = 10
def mbps(bps):
    return bps/BITS_PER_MEGABIT
def speedtest():
    return SPEED.ping(), mbps(SPEED.download()), mbps(SPEED.upload())
def average(lst):
    return sum(lst)/len(lst)
def average_speedtest(log=True):
    pings = []
    downloads = []
    uploads = []
    for test in range(ROUNDS_PER_TEST):
        p,d,u = speedtest()
        pings.append(p)
        downloads.append(d)
        uploads.append(u)
    ping = average(pings)
    download = average(downloads)
    upload = average(uploads)
    message = MESSAGE.format(pings, downloads, uploads,
              round(ping,2), round(download,2), round(upload,2))
    if log:
        log.logger.info(message)
    else:
        print(message)
if __name__ == '__main__':
    average_speedtest(False)

if you need the log.py file that is imported, it is:

import logging
import persistent
LOG_FORMAT = "%(asctime)s - %(levelname)s:  %(message)s"
LOG_DTTM_FORMAT = "%Y-%b-%d %H:%M:%S (%Z_%z)"
logging.basicConfig(filename = persistent.PATH + persistent.FILE_NAME,
                    level=logging.INFO,
                    format=LOG_FORMAT,
                    datefmt=LOG_DTTM_FORMAT)
logger = logging.getLogger()

if __name__ == '__main__':
    logger.info("Ran from log.py")

This just imports a persistent.py file that gets my personal info, such as filepath, etc..

It takes about a minute for the app.py program to work and get results. Any and all insight would be greatly appreciated!

READ ALSO
Removing duplicates in values of dictionary in python

Removing duplicates in values of dictionary in python

Sorry the topic's title is vague, I find it hard to explain

114
subprocess.Popen to interact with a CLI prompt

subprocess.Popen to interact with a CLI prompt

I am trying to write and read from a CLI program using subprocessPopen

105
want to replace uuid in given url '/v2/merchants/e0cf059a-5080-40a5-aaf1-67eb866aa48f/secretKey' with '*' using python

want to replace uuid in given url '/v2/merchants/e0cf059a-5080-40a5-aaf1-67eb866aa48f/secretKey' with '*' using python

I am trying to replace the uuid in the given URL /v2/merchants/e0cf059a-5080-40a5-aaf1-67eb866aa48f/secretKey with the * signI tried using the following regular expression, but I'm still not able to do it:

107
Replace Python nested For Loops with comprehension [duplicate]

Replace Python nested For Loops with comprehension [duplicate]

This question already has an answer here:

99