class Datarobot::AiApi::Dataset

Attributes

ai_id[R]
created_at[R]
id[R]
name[RW]
task[R]

Public Class Methods

all(limit: 50, offset: 0) click to toggle source

Retrieves all datasets as a paginated resource.

@param [Integer] limit Number of datasets per page @param [Integer] offset How many datasets to skip before this page

@return [Datarobot::AiApi::Page(Datarobot::AiApi::Dataset)]

# File lib/datarobot/ai_api/dataset.rb, line 14
def self.all(limit: 50, offset: 0)
  Datarobot::AiApi.request_endpoint('/aiapi/datasets/', params: {limit: limit, offset: offset}) do |data|
    Datarobot::AiApi::Page.new(self, data)
  end
end
create_from_file(file_path) click to toggle source

Creates a dataset from the file at the given (local) path

@param [String] file_path The path to the file to upload

@return [Datarobot::AiApi::Dataset]

# File lib/datarobot/ai_api/dataset.rb, line 51
def self.create_from_file(file_path)
  Datarobot::AiApi.upload_to_endpoint('/aiapi/datasets/fileImports', file_path) do |data|
    task = Datarobot::AiApi::Task.new(data)
    task.wait_until_complete
  end
end
create_from_url(url) click to toggle source

Creates a dataset from the file at the given (publicly accessible) url

@param [String] url The url to the file to upload

@return [Datarobot::AiApi::Dataset]

# File lib/datarobot/ai_api/dataset.rb, line 63
def self.create_from_url(url)
  uri = URI.parse(url)
  name = File.basename(uri.path)
  Datarobot::AiApi.request_endpoint("/aiapi/datasets/urlImports/", method: "post", body: {url: url}) do |data|
    dataset = new(data)
    dataset.name = name
    dataset
  end
end
delete(id) click to toggle source

Deletes a dataset. Returns `nil` if the action was successful. Will raise an error if the action was unsuccessful

@param [String] id The ID of the dataset to delete

@return [nil]

# File lib/datarobot/ai_api/dataset.rb, line 42
def self.delete(id)
  Datarobot::AiApi.request_endpoint("/aiapi/datasets/#{id}", method: "delete")
end
find(id) { |data| ... } click to toggle source

Retrieves an dataset given an ID.

@param [String] id The ID of the dataset to retrieve

@return [Datarobot::AiApi::Dataset]

# File lib/datarobot/ai_api/dataset.rb, line 25
def self.find(id, &block)
  raise Datarobot::AiApi::NotFoundError, "Cannot find Dataset with id: nil" if id.nil?
  Datarobot::AiApi.request_endpoint("/aiapi/datasets/#{id}") do |data|
    if block_given?
      yield data
    else
      self.new(data)
    end
  end
end
new(options = {}) click to toggle source

Given a parsed response body from the API, will create a new Dataset object

# File lib/datarobot/ai_api/dataset.rb, line 74
def initialize(options = {})
  # Suppresses warnings about uninitialized variables
  @ai_id = nil
  @name = nil
  @created_at = nil

  set_from_options(options)
end

Public Instance Methods

set_from_options(options = {}) click to toggle source

Takes a response body from the API. Will set all Dataset attributes from the response body

@param [Hash] options A parsed response body @return [void]

# File lib/datarobot/ai_api/dataset.rb, line 88
def set_from_options(options = {})
  # one-liner replacement for `stringify_keys`
  options = options.collect{|k,v| [k.to_s, v]}.to_h

  @created_at = options.dig("createdOn") || @created_at
  @name = options.dig("datasetName") || options.dig("name") || @name
  @id = options.dig("id") || options.dig("datasetId") || @id
  @ai_id = options.dig("aiId") || @ai_id
end