avg_records

in rspec_stats/rspec_query.rb [115:137]


  def avg_records
    return @avg_records if @avg_records

    q = SQL_QUERIES.find { |q| q[:name] == 'avg_time_per_file_per_day' }
    orig_query = RspecQuery.new(q)

    today = Date.today
    days = (today - 7..today - 1).map(&:to_s)
    by_file = orig_query.csv.group_by { |row| row['file'] }
    last_day = days.last

    @avg_records = by_file.filter_map do |file, rows|
      next unless last = rows.find { |r| r['day'] == last_day }

      first = rows.find { |r| r['day'] == days.first }
      diff_pct = diff_percent(first, last).to_f
      weight = last['sum_time'].to_f
      pct_impact = (diff_pct * weight).to_i

      [file, pct_impact, last['avg_time'], weight.to_i, diff_pct, pct_history(days, rows)]
    end
  end