def calculate(enterprise_id, trend_type, ts = Time.now.floor)
        args = {
          enterprise_id: enterprise_id,
          ts: ts,
          type: trend_type
        }

        klass = @trend_for.constantize
        hitsResult = klass.public_send(:where, args)
        trends = hitsResult.map { |h| counter2trend(h) }

        # group trends as per the time of their happening and rank them on their
        # score
        grouped_trends = trends.group_by { |x| x.ts }
        grouped_trends.each do |_ts, trendlist|
          sorted_trendlist = trendlist.sort_by { |x| x.score }
          sorted_trendlist.each_with_index do |trend, index|
            trend.rank = index
            trend.type = trend_type
            trend.save!
          end
        end
    end
def calculate(enterprise_id, trend_type, ts = Time.now.floor)
        args = {
          enterprise_id: enterprise_id,
          ts: ts,
          type: trend_type
        }

        klass = @trend_for.constantize
        hitsResult = klass.public_send(:where, args)
        trends = hitsResult.map { |h| counter2trend(h) }

        # group trends as per the time of their happening and rank them on their
        # score
        grouped_trends = trends.group_by { |x| x.ts }
        grouped_trends.each do |_ts, trendlist|
          sorted_trendlist = trendlist.sort_by { |x| x.score }
          sorted_trendlist.each_with_index do |trend, index|
            trend.rank = index
            trend.type = trend_type
            trend.save!
          end
        end
    end
Performs the actual trend calculation
 @param [String] enterprise_id The enterprise ID for whom trend needs to be found
 @param [Fixnum] trend_type The trend type to be calculates
 @param [Time] ts The Timestamp at which trend needs to be calculated.