Skip to content

Instantly share code, notes, and snippets.

@nosamanuel
Created August 11, 2010 16:40
Show Gist options
  • Save nosamanuel/519283 to your computer and use it in GitHub Desktop.
Save nosamanuel/519283 to your computer and use it in GitHub Desktop.
# Check how many users are *still* on IE6
# Also check the other IE versions out of curiosity
ip_agents = {}
ip_counts = {}
for l in open('nginx_access.log'):
try:
ip, event = l.split(' - - ')
except ValueError:
continue
if 'MSIE 6.0' in event or 'MSIE 6.1' in event:
ip_agents[ip] = 'IE6'
elif 'MSIE 7.0' in event:
ip_agents[ip] = 'IE7'
elif 'MSIE 8.0' in event:
ip_agents[ip] = 'IE8'
else:
ip_agents[ip] = 'Other'
ip_counts.setdefault(ip, 0)
ip_counts[ip] += 1
uniques = len(ip_agents.keys())
total = sum(ip_counts.values())
def agent_ips(agent):
return [ip for ip, ag in ip_agents.items() if ag == agent]
def unique_by_agent(agent):
unique_views = len(agent_ips(agent))
return round(float(unique_views ) / uniques * 100, 1)
def total_by_agent(agent):
total_views = sum([ip_counts[ip] for ip in agent_ips(agent)])
return round(float(total_views) / total * 100, 1)
ie6_part = unique_by_agent('IE6')
ie7_part = unique_by_agent('IE7')
ie8_part = unique_by_agent('IE8')
oth_part = unique_by_agent('Other')
ie6_part_adj = total_by_agent('IE6')
ie7_part_adj = total_by_agent('IE7')
ie8_part_adj = total_by_agent('IE8')
oth_part_adj = total_by_agent('Other')
print 'IE6: %s%%' % ie6_part
print 'IE7: %s%%' % ie7_part
print 'IE8: %s%%' % ie8_part
print 'Other: %s%%' % oth_part
print 'IE6 (adjusted): %s%%' % ie6_part_adj
print 'IE7 (adjusted): %s%%' % ie7_part_adj
print 'IE8 (adjusted): %s%%' % ie8_part_adj
print 'Other (adjusted): %s%%' % oth_part_adj
print 'Unique visitors: %d' % uniques
print 'Total page views: %d' % total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment