Class: Datarobot::AiApi::Dataset

Inherits:
Object
  • Object
show all
Includes:
Refreshable
Defined in:
lib/datarobot/ai_api/dataset.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Refreshable

#refresh, #refresh!

Constructor Details

#initialize(options = {}) ⇒ Dataset

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



74
75
76
77
78
79
80
81
# 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

Instance Attribute Details

#ai_idObject (readonly)

Returns the value of attribute ai_id.



6
7
8
# File 'lib/datarobot/ai_api/dataset.rb', line 6

def ai_id
  @ai_id
end

#created_atObject (readonly)

Returns the value of attribute created_at.



6
7
8
# File 'lib/datarobot/ai_api/dataset.rb', line 6

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/datarobot/ai_api/dataset.rb', line 6

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/datarobot/ai_api/dataset.rb', line 5

def name
  @name
end

#taskObject (readonly)

Returns the value of attribute task.



6
7
8
# File 'lib/datarobot/ai_api/dataset.rb', line 6

def task
  @task
end

Class Method Details

.all(limit: 50, offset: 0) ⇒ Datarobot::AiApi::Page(Datarobot::AiApi::Dataset)

Retrieves all datasets as a paginated resource.

Parameters:

  • limit (Integer) (defaults to: 50)

    Number of datasets per page

  • offset (Integer) (defaults to: 0)

    How many datasets to skip before this page

Returns:



14
15
16
17
18
# 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) ⇒ Datarobot::AiApi::Dataset

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

Parameters:

  • file_path (String)

    The path to the file to upload

Returns:



51
52
53
54
55
56
# 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) ⇒ Datarobot::AiApi::Dataset

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

Parameters:

  • url (String)

    The url to the file to upload

Returns:



63
64
65
66
67
68
69
70
71
# 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) ⇒ nil

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

Parameters:

  • id (String)

    The ID of the dataset to delete

Returns:

  • (nil)


42
43
44
# 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, &block) ⇒ Datarobot::AiApi::Dataset

Retrieves an dataset given an ID.

Parameters:

  • id (String)

    The ID of the dataset to retrieve

Returns:

Raises:



25
26
27
28
29
30
31
32
33
34
# 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

Instance Method Details

#set_from_options(options = {}) ⇒ void

This method returns an undefined value.

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

Parameters:

  • options (Hash) (defaults to: {})

    A parsed response body



88
89
90
91
92
93
94
95
96
# 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