app/helpers/stats_helpers.rb
def date_groups(table, column) # rubocop:disable Metrics/MethodLength
    query = <<~SQL.squish
      SELECT date_trunc('year', #{column}) AS year, count(*) as events
        FROM #{table}
      WHERE #{column} IS NOT NULL
      GROUP BY year
      ORDER BY year ASC
    SQL

    ApplicationRecord.connection.execute(query)
                     .map { |row| [row["year"].year, row["events"]] }
                     .select { |row| (2004..Time.current.year).cover? row.first }
                     .to_h
  end
#
# Fetches counts of occurences per year for given table/column combination
#
Fetches counts of occurences per year for given table/column combination
Fetches counts of occurences per year for given table / column combination
def date_groups(table, column) 
    query = <<~SQL.squish
      SELECT date_trunc('year', #{column}) AS year, count(*) as events
        FROM #{table}
      WHERE #{column} IS NOT NULL
      GROUP BY year
      ORDER BY year ASC
    SQL
    ApplicationRecord.connection.execute(query)
                     .map { |row| [row["year"].year, row["events"]] }
                     .select { |row| (2004..Time.current.year).cover? row.first }
                     .to_h
  end
def date_groups ( table , column ) query = <<~SQL . squish 
      SELECT date_trunc('year',  #{ column } ) AS year, count(*) as events
        FROM  #{ table } 
      WHERE  #{ column }  IS NOT NULL
      GROUP BY year
      ORDER BY year ASC
     SQL ApplicationRecord . connection . execute ( query ) . map { | row | [ row [ "year" ] . year , row [ "events" ] ] } . select { | row | ( 2004 .. Time . current . year ) . cover? row . first } . to_h end
Fetches counts of occurences per year for given table/column combination
Fetches counts of occurences per year for given table / column combination
# rubocop:disable Metrics/MethodLength
table
column