Permalink
Browse files

tidied browser versions to just log major version.

  • Loading branch information...
1 parent acbf980 commit 57c0459e94066613d33c89b29d3d6220e9d1c23e Derek Hoy committed Jun 8, 2012
@@ -57,8 +57,26 @@ def process_request(self, request):
try:
# parser.detect gives more detail- could break out into OS, browser, version stats...
# simple_detect -> ('Linux', 'Chrome 5.0.307.11')
- value = httpagentparser.simple_detect(value)[1]
- log = value != 'Unknown Browser'
+
+ values = httpagentparser.detect(value)
+ # print values
+ value = None
+ if values:
+ value = values.get('browser')
+ if value:
+ value = '%s %s' % (value.get('name', 'no name'), value.get('version','').split('.')[0])
+
+ if value is None:
+ value = 'Unknown Browser'
+ log = False
+
+ # value = httpagentparser.simple_detect(value)[1]
+ # print httpagentparser.detect(value)
+ # log = value != 'Unknown Browser'
+ # values = value.split()
+ # value = '%s %s' % (' '.join(values[:-1]), values[-1].split('.')[0])
+
+ # print value
except IndexError:
pass
analytics.increment(key, field=value)
@@ -212,7 +212,8 @@ def __init__(self, *args, **kwargs):
'top_accounts': ('Accounts', 'accounts_detail'),
}
self.flat_keys = {
-
+ 'user_agents': ('Browser type', 'HTTP_USER_AGENT'),
+ 'queries': ('Queries', 'search_queries'),
}
self.tags_key = 'search_tags'
@@ -231,7 +232,10 @@ def get_stats(self, stat_name, *args, **kwargs):
attr = self.sum_keys.get(stat_name)
if attr:
return self.sum_hash(attr[1], *args, **kwargs)
- raise AttributeError, attrname
+ attr = self.flat_keys.get(stat_name)
+ if attr:
+ return self.flat_data(attr[1], *args, **kwargs)
+ raise AttributeError, stat_name
def top_tags(self, *args, **kwargs):
return self.sum_hash(self.tags_key, *args, **kwargs)
@@ -559,7 +559,7 @@ def test_middleware_stats(self):
self.assertEqual(result.status_code, 200)
self.assertEqual(analytics.sum_hash('HTTP_USER_AGENT', yesterday, tomorrow),
- [('Unknown Browser', 2), ('Safari 5.1.7', 1)])
+ [('Unknown Browser', 2), ('Safari 5', 1)])
# self.assertEqual(analytics.sum_hash('REMOTE_ADDR', yesterday, tomorrow),
# [(ip, 3)])
@@ -51,11 +51,12 @@ def stat_json(request, stat_name):
else:
analytics = OverallAnalytics()
- if not hasattr(analytics, stat_name):
- raise Http404("Stat not found.")
+ # if not hasattr(analytics, stat_name):
+ # raise Http404("Stat not found.")
data = {
- 'result': getattr(analytics, stat_name)(start_date=start, end_date=end)
+ 'result': analytics.get_stats(stat_name, start_date=start, end_date=end)
+ # 'result': getattr(analytics, stat_name)(start_date=start, end_date=end)
}
return HttpResponse(json.dumps(data), mimetype='application/json')

0 comments on commit 57c0459

Please sign in to comment.