Skip to content

Commit

Permalink
Switching from statistics to numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Crown committed Jul 9, 2015
1 parent fa500f8 commit 7476ed7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
21 changes: 11 additions & 10 deletions haralyzer/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import dateutil
# I know this import is stupid, but I cannot use dateutil.parser without it
from dateutil import parser
import numpy
assert parser
import re
import statistics

from haralyzer.compat import iteritems

Expand Down Expand Up @@ -214,7 +214,8 @@ def get_stdev(self, asset_type):
else:
load_times = self.get_load_times(asset_type)

return round(statistics.stdev(load_times), self.decimal_precision)
return round(numpy.std(load_times, ddof=1),
self.decimal_precision)

@property
def pages(self):
Expand Down Expand Up @@ -247,15 +248,15 @@ def time_to_first_byte(self):
ttfb = []
for page in self.pages:
ttfb.append(page.time_to_first_byte)
return round(statistics.mean(ttfb), self.decimal_precision)
return round(numpy.mean(ttfb), self.decimal_precision)

@cached_property
def page_load_time(self):
"""
The average total load time for all runs (not weighted).
"""
load_times = self.get_load_times('page')
return round(statistics.mean(load_times), self.decimal_precision)
return round(numpy.mean(load_times), self.decimal_precision)

@cached_property
def js_load_time(self):
Expand All @@ -266,47 +267,47 @@ def js_load_time(self):
total load time or the browser load time
"""
load_times = self.get_load_times('js')
return round(statistics.mean(load_times), self.decimal_precision)
return round(numpy.mean(load_times), self.decimal_precision)

@cached_property
def css_load_time(self):
"""
Returns aggregate css load time for all pages.
"""
load_times = self.get_load_times('css')
return round(statistics.mean(load_times), self.decimal_precision)
return round(numpy.mean(load_times), self.decimal_precision)

@cached_property
def image_load_time(self):
"""
Returns aggregate image load time for all pages.
"""
load_times = self.get_load_times('image')
return round(statistics.mean(load_times), self.decimal_precision)
return round(numpy.mean(load_times), self.decimal_precision)

@cached_property
def html_load_time(self):
"""
Returns aggregate html load time for all pages.
"""
load_times = self.get_load_times('html')
return round(statistics.mean(load_times), self.decimal_precision)
return round(numpy.mean(load_times), self.decimal_precision)

@cached_property
def audio_load_time(self):
"""
Returns aggregate audio load time for all pages.
"""
load_times = self.get_load_times('audio')
return round(statistics.mean(load_times), self.decimal_precision)
return round(numpy.mean(load_times), self.decimal_precision)

@cached_property
def video_load_time(self):
"""
Returns aggregate video load time for all pages.
"""
load_times = self.get_load_times('video')
return round(statistics.mean(load_times), self.decimal_precision)
return round(numpy.mean(load_times), self.decimal_precision)


class HarPage(object):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
statistics; python_version <= '2.7'
cached-property
numpy
python-dateutil
pytest-cov
python-coveralls
cached-property
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


install_reqs = ['cached-property',
'python-dateutil',
'statistics', ]
'numpy',
'python-dateutil', ]

readme = open('README.rst').read()

Expand Down

0 comments on commit 7476ed7

Please sign in to comment.