def local_count(duration, type)
      aggr = {}
      Octo::Enterprise.each do |enterprise|
        args = {
            enterprise_id: enterprise.id,
            ts: duration,
            type: type
        }
        aggr[enterprise.id.to_s] = {} unless aggr.has_key?(enterprise.id.to_s)
        results = where(args)
        results_group = results.group_by { |x| x.uid }
        results_group.each do |uid, counters|
          _sum = counters.inject(0) do |sum, counter|
            sum + counter.count
          end
          aggr[enterprise.id.to_s][uid] = _sum
        end
      end
      aggr
    end
def local_count(duration, type)
      aggr = {}
      Octo::Enterprise.each do |enterprise|
        args = {
            enterprise_id: enterprise.id,
            ts: duration,
            type: type
        }
        aggr[enterprise.id.to_s] = {} unless aggr.has_key?(enterprise.id.to_s)
        results = where(args)
        results_group = results.group_by { |x| x.uid }
        results_group.each do |uid, counters|
          _sum = counters.inject(0) do |sum, counter|
            sum + counter.count
          end
          aggr[enterprise.id.to_s][uid] = _sum
        end
      end
      aggr
    end
Does the counting from DB. Unlike the other counter that uses Redis. Hence
   the name local_count
 @param [Time] duration A time/time range object
 @param [Fixnum] type The type of counter to look for