Skip to content

Commit

Permalink
by browser
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Mar 6, 2015
1 parent d46d48d commit e263747
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
31 changes: 31 additions & 0 deletions peterbecom/apps/localvsxhr/templates/localvsxhr/stats.html
Expand Up @@ -75,6 +75,37 @@ <h4>Time to Boot</h4>
</table>


<h4>By Browser</h4>
<h5>Take these with a fistfull of salt</h5>

<table class="table table-hover">
<thead>
<tr>
<th>Browser</th>
<th>Median</th>
<th>Average</th>
<th title="Standard Deviation">Std Dev.</th>
<th>Max.</th>
<th>Min.</th>
<th title="Number of measurements">#</th>
</tr>
</thead>
<tbody>
{% for data in browsers %}
<tr>
<td>{{ data.name }}</td>
<td class="median">{{ floatformat(data.median, 2) }}</td>
<td>{{ floatformat(data.average, 2) }}</td>
<td>{{ floatformat(data.stddev, 2) }}</td>
<td>{{ floatformat(data.max, 2) }}</td>
<td>{{ floatformat(data.min, 2) }}</td>
<td>{{ data.count }}</td>
</tr>
{% endfor %}
</tbody>
</table>


<h3>Analysis and Conclusion</h3>

<p>To be continued...</p>
38 changes: 38 additions & 0 deletions peterbecom/apps/localvsxhr/views.py
@@ -1,3 +1,4 @@
import re
from collections import defaultdict

from django.shortcuts import render
Expand All @@ -19,6 +20,32 @@ def index(request):
return render(request, 'localvsxhr/index.html', context)


simple_user_agent_regex = re.compile('''
Firefox/\d+ |
Chrome/\d+ |
Safari/\d+
''', re.X)


def parse_user_agent(ua):
browser = ''
version = None
if 'iPhone OS' in ua:
browser = 'iPhone '
elif 'AppleWebKit' in ua and 'Chrome' in ua:
browser = 'AppleWebKit '
elif 'Mobile;' in ua:
browser = 'Mobile '
elif 'SeaMonkey/' in ua:
browser = 'SeaMonkey '

for match in simple_user_agent_regex.findall(ua):
browser += match.split('/')[0]
version = match.split('/')[1]
break
return browser, version


def stats(request):
context = {}
# for m in Measurement.objects.all():
Expand Down Expand Up @@ -72,10 +99,21 @@ def wrap_sequence_boots(data):
return items

drivers = defaultdict(list)
browsers = defaultdict(list)
# browserversions = defaultdict(list)
for m in Measurement.objects.all():
drivers[m.driver].append(m.local_median)
drivers['XHR'].append(m.xhr_median)
browser, version = parse_user_agent(m.user_agent)
if browser:
browsers[browser].append(m.local_median)
# if version:
# browserversions['%s %s' % (browser, version)].append(
# m.xhr_median
# )
context['drivers'] = wrap_sequence(drivers)
context['browsers'] = wrap_sequence(browsers)
# context['browserversions'] = wrap_sequence(browserversions)

boots = defaultdict(list)
for m in BootMeasurement.objects.all():
Expand Down

0 comments on commit e263747

Please sign in to comment.