Comcast Speeds

In [2]:
import os
csv_file="../files/files/SpeedTests.csv"
assert(os.path.exists(csv_file))
In [3]:
# https://docs.python.org/3/library/csv.html#csv.reader
import csv
with open(csv_file, newline='') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
    for row in spamreader:
        break
In [4]:
print(row)
['"Mon', 'Jul', '13', '23:51:28', '2015","34.373","28.85","4.74"']
In [5]:
type(row)
Out[5]:
list
In [6]:
csv.list_dialects()
Out[6]:
['unix', 'excel', 'excel-tab']
In [7]:
# https://docs.python.org/3/library/csv.html#csv.reader
import csv
with open(csv_file, newline='') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
    for row in spamreader:
        break
In [8]:
class speedtest(object):
    def __init__(self,row_list):
        self.date=row_list[0]
        self.ping=float(row_list[1])
        self.dl=float(row_list[2])
        self.ul=float(row_list[3])
    def __repr__(self):
        return "speedtest<{},{},{},{}>".format(self.date, self.ping, self.ul, self.ul)
speedtest(row)
Out[8]:
speedtest<Mon Jul 13 23:51:28 2015,34.373,4.74,4.74>
In [9]:
from dateutil.parser import parse
parse(speedtest(row).date)
Out[9]:
datetime.datetime(2015, 7, 13, 23, 51, 28)
In [10]:
class speedtest(object):
    def __init__(self,row_list):
        self.date=parse(row_list[0])
        self.ping=float(row_list[1])
        self.dl=float(row_list[2])
        self.ul=float(row_list[3])
    def __repr__(self):
        return "speedtest<{},{},{},{}>".format(self.date, self.ping, self.ul, self.ul)
a=speedtest(row)
In [11]:
speedtests=list()
# https://docs.python.org/3/library/csv.html#csv.reader
import csv
with open(csv_file, newline='') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
    for row in spamreader:
        speedtests.append(speedtest(row))
In [12]:
for test in speedtests:
    break
In [13]:
import datetime
In [14]:
for i in range(1,len(speedtests)):
    pass
    # print(float(speedtests[i].date.strftime("%s"))-float(speedtests[i-1].date.strftime("%s")))
In [15]:
t0=float(speedtests[0].date.strftime("%s"))
days=[(float(t.date.strftime("%s"))-t0) for t in speedtests]
dl=[test.dl for test in speedtests]
ping=[test.ping for test in speedtests]
ul=[test.ul for test in speedtests]
In [16]:
%pylab
%matplotlib inline
Using matplotlib backend: TkAgg
Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['test']
`%matplotlib` prevents importing * from pylab and numpy
In [17]:
days=[(float(t.date.strftime("%s"))-t0)/(24*3600) for t in speedtests]
plot(days,dl,days,ul)
xlabel("Monitor Days")
ylabel(r"$\frac{Mb}{s}$")
title("200 days of Comcast")
Out[17]:
<matplotlib.text.Text at 0x80d2c53c8>
In [18]:
max(dl)
max(ul)
Out[18]:
4.79
In [65]:
n, bins, patches = plt.hist(dl, 50, normed=1, facecolor='green', alpha=0.75)
In [71]:
bins[numpy.where(max(n)==n)[0][0]]
Out[71]:
16.924399999999999
In [73]:
n, bins, patches = plt.hist(ul, 50, normed=1, facecolor='green', alpha=0.75)
In [74]:
bins[numpy.where(max(n)==n)[0][0]]
Out[74]:
2.2991999999999999
In [75]:
n, bins, patches = plt.hist(ping, 10, normed=1, facecolor='green', alpha=0.75)
In [76]:
import numpy
days=numpy.array(days)
dl=numpy.array(dl)
ul=numpy.array(ul)
ping=numpy.array(ping)
In [77]:
numpy.mean(dl)
Out[77]:
18.306073982962051
In [88]:
start_idx=numpy.where(numpy.array(days)>38.5)[0][0]
end_idx=numpy.where(numpy.array(days)<39)[0][-1]
plot(days[start_idx:end_idx],dl[start_idx:end_idx])
print(speedtests[start_idx])
print(speedtests[end_idx])
speedtest<2015-08-21 11:52:32,36.702,4.66,4.66>
speedtest<2015-08-21 23:26:36,29.625,2.34,2.34>
In [83]:
n, bins, patches = plt.hist(ping[numpy.where(ping<1000)[0]], 50, normed=1, facecolor='green', alpha=0.75)
In [84]:
n, bins, patches = plt.hist(ping[numpy.where(ping<60)[0]], 50, normed=1, facecolor='green', alpha=0.75)
xlabel("Ping (ms)")
ylabel("Probability")
title("Pings (0-60 ms)")