<commit_before>class FbesPlugin::ResponsaController < PublicController

  def enterprises
      @enterprises = environment.enterprises.enabled

      @page = (params[:page] || 1).to_i
      @per_page = if params[:per_page] == 'all' then 999999 else (params[:per_page] || 20).to_i end
      @enterprises = @enterprises.paginate page: @page, per_page: @per_page

      @json = @enterprises.map do |e|
        {
          local_id: e.id,
          url: url_for(e.url),
          title: e.short_name(null),
          description: e.description,
          lat: e.lat,
          lng: e.lng,
          address: [e.address, e.address_line2, e.district, e.zip_code].select{ |f| f.present? }.join(', '),
          city: e.city,
          state: e.state,
          country: 'BR',
          created_at: e.created_at,
          updated_at: e.updated_at,
          avatar: if e.image then "#{environment.top_url}#{e.image.public_filename}" else nil end,
        }
      end

      render json: @json
  end

  protected

  def default_url_options
    # avoid rails' use_relative_controller!
    {use_route: '/'}
  end

end

<commit_msg>fbes: better query and include consumers' coops<commit_after>class FbesPlugin::ResponsaController < PublicController

  def initiatives
    @last_updated_on = params[:last_updated_on] || 24
    @last_updated_on = @last_updated_on.months.ago

    @enterprises = environment.enterprises.enabled.joins(:products, :articles).
      where('profiles.updated_at > ? OR products.updated_at > ? OR articles.updated_at > ?', @last_updated_on, @last_updated_on, @last_updated_on).
      uniq.group('profiles.id')
    @consumers_coops = environment.communities.joins(:orders).
      where('orders_plugin_orders.updated_at > ?', @last_updated_on).
      uniq.group('profiles.id')

    @results = @enterprises + @consumers_coops

    @json = @results.map do |e|
      {
        local_id: e.id,
        url: url_for(e.url),
        title: e.short_name(nil),
        description: e.description,
        lat: e.lat,
        lng: e.lng,
        address: [e.address, e.address_line2, e.district, e.zip_code].select{ |f| f.present? }.join(', '),
        city: e.city,
        state: e.state,
        country: 'BR',
        created_at: e.created_at,
        updated_at: e.updated_at,
        avatar: if e.image then "#{environment.top_url}#{e.image.public_filename}" else nil end,
      }
    end

    render json: Oj.dump(@json, mode: :compat)
  end

  protected

  def default_url_options
    # avoid rails' use_relative_controller!
    {use_route: '/'}
  end

end


{'fraction_non_alphanumeric': 0.1277258566978193, 'fraction_numerical': 0.0050623052959501555, 'mean_word_length': 2.6857962697274034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3436259', 'n_tokens_mistral': 883, 'n_tokens_neox': 854, 'n_words': 176}