# Amalyze 0.02 # Amazon Log Analyze # Script by daisuke asano # 2007/08/10 require 'kconv' $KCODE = "s" def output(hush, map, total) map.each { |elem| wari = (hush[elem].to_f / total.to_f) * 10000 + 5 wari = (wari.to_i / 10).to_f / 10 print "#{elem} : #{hush[elem]} (#{wari}%)\n" } end log = File.new("report.txt") cat_cnt = Hash.new{0} cat_map = ["–{", "ƒGƒŒƒNƒgƒƒjƒNƒX", "ƒz[ƒ€•ƒLƒbƒ`ƒ“", "ƒ~ƒ…[ƒWƒbƒN", "DVD", "\x83\x5C\x83\x74\x83\x67\x83\x45\x83\x46\x83\x41", "ƒQ[ƒ€", "‚¨‚à‚¿‚ᕃzƒr[", "ƒXƒ|[ƒc•ƒAƒEƒgƒhƒA", "ƒwƒ‹ƒX•ƒrƒ…[ƒeƒB[", "ŽžŒv", "ƒxƒr[•ƒ}ƒ^ƒjƒeƒB"] price_cnt = Hash.new{0} price_map = ["`1000", "`3000", "`5000", "`10000", "`30000", "`50000", "50001`"] total = 0 i = 0 sales_sum = Hash.new{0} log.each_line do |line| if i > 1 line = Kconv.kconv(line, Kconv::SJIS, Kconv::UTF8) tabv = line.split(/\t/) s_category = tabv[0] #ƒJƒeƒSƒŠ s_item = tabv[1] #¤•i–¼ s_asin = tabv[2] #ASIN”Ô† # s_store = tabv[3] #o•iŽÒ # s_affi_id = tabv[4] #ƒgƒ‰ƒbƒLƒ“ƒOID # s_date = tabv[5] #”„ã“ú s_price = tabv[6] #‰¿Ši # s_per = tabv[7] #Љ—¦ s_shipping = tabv[8].to_i #”­‘—ςݤ•i # s_sales = tabv[9] #”„‚èã‚°‹àŠz # s_charge = tabv[10] #Љ total += s_shipping cat_cnt[s_category] += s_shipping price = s_price.delete("").delete(",").to_i sales_sum[s_asin + " " + s_item] += s_shipping if price <= 1000 price_cnt["`1000"] += s_shipping elsif price <= 3000 price_cnt["`3000"] += s_shipping elsif price <= 5000 price_cnt["`5000"] += s_shipping elsif price <= 10000 price_cnt["`10000"] += s_shipping elsif price <= 30000 price_cnt["`30000"] += s_shipping elsif price <= 50000 price_cnt["`50000"] += s_shipping else price_cnt["50001`"] += s_shipping end end i += 1 end print "ƒg[ƒ^ƒ‹”Ì”„” : #{total}\n" print "\nƒJƒeƒSƒŠ•ª•z\n" output(cat_cnt, cat_map, total) print "\n‰¿Ši•Ê•ª•z\n" output(price_cnt, price_map, total) print "\n”„‚èã‚°‡\n" sorted = sales_sum.sort {|a, b| b[1].to_i <=> a[1].to_i } for top in 0..19 do print "#{sorted[top][0]} : #{sorted[top][1]}\n" end