nexosis_api 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nexosis_api/algorithm.rb +22 -22
- data/lib/nexosis_api/algorithm_contestant.rb +43 -43
- data/lib/nexosis_api/calendar_jointarget.rb +35 -35
- data/lib/nexosis_api/classifier_result.rb +25 -25
- data/lib/nexosis_api/client/contest.rb +66 -66
- data/lib/nexosis_api/client/datasets.rb +155 -155
- data/lib/nexosis_api/client/imports.rb +141 -141
- data/lib/nexosis_api/client/models.rb +108 -108
- data/lib/nexosis_api/client/sessions.rb +213 -213
- data/lib/nexosis_api/client/views.rb +105 -105
- data/lib/nexosis_api/client.rb +118 -118
- data/lib/nexosis_api/column.rb +50 -50
- data/lib/nexosis_api/column_options.rb +38 -38
- data/lib/nexosis_api/column_role.rb +19 -19
- data/lib/nexosis_api/column_type.rb +23 -19
- data/lib/nexosis_api/dataset_data.rb +22 -22
- data/lib/nexosis_api/dataset_jointarget.rb +18 -18
- data/lib/nexosis_api/dataset_model.rb +26 -26
- data/lib/nexosis_api/dataset_summary.rb +33 -33
- data/lib/nexosis_api/http_exception.rb +28 -28
- data/lib/nexosis_api/impact_metric.rb +22 -22
- data/lib/nexosis_api/imports_response.rb +74 -79
- data/lib/nexosis_api/join.rb +63 -63
- data/lib/nexosis_api/link.rb +18 -18
- data/lib/nexosis_api/message.rb +19 -19
- data/lib/nexosis_api/metric.rb +16 -16
- data/lib/nexosis_api/model_summary.rb +66 -66
- data/lib/nexosis_api/paged_array.rb +35 -35
- data/lib/nexosis_api/predict_response.rb +35 -35
- data/lib/nexosis_api/session.rb +118 -118
- data/lib/nexosis_api/session_contest.rb +30 -30
- data/lib/nexosis_api/session_response.rb +33 -33
- data/lib/nexosis_api/session_result.rb +27 -27
- data/lib/nexosis_api/session_selection_metrics.rb +20 -20
- data/lib/nexosis_api/time_interval.rb +15 -15
- data/lib/nexosis_api/view_data.rb +14 -14
- data/lib/nexosis_api/view_definition.rb +64 -64
- data/lib/nexosis_api.rb +11 -11
- data/nexosisapi.gemspec +20 -20
- metadata +3 -3
@@ -1,105 +1,105 @@
|
|
1
|
-
module NexosisApi
|
2
|
-
# class to operate on views endpoint in Nexosis API
|
3
|
-
class Client
|
4
|
-
# Views-based API operations
|
5
|
-
# @see http://docs.nexosis.com/
|
6
|
-
# @since 1.2.0
|
7
|
-
module Views
|
8
|
-
## List all existing view defintions, optionally limited by
|
9
|
-
# partial name or participating data sources
|
10
|
-
# @param partial_name [String] optionally limit results by view name
|
11
|
-
# @param dataset_name [String] optionally limit results by dataset used in definition
|
12
|
-
# @param page [Integer] optionally get results by non-zero page - defaults to 0
|
13
|
-
# @param page_size [Integer] optionally limit page size - defaults to 50 (max: 1000)
|
14
|
-
# @return [NexosisApi::PagedArray of NexosisApi::ViewDefinition]
|
15
|
-
# @raise [NexosisApi::HttpException]
|
16
|
-
def list_views(partial_name = '', dataset_name = '', page = 0, page_size = 50)
|
17
|
-
url = '/views'
|
18
|
-
query = {
|
19
|
-
'page': page,
|
20
|
-
'pageSize': page_size
|
21
|
-
}
|
22
|
-
query.store 'partialName', partial_name if partial_name.empty? == false
|
23
|
-
query.store 'dataSetName', dataset_name if dataset_name.empty? == false
|
24
|
-
response = self.class.get(url, headers: @headers, query: query)
|
25
|
-
raise NexosisApi::HttpException('Could not retrieve list of views.', 'attempting list of views', response) unless response.success?
|
26
|
-
NexosisApi::PagedArray.new(response.parsed_response, response.parsed_response['items']
|
27
|
-
.map { |definition| NexosisApi::ViewDefinition.new(definition) })
|
28
|
-
end
|
29
|
-
|
30
|
-
# Create a new view or update an existing one by name
|
31
|
-
# @param view_name [String] the name of the view to create or update.
|
32
|
-
# @param dataset_name [String] the unique name of a data that is one source of this view.
|
33
|
-
# @param right_datasource_name [String] the additional data source to join in this view.
|
34
|
-
# @return [NexosisApi::ViewDefinition] - definition as created by API
|
35
|
-
# @note @view_name Must be unique within your organization
|
36
|
-
# @raise [NexosisApi::HttpException]
|
37
|
-
def create_view(view_name, dataset_name, right_datasource_name)
|
38
|
-
raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false
|
39
|
-
raise ArgumentError, 'dataset_name was not provided and is not optional' unless dataset_name.to_s.empty? == false
|
40
|
-
raise ArgumentError, 'right_datasource_name was not provided and is not optional' unless right_datasource_name.to_s.empty? == false
|
41
|
-
view_definition = NexosisApi::ViewDefinition.new('viewName' => view_name)
|
42
|
-
view_definition.dataset_name = dataset_name
|
43
|
-
join = NexosisApi::Join.new('dataSet' => { 'name' => right_datasource_name })
|
44
|
-
view_definition.joins = [join]
|
45
|
-
create_view_by_def(view_definition)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Create or update a view based on a view definition object
|
49
|
-
# @param view_definition [NexosisApi::ViewDefinition] an object populated with the view configuration to create
|
50
|
-
# @return [NexosisApi::ViewDefinition] - definition as created by API
|
51
|
-
# @raise [NexosisApi::HttpException]
|
52
|
-
def create_view_by_def(view_definition)
|
53
|
-
view_name = view_definition.view_name
|
54
|
-
raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false
|
55
|
-
url = "/views/#{view_name}"
|
56
|
-
response = self.class.put(url, headers: @headers, body: view_definition.to_json)
|
57
|
-
if response.success?
|
58
|
-
return NexosisApi::ViewDefinition.new(response.parsed_response)
|
59
|
-
else
|
60
|
-
raise NexosisApi::HttpException.new('Could not create the requested view',
|
61
|
-
"Attempting to create view named #{view_name}",
|
62
|
-
response)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Deletes the named view and optionally all sessions created from it
|
67
|
-
# @param view_name [String] the view to remove
|
68
|
-
# @param cascade [String] indicate any non-nil to remove associated sessions
|
69
|
-
# @return [void]
|
70
|
-
# @raise [NexosisApi::HttpException]
|
71
|
-
def remove_view(view_name, cascade = nil)
|
72
|
-
raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false
|
73
|
-
url = "/views/#{view_name}"
|
74
|
-
query = 'cascade=sessions' unless cascade.nil?
|
75
|
-
response = self.class.delete(url, headers: @headers, query: query)
|
76
|
-
unless response.success?
|
77
|
-
raise NexosisApi::HttpException.new('Could not delete view',
|
78
|
-
"Attempting to delete view #{view_name}",
|
79
|
-
response)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# Get the processed data from the view definition
|
84
|
-
#
|
85
|
-
# @param view_name [String] the unique name of the view for which to retrieve data
|
86
|
-
# @param page_number [Integer] zero-based page number of results to retrieve
|
87
|
-
# @param page_size [Integer] Count of results to retrieve in each page (max 1000).
|
88
|
-
# @param query_options [Hash] options hash for limiting and projecting returned results
|
89
|
-
# @note Query Options includes start_date as a DateTime or ISO 8601 compliant string,
|
90
|
-
# end_date, also as a DateTime or string, and :include as an Array of strings indicating the columns to return.
|
91
|
-
# The dates can be used independently and are inclusive. Lack of options returns all values within the given page.
|
92
|
-
# @note - the results include any transformations or imputations required to prepare the data for a session
|
93
|
-
# @raise [NexosisApi::HttpException]
|
94
|
-
def get_view(view_name, page_number = 0, page_size = 50, query_options = {})
|
95
|
-
raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false
|
96
|
-
url = "/views/#{view_name}"
|
97
|
-
response = self.class.get(url, headers: @headers,
|
98
|
-
query: create_query(page_number, page_size, query_options),
|
99
|
-
query_string_normalizer: ->(query_map) { array_query_normalizer(query_map) } )
|
100
|
-
raise NexosisApi::HttpException.new('Could not retrieve data for the given view', "Requesting data for view #{view_name}", response) unless response.success?
|
101
|
-
NexosisApi::ViewData.new(response.parsed_response)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
1
|
+
module NexosisApi
|
2
|
+
# class to operate on views endpoint in Nexosis API
|
3
|
+
class Client
|
4
|
+
# Views-based API operations
|
5
|
+
# @see http://docs.nexosis.com/
|
6
|
+
# @since 1.2.0
|
7
|
+
module Views
|
8
|
+
## List all existing view defintions, optionally limited by
|
9
|
+
# partial name or participating data sources
|
10
|
+
# @param partial_name [String] optionally limit results by view name
|
11
|
+
# @param dataset_name [String] optionally limit results by dataset used in definition
|
12
|
+
# @param page [Integer] optionally get results by non-zero page - defaults to 0
|
13
|
+
# @param page_size [Integer] optionally limit page size - defaults to 50 (max: 1000)
|
14
|
+
# @return [NexosisApi::PagedArray of NexosisApi::ViewDefinition]
|
15
|
+
# @raise [NexosisApi::HttpException]
|
16
|
+
def list_views(partial_name = '', dataset_name = '', page = 0, page_size = 50)
|
17
|
+
url = '/views'
|
18
|
+
query = {
|
19
|
+
'page': page,
|
20
|
+
'pageSize': page_size
|
21
|
+
}
|
22
|
+
query.store 'partialName', partial_name if partial_name.empty? == false
|
23
|
+
query.store 'dataSetName', dataset_name if dataset_name.empty? == false
|
24
|
+
response = self.class.get(url, headers: @headers, query: query)
|
25
|
+
raise NexosisApi::HttpException('Could not retrieve list of views.', 'attempting list of views', response) unless response.success?
|
26
|
+
NexosisApi::PagedArray.new(response.parsed_response, response.parsed_response['items']
|
27
|
+
.map { |definition| NexosisApi::ViewDefinition.new(definition) })
|
28
|
+
end
|
29
|
+
|
30
|
+
# Create a new view or update an existing one by name
|
31
|
+
# @param view_name [String] the name of the view to create or update.
|
32
|
+
# @param dataset_name [String] the unique name of a data that is one source of this view.
|
33
|
+
# @param right_datasource_name [String] the additional data source to join in this view.
|
34
|
+
# @return [NexosisApi::ViewDefinition] - definition as created by API
|
35
|
+
# @note @view_name Must be unique within your organization
|
36
|
+
# @raise [NexosisApi::HttpException]
|
37
|
+
def create_view(view_name, dataset_name, right_datasource_name)
|
38
|
+
raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false
|
39
|
+
raise ArgumentError, 'dataset_name was not provided and is not optional' unless dataset_name.to_s.empty? == false
|
40
|
+
raise ArgumentError, 'right_datasource_name was not provided and is not optional' unless right_datasource_name.to_s.empty? == false
|
41
|
+
view_definition = NexosisApi::ViewDefinition.new('viewName' => view_name)
|
42
|
+
view_definition.dataset_name = dataset_name
|
43
|
+
join = NexosisApi::Join.new('dataSet' => { 'name' => right_datasource_name })
|
44
|
+
view_definition.joins = [join]
|
45
|
+
create_view_by_def(view_definition)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create or update a view based on a view definition object
|
49
|
+
# @param view_definition [NexosisApi::ViewDefinition] an object populated with the view configuration to create
|
50
|
+
# @return [NexosisApi::ViewDefinition] - definition as created by API
|
51
|
+
# @raise [NexosisApi::HttpException]
|
52
|
+
def create_view_by_def(view_definition)
|
53
|
+
view_name = view_definition.view_name
|
54
|
+
raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false
|
55
|
+
url = "/views/#{view_name}"
|
56
|
+
response = self.class.put(url, headers: @headers, body: view_definition.to_json)
|
57
|
+
if response.success?
|
58
|
+
return NexosisApi::ViewDefinition.new(response.parsed_response)
|
59
|
+
else
|
60
|
+
raise NexosisApi::HttpException.new('Could not create the requested view',
|
61
|
+
"Attempting to create view named #{view_name}",
|
62
|
+
response)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Deletes the named view and optionally all sessions created from it
|
67
|
+
# @param view_name [String] the view to remove
|
68
|
+
# @param cascade [String] indicate any non-nil to remove associated sessions
|
69
|
+
# @return [void]
|
70
|
+
# @raise [NexosisApi::HttpException]
|
71
|
+
def remove_view(view_name, cascade = nil)
|
72
|
+
raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false
|
73
|
+
url = "/views/#{view_name}"
|
74
|
+
query = 'cascade=sessions' unless cascade.nil?
|
75
|
+
response = self.class.delete(url, headers: @headers, query: query)
|
76
|
+
unless response.success?
|
77
|
+
raise NexosisApi::HttpException.new('Could not delete view',
|
78
|
+
"Attempting to delete view #{view_name}",
|
79
|
+
response)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Get the processed data from the view definition
|
84
|
+
#
|
85
|
+
# @param view_name [String] the unique name of the view for which to retrieve data
|
86
|
+
# @param page_number [Integer] zero-based page number of results to retrieve
|
87
|
+
# @param page_size [Integer] Count of results to retrieve in each page (max 1000).
|
88
|
+
# @param query_options [Hash] options hash for limiting and projecting returned results
|
89
|
+
# @note Query Options includes start_date as a DateTime or ISO 8601 compliant string,
|
90
|
+
# end_date, also as a DateTime or string, and :include as an Array of strings indicating the columns to return.
|
91
|
+
# The dates can be used independently and are inclusive. Lack of options returns all values within the given page.
|
92
|
+
# @note - the results include any transformations or imputations required to prepare the data for a session
|
93
|
+
# @raise [NexosisApi::HttpException]
|
94
|
+
def get_view(view_name, page_number = 0, page_size = 50, query_options = {})
|
95
|
+
raise ArgumentError, 'view_name was not provided and is not optional' unless view_name.to_s.empty? == false
|
96
|
+
url = "/views/#{view_name}"
|
97
|
+
response = self.class.get(url, headers: @headers,
|
98
|
+
query: create_query(page_number, page_size, query_options),
|
99
|
+
query_string_normalizer: ->(query_map) { array_query_normalizer(query_map) } )
|
100
|
+
raise NexosisApi::HttpException.new('Could not retrieve data for the given view', "Requesting data for view #{view_name}", response) unless response.success?
|
101
|
+
NexosisApi::ViewData.new(response.parsed_response)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/nexosis_api/client.rb
CHANGED
@@ -1,118 +1,118 @@
|
|
1
|
-
require 'nexosis_api/algorithm_contestant'
|
2
|
-
require 'nexosis_api/algorithm'
|
3
|
-
require 'nexosis_api/calendar_jointarget'
|
4
|
-
require 'nexosis_api/classifier_result'
|
5
|
-
require 'nexosis_api/column'
|
6
|
-
require 'nexosis_api/column_options'
|
7
|
-
require 'nexosis_api/column_role'
|
8
|
-
require 'nexosis_api/column_type'
|
9
|
-
require 'nexosis_api/dataset_data'
|
10
|
-
require 'nexosis_api/dataset_jointarget'
|
11
|
-
require 'nexosis_api/dataset_model'
|
12
|
-
require 'nexosis_api/dataset_summary'
|
13
|
-
require 'nexosis_api/http_exception'
|
14
|
-
require 'nexosis_api/impact_metric'
|
15
|
-
require 'nexosis_api/imports_response'
|
16
|
-
require 'nexosis_api/join'
|
17
|
-
require 'nexosis_api/link'
|
18
|
-
require 'nexosis_api/message'
|
19
|
-
require 'nexosis_api/metric'
|
20
|
-
require 'nexosis_api/model_summary'
|
21
|
-
require 'nexosis_api/paged_array'
|
22
|
-
require 'nexosis_api/predict_response'
|
23
|
-
require 'nexosis_api/session_contest'
|
24
|
-
require 'nexosis_api/session_response'
|
25
|
-
require 'nexosis_api/session_result'
|
26
|
-
require 'nexosis_api/session_selection_metrics'
|
27
|
-
require 'nexosis_api/session'
|
28
|
-
require 'nexosis_api/time_interval'
|
29
|
-
require 'nexosis_api/view_definition'
|
30
|
-
require 'nexosis_api/view_data'
|
31
|
-
require 'nexosis_api/client/contest'
|
32
|
-
require 'nexosis_api/client/sessions'
|
33
|
-
require 'nexosis_api/client/datasets'
|
34
|
-
require 'nexosis_api/client/imports'
|
35
|
-
require 'nexosis_api/client/views'
|
36
|
-
require 'nexosis_api/client/models'
|
37
|
-
|
38
|
-
module NexosisApi
|
39
|
-
# Primary entry point to working with Nexosis API
|
40
|
-
class Client
|
41
|
-
include HTTParty
|
42
|
-
base_uri 'https://ml.nexosis.com/v1'
|
43
|
-
include Client::Sessions
|
44
|
-
include Client::Datasets
|
45
|
-
include Client::Imports
|
46
|
-
include Client::Views
|
47
|
-
include Client::Models
|
48
|
-
include Client::Contest
|
49
|
-
|
50
|
-
def initialize(options = {})
|
51
|
-
raise ArgumentError, 'api_key was not defined' unless options[:api_key].nil? == false
|
52
|
-
@api_key = options[:api_key]
|
53
|
-
self.class.base_uri options[:base_uri] unless options[:base_uri].nil?
|
54
|
-
@headers = { 'api-key' => @api_key, 'Content-Type' => 'application/json',
|
55
|
-
'User-Agent' => 'Nexosis-Ruby-API-Client/1.2' }
|
56
|
-
@options = { headers: @headers, format: :json }
|
57
|
-
end
|
58
|
-
|
59
|
-
# Gets the quota stats for the account
|
60
|
-
#
|
61
|
-
# @return [Hash] a hash of quota values and current values
|
62
|
-
def get_account_quotas()
|
63
|
-
session_url = '/sessions?page=0&pageSize=1'
|
64
|
-
response = self.class.get(session_url, @options)
|
65
|
-
response.headers.select { |k, _v| k.to_s.start_with? 'nexosis-account' }
|
66
|
-
end
|
67
|
-
|
68
|
-
# Provide access to read or modify the api key
|
69
|
-
# @return [String]
|
70
|
-
# @since 2.0.0
|
71
|
-
def api_key(value)
|
72
|
-
@api_key = value unless value.nil?
|
73
|
-
@headers['api-key'] = @api_key
|
74
|
-
@api_key
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
# @private
|
80
|
-
def process_csv_to_s csv
|
81
|
-
content = ''
|
82
|
-
if(csv.is_a?(CSV))
|
83
|
-
csv.each do |row|
|
84
|
-
if(csv.headers.nil?)
|
85
|
-
# not using row.to_csv because it uses non-compliant '\n' newline
|
86
|
-
content.concat(row.join(',')).concat("\r\n")
|
87
|
-
else
|
88
|
-
content.concat(row.fields.join(',')).concat("\r\n")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
if(csv.headers.nil? == false)
|
92
|
-
content.prepend(csv.headers.join(',').concat("\r\n")) unless csv.headers.nil?
|
93
|
-
end
|
94
|
-
else
|
95
|
-
content = csv
|
96
|
-
end
|
97
|
-
content
|
98
|
-
end
|
99
|
-
|
100
|
-
# @private
|
101
|
-
def create_query(page_number, page_size, options = {})
|
102
|
-
options.store(:page_number, page_number)
|
103
|
-
options.store(:page_size, page_size)
|
104
|
-
query = {
|
105
|
-
'page' => [page_number],
|
106
|
-
'pageSize' => [page_size]
|
107
|
-
}
|
108
|
-
query['startDate'] = [options[:start_date].iso8601.gsub(/\+/,'%2B')] unless options[:start_date].nil?
|
109
|
-
query['endDate'] = [options[:end_date].iso8601.gsub(/\+/,'%2B')] unless options[:end_date].nil?
|
110
|
-
query['include'] = options[:include] unless options[:include].nil?
|
111
|
-
query
|
112
|
-
end
|
113
|
-
|
114
|
-
def array_query_normalizer(query_set)
|
115
|
-
query_set.map { |key, value| value.map { |v| "#{key}=#{v}" } }.join('&')
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
1
|
+
require 'nexosis_api/algorithm_contestant'
|
2
|
+
require 'nexosis_api/algorithm'
|
3
|
+
require 'nexosis_api/calendar_jointarget'
|
4
|
+
require 'nexosis_api/classifier_result'
|
5
|
+
require 'nexosis_api/column'
|
6
|
+
require 'nexosis_api/column_options'
|
7
|
+
require 'nexosis_api/column_role'
|
8
|
+
require 'nexosis_api/column_type'
|
9
|
+
require 'nexosis_api/dataset_data'
|
10
|
+
require 'nexosis_api/dataset_jointarget'
|
11
|
+
require 'nexosis_api/dataset_model'
|
12
|
+
require 'nexosis_api/dataset_summary'
|
13
|
+
require 'nexosis_api/http_exception'
|
14
|
+
require 'nexosis_api/impact_metric'
|
15
|
+
require 'nexosis_api/imports_response'
|
16
|
+
require 'nexosis_api/join'
|
17
|
+
require 'nexosis_api/link'
|
18
|
+
require 'nexosis_api/message'
|
19
|
+
require 'nexosis_api/metric'
|
20
|
+
require 'nexosis_api/model_summary'
|
21
|
+
require 'nexosis_api/paged_array'
|
22
|
+
require 'nexosis_api/predict_response'
|
23
|
+
require 'nexosis_api/session_contest'
|
24
|
+
require 'nexosis_api/session_response'
|
25
|
+
require 'nexosis_api/session_result'
|
26
|
+
require 'nexosis_api/session_selection_metrics'
|
27
|
+
require 'nexosis_api/session'
|
28
|
+
require 'nexosis_api/time_interval'
|
29
|
+
require 'nexosis_api/view_definition'
|
30
|
+
require 'nexosis_api/view_data'
|
31
|
+
require 'nexosis_api/client/contest'
|
32
|
+
require 'nexosis_api/client/sessions'
|
33
|
+
require 'nexosis_api/client/datasets'
|
34
|
+
require 'nexosis_api/client/imports'
|
35
|
+
require 'nexosis_api/client/views'
|
36
|
+
require 'nexosis_api/client/models'
|
37
|
+
|
38
|
+
module NexosisApi
|
39
|
+
# Primary entry point to working with Nexosis API
|
40
|
+
class Client
|
41
|
+
include HTTParty
|
42
|
+
base_uri 'https://ml.nexosis.com/v1'
|
43
|
+
include Client::Sessions
|
44
|
+
include Client::Datasets
|
45
|
+
include Client::Imports
|
46
|
+
include Client::Views
|
47
|
+
include Client::Models
|
48
|
+
include Client::Contest
|
49
|
+
|
50
|
+
def initialize(options = {})
|
51
|
+
raise ArgumentError, 'api_key was not defined' unless options[:api_key].nil? == false
|
52
|
+
@api_key = options[:api_key]
|
53
|
+
self.class.base_uri options[:base_uri] unless options[:base_uri].nil?
|
54
|
+
@headers = { 'api-key' => @api_key, 'Content-Type' => 'application/json',
|
55
|
+
'User-Agent' => 'Nexosis-Ruby-API-Client/1.2' }
|
56
|
+
@options = { headers: @headers, format: :json }
|
57
|
+
end
|
58
|
+
|
59
|
+
# Gets the quota stats for the account
|
60
|
+
#
|
61
|
+
# @return [Hash] a hash of quota values and current values
|
62
|
+
def get_account_quotas()
|
63
|
+
session_url = '/sessions?page=0&pageSize=1'
|
64
|
+
response = self.class.get(session_url, @options)
|
65
|
+
response.headers.select { |k, _v| k.to_s.start_with? 'nexosis-account' }
|
66
|
+
end
|
67
|
+
|
68
|
+
# Provide access to read or modify the api key
|
69
|
+
# @return [String]
|
70
|
+
# @since 2.0.0
|
71
|
+
def api_key(value)
|
72
|
+
@api_key = value unless value.nil?
|
73
|
+
@headers['api-key'] = @api_key
|
74
|
+
@api_key
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
# @private
|
80
|
+
def process_csv_to_s csv
|
81
|
+
content = ''
|
82
|
+
if(csv.is_a?(CSV))
|
83
|
+
csv.each do |row|
|
84
|
+
if(csv.headers.nil?)
|
85
|
+
# not using row.to_csv because it uses non-compliant '\n' newline
|
86
|
+
content.concat(row.join(',')).concat("\r\n")
|
87
|
+
else
|
88
|
+
content.concat(row.fields.join(',')).concat("\r\n")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
if(csv.headers.nil? == false)
|
92
|
+
content.prepend(csv.headers.join(',').concat("\r\n")) unless csv.headers.nil?
|
93
|
+
end
|
94
|
+
else
|
95
|
+
content = csv
|
96
|
+
end
|
97
|
+
content
|
98
|
+
end
|
99
|
+
|
100
|
+
# @private
|
101
|
+
def create_query(page_number, page_size, options = {})
|
102
|
+
options.store(:page_number, page_number)
|
103
|
+
options.store(:page_size, page_size)
|
104
|
+
query = {
|
105
|
+
'page' => [page_number],
|
106
|
+
'pageSize' => [page_size]
|
107
|
+
}
|
108
|
+
query['startDate'] = [options[:start_date].iso8601.gsub(/\+/,'%2B')] unless options[:start_date].nil?
|
109
|
+
query['endDate'] = [options[:end_date].iso8601.gsub(/\+/,'%2B')] unless options[:end_date].nil?
|
110
|
+
query['include'] = options[:include] unless options[:include].nil?
|
111
|
+
query
|
112
|
+
end
|
113
|
+
|
114
|
+
def array_query_normalizer(query_set)
|
115
|
+
query_set.map { |key, value| value.map { |v| "#{key}=#{v}" } }.join('&')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/lib/nexosis_api/column.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
1
|
-
module NexosisApi
|
2
|
-
# class to hold the parsed results of column metadata
|
3
|
-
class Column
|
4
|
-
def initialize(column_name, value_hash)
|
5
|
-
@name = column_name
|
6
|
-
@type = NexosisApi::ColumnType.const_get(value_hash['dataType'].upcase) unless value_hash['dataType'].nil?
|
7
|
-
@role = NexosisApi::ColumnRole.const_get(value_hash['role'].upcase) unless value_hash['role'].nil?
|
8
|
-
@imputation = value_hash['imputation'] unless value_hash['imputation'].nil?
|
9
|
-
@aggregation = value_hash['aggregation'] unless value_hash['aggregation'].nil?
|
10
|
-
end
|
11
|
-
# The column header, label, or name
|
12
|
-
# @return [String]
|
13
|
-
attr_accessor :name
|
14
|
-
|
15
|
-
# The data type of this column
|
16
|
-
# @note Either string, numeric, logical, or date
|
17
|
-
# @return [NexosisApi::ColumnType]
|
18
|
-
attr_accessor :type
|
19
|
-
|
20
|
-
# The role of this column
|
21
|
-
# @note Either none, timestamp, target, or feature
|
22
|
-
# @return [NexosisApi::ColumnRole]
|
23
|
-
attr_accessor :role
|
24
|
-
|
25
|
-
# The strategy used to imput missing values
|
26
|
-
# @note Either Zeroes, Mean, Median, or Mode
|
27
|
-
# @return [String]
|
28
|
-
attr_accessor :imputation
|
29
|
-
|
30
|
-
# The strategy used to aggregate data if requested prediction period is greater than observation period
|
31
|
-
# @note Either Sum, Mean, Median, or Mode
|
32
|
-
# @return [String]
|
33
|
-
attr_accessor :aggregation
|
34
|
-
|
35
|
-
# utility method to format a column description in the way it is expected on input
|
36
|
-
def to_hash
|
37
|
-
{ name => { 'dataType' => type.to_s,
|
38
|
-
'role' => role.to_s,
|
39
|
-
'imputation' => imputation.to_s,
|
40
|
-
'aggregation' => aggregation.to_s } }
|
41
|
-
end
|
42
|
-
|
43
|
-
# allows json to be built for api requests
|
44
|
-
def self.to_json(column_array)
|
45
|
-
result = {}
|
46
|
-
column_array.each { |col| result[col.to_hash.keys[0]] = col.to_hash.values[0] }
|
47
|
-
result
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
1
|
+
module NexosisApi
|
2
|
+
# class to hold the parsed results of column metadata
|
3
|
+
class Column
|
4
|
+
def initialize(column_name, value_hash)
|
5
|
+
@name = column_name
|
6
|
+
@type = NexosisApi::ColumnType.const_get(value_hash['dataType'].upcase) unless value_hash['dataType'].nil?
|
7
|
+
@role = NexosisApi::ColumnRole.const_get(value_hash['role'].upcase) unless value_hash['role'].nil?
|
8
|
+
@imputation = value_hash['imputation'] unless value_hash['imputation'].nil?
|
9
|
+
@aggregation = value_hash['aggregation'] unless value_hash['aggregation'].nil?
|
10
|
+
end
|
11
|
+
# The column header, label, or name
|
12
|
+
# @return [String]
|
13
|
+
attr_accessor :name
|
14
|
+
|
15
|
+
# The data type of this column
|
16
|
+
# @note Either string, numeric, logical, or date
|
17
|
+
# @return [NexosisApi::ColumnType]
|
18
|
+
attr_accessor :type
|
19
|
+
|
20
|
+
# The role of this column
|
21
|
+
# @note Either none, timestamp, target, or feature
|
22
|
+
# @return [NexosisApi::ColumnRole]
|
23
|
+
attr_accessor :role
|
24
|
+
|
25
|
+
# The strategy used to imput missing values
|
26
|
+
# @note Either Zeroes, Mean, Median, or Mode
|
27
|
+
# @return [String]
|
28
|
+
attr_accessor :imputation
|
29
|
+
|
30
|
+
# The strategy used to aggregate data if requested prediction period is greater than observation period
|
31
|
+
# @note Either Sum, Mean, Median, or Mode
|
32
|
+
# @return [String]
|
33
|
+
attr_accessor :aggregation
|
34
|
+
|
35
|
+
# utility method to format a column description in the way it is expected on input
|
36
|
+
def to_hash
|
37
|
+
{ name => { 'dataType' => type.to_s,
|
38
|
+
'role' => role.to_s,
|
39
|
+
'imputation' => imputation.to_s,
|
40
|
+
'aggregation' => aggregation.to_s } }
|
41
|
+
end
|
42
|
+
|
43
|
+
# allows json to be built for api requests
|
44
|
+
def self.to_json(column_array)
|
45
|
+
result = {}
|
46
|
+
column_array.each { |col| result[col.to_hash.keys[0]] = col.to_hash.values[0] }
|
47
|
+
result
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
module NexosisApi
|
2
|
-
# Class for holding the join options on a column in a view-based join
|
3
|
-
# @since 1.2.0
|
4
|
-
class ColumnOptions
|
5
|
-
# Create a new option for a join column.
|
6
|
-
# @param column_name [String] the name of the original column from the source dataset
|
7
|
-
# @param options_hash [Hash] additional information about how to process the column in a join
|
8
|
-
def initialize(column_name, options_hash)
|
9
|
-
@column_name = column_name
|
10
|
-
@join_interval = NexosisApi::TimeInterval.const_get(options_hash['joinInterval'].upcase) unless options_hash['joinInterval'].nil?
|
11
|
-
@alias = options_hash['alias']
|
12
|
-
end
|
13
|
-
|
14
|
-
# The name of the column on which these options are applied
|
15
|
-
# @return [String]
|
16
|
-
attr_accessor :column_name
|
17
|
-
|
18
|
-
# Optional interval of a time series column being joined to another time series
|
19
|
-
# @note not valid outside of join defintion
|
20
|
-
# @return [NexosisApi::TimeInterval]
|
21
|
-
attr_accessor :join_interval
|
22
|
-
|
23
|
-
# Optional alias of the column when participating in a join
|
24
|
-
# @note An alias can be used to keep two same-named columns distinct
|
25
|
-
# or to merge two distinctly named columns. By default same-named columns
|
26
|
-
# on two sides of a join will be merged.
|
27
|
-
# @return [String]
|
28
|
-
attr_accessor :alias
|
29
|
-
|
30
|
-
# builds a custom hash which will match api requests
|
31
|
-
def to_hash
|
32
|
-
hash = { column_name => {} }
|
33
|
-
hash[column_name]['join_interval'] = join_interval.to_s unless join_interval.nil?
|
34
|
-
hash[column_name]['alias'] = @alias.to_s unless @alias.nil?
|
35
|
-
hash
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
module NexosisApi
|
2
|
+
# Class for holding the join options on a column in a view-based join
|
3
|
+
# @since 1.2.0
|
4
|
+
class ColumnOptions
|
5
|
+
# Create a new option for a join column.
|
6
|
+
# @param column_name [String] the name of the original column from the source dataset
|
7
|
+
# @param options_hash [Hash] additional information about how to process the column in a join
|
8
|
+
def initialize(column_name, options_hash)
|
9
|
+
@column_name = column_name
|
10
|
+
@join_interval = NexosisApi::TimeInterval.const_get(options_hash['joinInterval'].upcase) unless options_hash['joinInterval'].nil?
|
11
|
+
@alias = options_hash['alias']
|
12
|
+
end
|
13
|
+
|
14
|
+
# The name of the column on which these options are applied
|
15
|
+
# @return [String]
|
16
|
+
attr_accessor :column_name
|
17
|
+
|
18
|
+
# Optional interval of a time series column being joined to another time series
|
19
|
+
# @note not valid outside of join defintion
|
20
|
+
# @return [NexosisApi::TimeInterval]
|
21
|
+
attr_accessor :join_interval
|
22
|
+
|
23
|
+
# Optional alias of the column when participating in a join
|
24
|
+
# @note An alias can be used to keep two same-named columns distinct
|
25
|
+
# or to merge two distinctly named columns. By default same-named columns
|
26
|
+
# on two sides of a join will be merged.
|
27
|
+
# @return [String]
|
28
|
+
attr_accessor :alias
|
29
|
+
|
30
|
+
# builds a custom hash which will match api requests
|
31
|
+
def to_hash
|
32
|
+
hash = { column_name => {} }
|
33
|
+
hash[column_name]['join_interval'] = join_interval.to_s unless join_interval.nil?
|
34
|
+
hash[column_name]['alias'] = @alias.to_s unless @alias.nil?
|
35
|
+
hash
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|