<commit_before>module Api
  module V3
    class ConvertersController < BaseController
      before_filter :set_current_scenario, :only => :show
      before_filter :find_converter, :only => :show

      # GET /api/v3/converters/:id
      #
      # Returns the converter details in JSON format. If the scenario is missing
      # the action returns an empty hash and a 404 status code. Since the
      # converters now aren't stored in a db table we use the key rather than
      # the id
      #
      def show
        render :json => @converter
      end

      # returns the converter topology coordinates, using the old
      # converter_positions table
      #
      def topology
        render :json => ConverterPosition.not_hidden.map {|c|
          { key: c.converter_key, x: c.x, y: c.y }
        }
      end

      private

      def find_converter
        key = params[:id].to_sym rescue nil
        @converter = ConverterPresenter.new(key, @scenario)
      rescue Exception => e
        render :json => {:errors => [e.message]}, :status => 404 and return
      end
    end
  end
end<commit_msg>API topology: return only valid converter_positions<commit_after>module Api
  module V3
    class ConvertersController < BaseController
      before_filter :set_current_scenario, :only => :show
      before_filter :find_converter, :only => :show

      # GET /api/v3/converters/:id
      #
      # Returns the converter details in JSON format. If the scenario is missing
      # the action returns an empty hash and a 404 status code. Since the
      # converters now aren't stored in a db table we use the key rather than
      # the id
      #
      def show
        render :json => @converter
      end

      # returns the converter topology coordinates, using the old
      # converter_positions table
      #
      def topology
        converters = ConverterPosition.not_hidden.where("converter_key IS NOT NULL")
        out = {
          :converters => converters.map {|c| { key: c.converter_key, x: c.x, y: c.y } },
          :links => []
        }
        render :json => out
      end

      private

      def find_converter
        key = params[:id].to_sym rescue nil
        @converter = ConverterPresenter.new(key, @scenario)
      rescue Exception => e
        render :json => {:errors => [e.message]}, :status => 404 and return
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08122895622895623, 'fraction_numerical': 0.006734006734006734, 'mean_word_length': 2.234013605442177, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '6605821', 'n_tokens_mistral': 700, 'n_tokens_neox': 667, 'n_words': 237}