Title / Description
Code #!/usr/bin/env ruby # encoding: UTF-8 PRODUCT_TYPES = {1 => 'Web Filter', 8 => 'Antivirus', 9 => 'Web Filter + Antivirus', 125 => 'Security Suite'} class Report def initialize(filename) @file = File.open(filename, 'r') @headers = {} begin line = @file.gets next if line.strip.empty? or line =~ /^Generated on / @headers = line.strip.split("\t") # for i in 0 ... hdrs.size # headers[hdrs[i]] = i # end end while @headers.empty? end def line(&block) while line = @file.gets fields = line.strip.split("\t") data = {} for i in 0 ... fields.size data[@headers[i]] = fields[i] end block.call(data) end end end filename = ARGV.shift active_licenses = {} report = Report.new(filename) report.line do |data| active_licenses[data['LicenseID']] = data['Product'].to_i if data['LicenseStatus'] == '1' end license_count_per_product = {} active_licenses.each do |license_id, product_type| if license_count_per_product[product_type] license_count_per_product[product_type] += 1 else license_count_per_product[product_type] = 1 end end license_count_per_product = license_count_per_product.sort { |a, b| a[0] <=> b[0] } license_count_per_product.each do |data| if PRODUCT_TYPES[data[0]] product_name = PRODUCT_TYPES[data[0]] else product_name = "Unknown (type %d)" % data[0] end puts "%24s %d" % [product_name, data[1]] end
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code