#!/usr/bin/env ruby $: << File.join(File.dirname(__FILE__), '..', 'lib') require 'setup_environment' require 'observation' require 'stream_wrapper' require 'ansi_colors' require 'set' require 'yaml' filters = { :valid => true, :skip_debug_observations => true } observations = StreamWrapper.open(ARGV, filters) shops = Hash.new do |h,k| h2 = Hash.new(0) h2[:u_items] = Set.new h2[:u_users] = Set.new h[k] = h2 end observations.each do |obs| stats = shops["#{obs[:account_id]}/#{obs[:shop_id]}"] stats[obs.type] += 1 stats[:u_items] << obs[:item_id] if obs[:item_id] stats[:u_users] << obs[:user_id] if obs[:user_id] end shops.each_pair do |k,stats| [:u_items, :u_users].each do |u| stats[u] = stats[u].size end end shops.keys.sort.each do |shop_id| stats = shops[shop_id] puts stats.to_yaml.sub('---', "*** #{shop_id}") end