def execute
      ActiveRecord::Base.connection_pool.with_connection do |connection|
        connection.execute(sanitized_sql).map do |elem|
          [Date.parse(elem["frame"]).to_time, elem["result"].to_i]
        end
      end
    end
def execute
      ActiveRecord::Base.connection_pool.with_connection do |connection|
        connection.execute(sanitized_sql).map do |elem|
          [Date.parse(elem["frame"]).to_time, elem["result"].to_i]
        end
      end
    end
TODO:
  * prepared statement?
 Builds a periodic operation query with PostgresSQL window functions

 @param relation [ActiveRecord::Relation] Object to build query from
 @param query_options [QueryOptions]
 @return [Array<Array>] for each period the time of the interval and the count of it