#!/usr/bin/ruby # Author: Tony Perrie # Date: 11/19/2005 # # Description: Takes AWStats Cache Files and makes a perty graph require 'rubygems' require 'gruff' awsmonth = Dir.glob("/var/cache/awstats/awstats[0-1][0-9]200[45].txt").to_a ff_a = [] ie_a = [] lb_a = [] awsmonth.sort {|x,y| (x[-8..-5] << x[-10..-9]) <=> (y[-8..-5] << y[-10..-9])}.each { |filename| year = filename[-8..-5] month = filename[-10..-9] datafile=File.open(filename) ie=0 ff=0 total=0 ff_cnt=0 in_browser_block=false datafile.each_line { |line| if !in_browser_block && line =~ /BEGIN_BROWSER/ then in_browser_block=true end if in_browser_block if line =~ /END_BROWSER/ break end cols = line.scan(/[^\s]+/) if cols[0] =~ /firefox/ then ff+=cols[1].to_i elsif cols[0] =~ /msie\d/ then ie+=cols[1].to_i end cols[1] =~ /^\d+$/ && total+= cols[1].to_i end } ff_a <<= (ff.to_f/total.to_f*100).to_f ie_a <<= (ie.to_f/total.to_f*100).to_f lb_a <<= month << "/" << year } g = Gruff::Line.new g.title = "Firefox vs IE for Involution.com" g.data("Firefox", ff_a) g.data("Internet Explorer", ie_a) g.labels = { 0 => "2004", 13 => "2005" } # g.labels = lb_a g.write('browsershare.png') print "ie entries -> " << ie_a.length.to_s << "\n" print "ff entries -> " << ff_a.length.to_s << "\n"