<commit_before>class DatasetService
  include DatasetFieldsHelper

  @conn ||= Faraday.new(:url => ENV.fetch("API_URL") + '/v1') do |faraday|
    faraday.request :url_encoded
    faraday.response :logger, Rails.logger #, bodies: true # Activate this only for specific debugging
    faraday.adapter Faraday.default_adapter
  end

  # Gets all the existing datasets
  # This was changed in the new version of the API, and now it's paginated...
  # ... so this will get the first 10000 records
  # Params
  # ++status++ the status of the dataset
  def self.get_datasets(status = 'saved')
    datasetRequest = @conn.get '/dataset', {'page[number]': '1', 'page[size]': '10000', \
      'status': status, 'app': 'forest-atlas,gfw', '_': Time.now.to_f}
    datasetsJSON = JSON.parse datasetRequest.body
    datasets = []

    begin
      datasetsJSON['data'].each do |data|
        # TODO: Refactor!!! The service can't depend on the model
        dataset = Dataset.new data
        datasets.push dataset
      end
    rescue Exception => e
      # TODO All this methods should throw an exception caught in the controller...
      # ... to render a different page<commit_msg>Param name changed<commit_after>class DatasetService
  include DatasetFieldsHelper

  @conn ||= Faraday.new(:url => ENV.fetch("API_URL") + '/v1') do |faraday|
    faraday.request :url_encoded
    faraday.response :logger, Rails.logger #, bodies: true # Activate this only for specific debugging
    faraday.adapter Faraday.default_adapter
  end

  # Gets all the existing datasets
  # This was changed in the new version of the API, and now it's paginated...
  # ... so this will get the first 10000 records
  # Params
  # ++status++ the status of the dataset
  def self.get_datasets(status = 'saved')
    datasetRequest = @conn.get '/dataset', {'page[number]': '1', 'page[size]': '10000', \
      'status': status, 'application': 'forest-atlas,gfw', '_': Time.now.to_f}
    datasetsJSON = JSON.parse datasetRequest.body
    datasets = []

    begin
      datasetsJSON['data'].each do |data|
        # TODO: Refactor!!! The service can't depend on the model
        dataset = Dataset.new data
        datasets.push dataset
      end
    rescue Exception => e
      # TODO All this methods should throw an exception caught in the controller...
      # ... to render a different page
{'fraction_non_alphanumeric': 0.11409110259684972, 'fraction_numerical': 0.010217113665389528, 'mean_word_length': 3.1740674955595027, 'pattern_counts': {'":': 0, '<': 3, '<?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': '947625', 'n_tokens_mistral': 709, 'n_tokens_neox': 674, 'n_words': 237}