<commit_before>module Descartes
  class Web < Sinatra::Base

    get '/dashboards/?' do
      if request.accept.include?('application/json')
        @dashboards = []
        if params[:search]
          matching_dashboards = []
          params[:search].split(',').each do |search|
            matching_dashboards << Dashboard.select('dashboards.*'.lit, 'COUNT(graph_dashboard_relations.*) AS graph_count'.lit).
              from(:dashboards, :graph_dashboard_relations).
              where(:dashboards__enabled => true).
              where(:dashboards__id => :graph_dashboard_relations__dashboard_id).
              where(:dashboards__name.like(/#{search}/i)).
              group(:dashboards__id,
                    :dashboards__uuid,
                    :dashboards__owner,
                    :dashboards__name,
                    :dashboards__description,
                    :dashboards__configuration,
                    :dashboards__enabled,
                    :dashboards__created_at,
                    :dashboards__updated_at).
              order('LOWER(dashboards.name)'.lit).all
          end
          # Filter out duplicates
          known_dashboards = []
          matching_dashboards.flatten!
          matching_dashboards.each do |d|
            unless known_dashboards.include?(d.values[:id])
              known_dashboards.push(d.values[:id])
              @dashboards.push(d)
            end
          end
        else
          @dashboards << Dashboard.select('dashboards.*'.lit, 'COUNT(graph_dashboard_relations.*) AS graph_count'.lit).
            from(:dashboards, :graph_dashboard_relations).
            where(:dashboards__enabled => true).
            where(:dashboards__id => :graph_dashboard_relations__dashboard_id).
            group(:dashboards__id,
                  :dashboards__uuid,
                  :dashboards__owner,
                  :dashboards__name,
                  :dashboards__description,<commit_msg>add param for returning only favorite dashboards<commit_after>module Descartes
  class Web < Sinatra::Base

    get '/dashboards/?' do
      if request.accept.include?('application/json')
        @dashboards = []
        if params[:search]
          matching_dashboards = []
          params[:search].split(',').each do |search|
            matching_dashboards << Dashboard.select('dashboards.*'.lit, 'COUNT(graph_dashboard_relations.*) AS graph_count'.lit).
              from(:dashboards, :graph_dashboard_relations).
              where(:dashboards__enabled => true).
              where(:dashboards__id => :graph_dashboard_relations__dashboard_id).
              where(:dashboards__name.like(/#{search}/i)).
              group(:dashboards__id,
                    :dashboards__uuid,
                    :dashboards__owner,
                    :dashboards__name,
                    :dashboards__description,
                    :dashboards__configuration,
                    :dashboards__enabled,
                    :dashboards__created_at,
                    :dashboards__updated_at).
              order('LOWER(dashboards.name)'.lit).all
          end
          # Filter out duplicates
          known_dashboards = []
          matching_dashboards.flatten!
          matching_dashboards.each do |d|
            unless known_dashboards.include?(d.values[:id])
              known_dashboards.push(d.values[:id])
              @dashboards.push(d)
            end
          end
        elsif params[:favorites] == 'true'
          @dashboards << Dashboard.select('dashboards.*'.lit, 'COUNT(graph_dashboard_relations.*) AS graph_count'.lit).
            from(:dashboards, :graph_dashboard_relations, :users).
            where(:dashboards__enabled => true).
            where(:dashboards__id => :graph_dashboard_relations__dashboard_id).
            where(:dashboards__uuid => User.filter(:uid => session['user']['uid']).first.favorites).
            group(:dashboards__id,
                  :dashboards__uuid,
                  :dashboards__owner,
                  :dashboards__name,
                  :dashboards__description,
                  :dashboards__configuration,
                  :dashboards__enabled,
                  :dashboards__created_at,
                  :dashboards__updated_at).
            order('LOWER(dashboards.name)'.lit).all
        else
          @dashboards << Dashboard.select('dashboards.*'.lit, 'COUNT(graph_dashboard_relations.*) AS graph_count'.lit).
            from(:dashboards, :graph_dashboard_relations).
            where(:dashboards__enabled => true).
            where(:dashboards__id => :graph_dashboard_relations__dashboard_id).
            group(:dashboards__id,
                  :dashboards__uuid,
                  :dashboards__owner,
                  :dashboards__name,
                  :dashboards__description,
{'fraction_non_alphanumeric': 0.10246325812461188, 'fraction_numerical': 0.0, 'mean_word_length': 1.9284848484848485, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3811528', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1206, 'n_words': 175}