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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nexosis_api/algorithm.rb +22 -22
  3. data/lib/nexosis_api/algorithm_contestant.rb +43 -43
  4. data/lib/nexosis_api/calendar_jointarget.rb +35 -35
  5. data/lib/nexosis_api/classifier_result.rb +25 -25
  6. data/lib/nexosis_api/client/contest.rb +66 -66
  7. data/lib/nexosis_api/client/datasets.rb +155 -155
  8. data/lib/nexosis_api/client/imports.rb +141 -141
  9. data/lib/nexosis_api/client/models.rb +108 -108
  10. data/lib/nexosis_api/client/sessions.rb +213 -213
  11. data/lib/nexosis_api/client/views.rb +105 -105
  12. data/lib/nexosis_api/client.rb +118 -118
  13. data/lib/nexosis_api/column.rb +50 -50
  14. data/lib/nexosis_api/column_options.rb +38 -38
  15. data/lib/nexosis_api/column_role.rb +19 -19
  16. data/lib/nexosis_api/column_type.rb +23 -19
  17. data/lib/nexosis_api/dataset_data.rb +22 -22
  18. data/lib/nexosis_api/dataset_jointarget.rb +18 -18
  19. data/lib/nexosis_api/dataset_model.rb +26 -26
  20. data/lib/nexosis_api/dataset_summary.rb +33 -33
  21. data/lib/nexosis_api/http_exception.rb +28 -28
  22. data/lib/nexosis_api/impact_metric.rb +22 -22
  23. data/lib/nexosis_api/imports_response.rb +74 -79
  24. data/lib/nexosis_api/join.rb +63 -63
  25. data/lib/nexosis_api/link.rb +18 -18
  26. data/lib/nexosis_api/message.rb +19 -19
  27. data/lib/nexosis_api/metric.rb +16 -16
  28. data/lib/nexosis_api/model_summary.rb +66 -66
  29. data/lib/nexosis_api/paged_array.rb +35 -35
  30. data/lib/nexosis_api/predict_response.rb +35 -35
  31. data/lib/nexosis_api/session.rb +118 -118
  32. data/lib/nexosis_api/session_contest.rb +30 -30
  33. data/lib/nexosis_api/session_response.rb +33 -33
  34. data/lib/nexosis_api/session_result.rb +27 -27
  35. data/lib/nexosis_api/session_selection_metrics.rb +20 -20
  36. data/lib/nexosis_api/time_interval.rb +15 -15
  37. data/lib/nexosis_api/view_data.rb +14 -14
  38. data/lib/nexosis_api/view_definition.rb +64 -64
  39. data/lib/nexosis_api.rb +11 -11
  40. data/nexosisapi.gemspec +20 -20
  41. metadata +3 -3
@@ -1,118 +1,118 @@
1
- module NexosisApi
2
- # Class for parsing the results of a session based request
3
- class Session
4
- def initialize(session_hash)
5
- val_map = { 'resultInterval' => :@result_interval,
6
- 'dataSourceName' => :@datasource_name,
7
- 'modelId' => :@model_id,
8
- 'sessionId' => :@session_id,
9
- 'availablePredictionIntervals' => :@prediction_intervals,
10
- 'startDate' => :@start_date,
11
- 'endDate' => :@end_date,
12
- 'predictionDomain' => :@prediction_domain,
13
- 'extraParameters' => :@extra_parameters,
14
- 'targetColumn' => :@target_column,
15
- 'statusHistory' => :@status_history }
16
- session_hash.each do |k, v|
17
- if (k == 'links')
18
- @links = v.map { |l| NexosisApi::Link.new(l) }
19
- elsif (k == 'columns')
20
- @column_metadata = v.reject { |_key, value| value.nil? }
21
- .map do |col_key, col_val|
22
- NexosisApi::Column.new(col_key, v[col_key])
23
- end
24
- elsif (k == 'requestedDate')
25
- @requested_date = DateTime.parse(v)
26
- elsif (k == 'messages')
27
- @messages = v.map { |m| NexosisApi::Message.new(m) } unless v.empty?
28
- else
29
- instance_variable_set("@#{k}", v) unless v.nil?
30
- end
31
- instance_variable_set(val_map[k.to_s], v) unless val_map[k.to_s].nil?
32
- end
33
- end
34
-
35
- # identifier for this sesssion
36
- # @return [String]
37
- # @since 1.4.0
38
- attr_accessor :session_id
39
-
40
- # What type of analysis was run during this session
41
- # @return [String]
42
- attr_accessor :type
43
-
44
- # Is this session requested, started, or completed
45
- # @return [String]
46
- attr_accessor :status
47
-
48
- # Date and status of each status this session has entered
49
- # @return [Array of Hash]
50
- # @note - each status object in array is form { date: 'date', status: 'status' }
51
- attr_accessor :status_history
52
-
53
- # reserved for future extensions
54
- # @return [Hash]
55
- # @note - included 'balance' parameter for classification models
56
- attr_accessor :extra_parameters
57
-
58
- # The column in the dataset for which this session ran predictions
59
- # @return [String]
60
- attr_accessor :target_column
61
-
62
- # The start date of analysis in this session
63
- # @return [DateTime]
64
- # @since 1.4.0
65
- attr_accessor :start_date
66
-
67
- # The end date of analysis in this session
68
- # @return [DateTime]
69
- # @since 1.4.0
70
- attr_accessor :end_date
71
-
72
- # associated hypermedia
73
- # @return [Array of NexosisApi::Link]
74
- attr_accessor :links
75
-
76
- # The column descriptors for the data in this session
77
- # will reflect either the metadata sent in, defaults form dataset, or inferred values
78
- # @return[Array of NexosisApi::Column]
79
- attr_accessor :column_metadata
80
-
81
- # The requested result interval. Default is DAY if none was requested during session creation.
82
- # @return [NexosisApi::TimeInterval]
83
- attr_accessor :result_interval
84
-
85
- # The name of the datasource used to run this session
86
- # @return [String] - the dataset or view name
87
- # @since 1.2.0
88
- attr_accessor :datasource_name
89
-
90
- # The date this session was orginally submitted
91
- # @since 1.3.0
92
- attr_accessor :requested_date
93
-
94
- # The id of the model created by this session if any
95
- # @return [String] a uuid/buid format unique string for the model
96
- # @since 1.3.0
97
- # @note This is always empty in time-series sessions (forecast/impact)
98
- # The model id returned here should be used in all future calls
99
- # to model endpoints - primarily the /models/{model_id}/predict endpoint.
100
- attr_accessor :model_id
101
-
102
- # An array of the prediction intervals available for this session's results
103
- # @return [Array]
104
- # @note - by default the .5 interval will be returned in results. Consult
105
- # this list for other intervals which can be requested.
106
- # @since 1.4.0
107
- attr_accessor :prediction_intervals
108
-
109
- # The type of model if a model creation session
110
- # @return [String]
111
- # @since 1.4.1
112
- attr_accessor :prediction_domain
113
-
114
- # A list of warning or error messages optionally returned from session
115
- # @return [Array of Message]
116
- attr_accessor :messages
117
- end
118
- end
1
+ module NexosisApi
2
+ # Class for parsing the results of a session based request
3
+ class Session
4
+ def initialize(session_hash)
5
+ val_map = { 'resultInterval' => :@result_interval,
6
+ 'dataSourceName' => :@datasource_name,
7
+ 'modelId' => :@model_id,
8
+ 'sessionId' => :@session_id,
9
+ 'availablePredictionIntervals' => :@prediction_intervals,
10
+ 'startDate' => :@start_date,
11
+ 'endDate' => :@end_date,
12
+ 'predictionDomain' => :@prediction_domain,
13
+ 'extraParameters' => :@extra_parameters,
14
+ 'targetColumn' => :@target_column,
15
+ 'statusHistory' => :@status_history }
16
+ session_hash.each do |k, v|
17
+ if (k == 'links')
18
+ @links = v.map { |l| NexosisApi::Link.new(l) }
19
+ elsif (k == 'columns')
20
+ @column_metadata = v.reject { |_key, value| value.nil? }
21
+ .map do |col_key, col_val|
22
+ NexosisApi::Column.new(col_key, v[col_key])
23
+ end
24
+ elsif (k == 'requestedDate')
25
+ @requested_date = DateTime.parse(v)
26
+ elsif (k == 'messages')
27
+ @messages = v.map { |m| NexosisApi::Message.new(m) } unless v.empty?
28
+ else
29
+ instance_variable_set("@#{k}", v) unless v.nil?
30
+ end
31
+ instance_variable_set(val_map[k.to_s], v) unless val_map[k.to_s].nil?
32
+ end
33
+ end
34
+
35
+ # identifier for this sesssion
36
+ # @return [String]
37
+ # @since 1.4.0
38
+ attr_accessor :session_id
39
+
40
+ # What type of analysis was run during this session
41
+ # @return [String]
42
+ attr_accessor :type
43
+
44
+ # Is this session requested, started, or completed
45
+ # @return [String]
46
+ attr_accessor :status
47
+
48
+ # Date and status of each status this session has entered
49
+ # @return [Array of Hash]
50
+ # @note - each status object in array is form { date: 'date', status: 'status' }
51
+ attr_accessor :status_history
52
+
53
+ # reserved for future extensions
54
+ # @return [Hash]
55
+ # @note - included 'balance' parameter for classification models
56
+ attr_accessor :extra_parameters
57
+
58
+ # The column in the dataset for which this session ran predictions
59
+ # @return [String]
60
+ attr_accessor :target_column
61
+
62
+ # The start date of analysis in this session
63
+ # @return [DateTime]
64
+ # @since 1.4.0
65
+ attr_accessor :start_date
66
+
67
+ # The end date of analysis in this session
68
+ # @return [DateTime]
69
+ # @since 1.4.0
70
+ attr_accessor :end_date
71
+
72
+ # associated hypermedia
73
+ # @return [Array of NexosisApi::Link]
74
+ attr_accessor :links
75
+
76
+ # The column descriptors for the data in this session
77
+ # will reflect either the metadata sent in, defaults form dataset, or inferred values
78
+ # @return[Array of NexosisApi::Column]
79
+ attr_accessor :column_metadata
80
+
81
+ # The requested result interval. Default is DAY if none was requested during session creation.
82
+ # @return [NexosisApi::TimeInterval]
83
+ attr_accessor :result_interval
84
+
85
+ # The name of the datasource used to run this session
86
+ # @return [String] - the dataset or view name
87
+ # @since 1.2.0
88
+ attr_accessor :datasource_name
89
+
90
+ # The date this session was orginally submitted
91
+ # @since 1.3.0
92
+ attr_accessor :requested_date
93
+
94
+ # The id of the model created by this session if any
95
+ # @return [String] a uuid/buid format unique string for the model
96
+ # @since 1.3.0
97
+ # @note This is always empty in time-series sessions (forecast/impact)
98
+ # The model id returned here should be used in all future calls
99
+ # to model endpoints - primarily the /models/{model_id}/predict endpoint.
100
+ attr_accessor :model_id
101
+
102
+ # An array of the prediction intervals available for this session's results
103
+ # @return [Array]
104
+ # @note - by default the .5 interval will be returned in results. Consult
105
+ # this list for other intervals which can be requested.
106
+ # @since 1.4.0
107
+ attr_accessor :prediction_intervals
108
+
109
+ # The type of model if a model creation session
110
+ # @return [String]
111
+ # @since 1.4.1
112
+ attr_accessor :prediction_domain
113
+
114
+ # A list of warning or error messages optionally returned from session
115
+ # @return [Array of Message]
116
+ attr_accessor :messages
117
+ end
118
+ end
@@ -1,30 +1,30 @@
1
- module NexosisApi
2
- # Class to parse the algorithm contestants from a session
3
- # @since 2.0.0
4
- class SessionContest < Session
5
- def initialize(contest_hash)
6
- contest_hash.each do |k, v|
7
- if k.to_s == 'champion'
8
- instance_variable_set("@#{k}", NexosisApi::AlgorithmContestant.new(v))
9
- elsif k.to_s == 'contestants'
10
- instance_variable_set("@#{k}", v.map { |c| NexosisApi::AlgorithmContestant.new(c) })
11
- elsif k.to_s == 'championMetric'
12
- @champion_metric = v
13
- end
14
- end
15
- super(contest_hash.reject { |key, _v| key == 'champion' || key == 'contestants' })
16
- end
17
-
18
- # The champion algorithm used
19
- # @return [NexosisApi::AlgorithmContestant]
20
- attr_accessor :champion
21
-
22
- # All other algorithms which competed
23
- # @return [Array of NexosisApi::AlgorithmContestant]
24
- attr_accessor :contestants
25
-
26
- # Name of metric used to determine champion algorithm
27
- # @return [String] metric name
28
- attr_accessor :champion_metric
29
- end
30
- end
1
+ module NexosisApi
2
+ # Class to parse the algorithm contestants from a session
3
+ # @since 2.0.0
4
+ class SessionContest < Session
5
+ def initialize(contest_hash)
6
+ contest_hash.each do |k, v|
7
+ if k.to_s == 'champion'
8
+ instance_variable_set("@#{k}", NexosisApi::AlgorithmContestant.new(v))
9
+ elsif k.to_s == 'contestants'
10
+ instance_variable_set("@#{k}", v.map { |c| NexosisApi::AlgorithmContestant.new(c) })
11
+ elsif k.to_s == 'championMetric'
12
+ @champion_metric = v
13
+ end
14
+ end
15
+ super(contest_hash.reject { |key, _v| key == 'champion' || key == 'contestants' })
16
+ end
17
+
18
+ # The champion algorithm used
19
+ # @return [NexosisApi::AlgorithmContestant]
20
+ attr_accessor :champion
21
+
22
+ # All other algorithms which competed
23
+ # @return [Array of NexosisApi::AlgorithmContestant]
24
+ attr_accessor :contestants
25
+
26
+ # Name of metric used to determine champion algorithm
27
+ # @return [String] metric name
28
+ attr_accessor :champion_metric
29
+ end
30
+ end
@@ -1,33 +1,33 @@
1
- require 'nexosis_api/session'
2
-
3
- module NexosisApi
4
- # Class to parse the results from a new session
5
- class SessionResponse < Session
6
- def initialize(forecast_hash)
7
- val_map = {
8
- 'Nexosis-Account-DataSetCount-Allotted' => :@datasets_allotted,
9
- 'Nexosis-Account-DataSetCount-Current' => :@datasets_current,
10
- 'Nexosis-Account-PredictionCount-Allotted' => :@predictions_allotted,
11
- 'Nexosis-Account-PredictionCount-Current' => :@predictions_current,
12
- 'Nexosis-Account-SessionCount-Allotted' => :@sessions_allotted,
13
- 'Nexosis-Account-SessionCount-Current' => :@sessions_current
14
- }
15
- forecast_hash.each do |k, v|
16
- if (k == 'session')
17
- super(v) unless v.nil?
18
- else
19
- instance_variable_set(val_map[k], v) unless val_map[k].nil?
20
- end
21
- end
22
- end
23
-
24
- attr_reader :datasets_allotted
25
- attr_reader :datasets_allotted
26
- attr_reader :datasets_current
27
- attr_reader :predictions_allotted
28
- attr_reader :predictions_current
29
- attr_reader :sessions_allotted
30
- attr_reader :sessions_current
31
-
32
- end
33
- end
1
+ require 'nexosis_api/session'
2
+
3
+ module NexosisApi
4
+ # Class to parse the results from a new session
5
+ class SessionResponse < Session
6
+ def initialize(forecast_hash)
7
+ val_map = {
8
+ 'Nexosis-Account-DataSetCount-Allotted' => :@datasets_allotted,
9
+ 'Nexosis-Account-DataSetCount-Current' => :@datasets_current,
10
+ 'Nexosis-Account-PredictionCount-Allotted' => :@predictions_allotted,
11
+ 'Nexosis-Account-PredictionCount-Current' => :@predictions_current,
12
+ 'Nexosis-Account-SessionCount-Allotted' => :@sessions_allotted,
13
+ 'Nexosis-Account-SessionCount-Current' => :@sessions_current
14
+ }
15
+ forecast_hash.each do |k, v|
16
+ if (k == 'session')
17
+ super(v) unless v.nil?
18
+ else
19
+ instance_variable_set(val_map[k], v) unless val_map[k].nil?
20
+ end
21
+ end
22
+ end
23
+
24
+ attr_reader :datasets_allotted
25
+ attr_reader :datasets_allotted
26
+ attr_reader :datasets_current
27
+ attr_reader :predictions_allotted
28
+ attr_reader :predictions_current
29
+ attr_reader :sessions_allotted
30
+ attr_reader :sessions_current
31
+
32
+ end
33
+ end
@@ -1,27 +1,27 @@
1
- module NexosisApi
2
- # Class for parsing the results of a completed session
3
- class SessionResult < Session
4
- def initialize(session_hash)
5
- session_hash.each do |k, v|
6
- if k.to_s == 'metrics' && session_hash['type'] == 'impact'
7
- instance_variable_set("@#{k}", NexosisApi::ImpactMetric.new(v)) unless v.nil?
8
- elsif k.to_s == 'metrics'
9
- @metrics = v.map { |key, value| NexosisApi::Metric.new(key.to_s, value) } unless v.nil?
10
- elsif k.to_s == 'data'
11
- @data = v
12
- end
13
- end
14
- super(session_hash.reject { |k, _v| k.to_s == 'data' || k.to_s == 'metrics' })
15
- end
16
-
17
- # The impact analysis if this session type is impact
18
- # @return [NexosisApi::ImpactMetric]
19
- attr_accessor :metrics
20
-
21
- # The result data in a hash with the name of the target column
22
- # @return [Array of Hash]
23
- # @note When retrieving a model creation session this field
24
- # will contain the test data and results.
25
- attr_accessor :data
26
- end
27
- end
1
+ module NexosisApi
2
+ # Class for parsing the results of a completed session
3
+ class SessionResult < Session
4
+ def initialize(session_hash)
5
+ session_hash.each do |k, v|
6
+ if k.to_s == 'metrics' && session_hash['type'] == 'impact'
7
+ instance_variable_set("@#{k}", NexosisApi::ImpactMetric.new(v)) unless v.nil?
8
+ elsif k.to_s == 'metrics'
9
+ @metrics = v.map { |key, value| NexosisApi::Metric.new(key.to_s, value) } unless v.nil?
10
+ elsif k.to_s == 'data'
11
+ @data = v
12
+ end
13
+ end
14
+ super(session_hash.reject { |k, _v| k.to_s == 'data' || k.to_s == 'metrics' })
15
+ end
16
+
17
+ # The impact analysis if this session type is impact
18
+ # @return [NexosisApi::ImpactMetric]
19
+ attr_accessor :metrics
20
+
21
+ # The result data in a hash with the name of the target column
22
+ # @return [Array of Hash]
23
+ # @note When retrieving a model creation session this field
24
+ # will contain the test data and results.
25
+ attr_accessor :data
26
+ end
27
+ end
@@ -1,21 +1,21 @@
1
- module NexosisApi
2
- # Class to parse the session selection metrics from a particular session
3
- # @since 2.0.0
4
- class SessionSelectionMetrics < Session
5
- def initialize(metrics_hash)
6
- if !metrics_hash['metricSets'].nil?
7
- @dataset_properties = metrics_hash['metricSets'][0]['dataSetProperties'] unless metrics_hash['metricSets'][0]['dataSetProperties'].nil?
8
- @metrics = metrics_hash['metricSets'][0]['metrics'] unless metrics_hash['metricSets'][0]['metrics'].nil?
9
- end
10
- super(metrics_hash.reject { |k, _v| k == 'metricSets' })
11
- end
12
-
13
- # transformations performed on dataset prior to algorithm run
14
- # @return [Array] string list of transformations
15
- attr_reader :dataset_properties
16
-
17
- # dataset metrics describing some properties of it
18
- # @return [Hash] name value pairs of dataset metrics
19
- attr_reader :metrics
20
- end
1
+ module NexosisApi
2
+ # Class to parse the session selection metrics from a particular session
3
+ # @since 2.0.0
4
+ class SessionSelectionMetrics < Session
5
+ def initialize(metrics_hash)
6
+ if !metrics_hash['metricSets'].nil?
7
+ @dataset_properties = metrics_hash['metricSets'][0]['dataSetProperties'] unless metrics_hash['metricSets'][0]['dataSetProperties'].nil?
8
+ @metrics = metrics_hash['metricSets'][0]['metrics'] unless metrics_hash['metricSets'][0]['metrics'].nil?
9
+ end
10
+ super(metrics_hash.reject { |k, _v| k == 'metricSets' })
11
+ end
12
+
13
+ # transformations performed on dataset prior to algorithm run
14
+ # @return [Array] string list of transformations
15
+ attr_reader :dataset_properties
16
+
17
+ # dataset metrics describing some properties of it
18
+ # @return [Hash] name value pairs of dataset metrics
19
+ attr_reader :metrics
20
+ end
21
21
  end
@@ -1,15 +1,15 @@
1
- module NexosisApi
2
- # constants for the date/time interval (e.g. Day, Hour) at which predictions should be generated.
3
- module TimeInterval
4
- # results summarized by hour
5
- HOUR = :hour
6
- # results summarized by day. Default option.
7
- DAY = :day
8
- # results summarized by week
9
- WEEK = :week
10
- # results summarized by month
11
- MONTH = :month
12
- # results summarized by year
13
- YEAR = :year
14
- end
15
- end
1
+ module NexosisApi
2
+ # constants for the date/time interval (e.g. Day, Hour) at which predictions should be generated.
3
+ module TimeInterval
4
+ # results summarized by hour
5
+ HOUR = :hour
6
+ # results summarized by day. Default option.
7
+ DAY = :day
8
+ # results summarized by week
9
+ WEEK = :week
10
+ # results summarized by month
11
+ MONTH = :month
12
+ # results summarized by year
13
+ YEAR = :year
14
+ end
15
+ end
@@ -1,14 +1,14 @@
1
- module NexosisApi
2
- # Class to hold the parsed results of a view data retrieval
3
- # @since 1.2.0
4
- class ViewData < ViewDefinition
5
- def initialize(viewdata_hash)
6
- @data = viewdata_hash['data']
7
- super(viewdata_hash.reject { |k| k == 'data' })
8
- end
9
-
10
- # An array of hashes representing the processed data of the view
11
- # @return [Array of Hash] - one hash per row of data where key = column name
12
- attr_accessor :data
13
- end
14
- end
1
+ module NexosisApi
2
+ # Class to hold the parsed results of a view data retrieval
3
+ # @since 1.2.0
4
+ class ViewData < ViewDefinition
5
+ def initialize(viewdata_hash)
6
+ @data = viewdata_hash['data']
7
+ super(viewdata_hash.reject { |k| k == 'data' })
8
+ end
9
+
10
+ # An array of hashes representing the processed data of the view
11
+ # @return [Array of Hash] - one hash per row of data where key = column name
12
+ attr_accessor :data
13
+ end
14
+ end
@@ -1,64 +1,64 @@
1
- module NexosisApi
2
- # class to hold the parsed results of a view
3
- # @since 1.2.0
4
- class ViewDefinition
5
- def initialize(view_hash)
6
- view_hash.each do |k, v|
7
- if k == 'viewName'
8
- @view_name = v unless v.nil?
9
- elsif k == 'dataSetName'
10
- @dataset_name = v unless v.nil?
11
- elsif k == 'columns'
12
- next if v.nil?
13
- @column_metadata = v.reject { |value| value.nil? } .map { |col_name, col_hash| NexosisApi::Column.new(col_name, col_hash)}
14
- elsif k == 'joins'
15
- next if v.nil?
16
- @joins = v.reject(&:nil?).map { |join| NexosisApi::Join.new(join) }
17
- elsif k == 'isTimeSeries'
18
- @is_timeseries = v
19
- end
20
- end
21
- end
22
-
23
- # The name of the view uploaded and saved
24
- # @return [String]
25
- attr_accessor :view_name
26
-
27
- # The name of the dataset on the left of the join
28
- # @return [String]
29
- attr_accessor :dataset_name
30
-
31
- # Descriptive information about the columns
32
- # @return [Array of NexosisApi::Column]
33
- attr_accessor :column_metadata
34
-
35
- # The join configuration for this view
36
- # @return [Array of NexosisApi::Join]
37
- attr_accessor :joins
38
-
39
- # Is this view based on time series data?
40
- # @since 1.3.0
41
- attr_accessor :is_timeseries
42
-
43
- # Is this view based on time series data?
44
- # @since 1.3.0
45
- alias_method :timeseries?, :is_timeseries
46
-
47
- # Provides a custom hash which matches json of api request
48
- def to_json
49
- hash = {}
50
- hash['dataSetName'] = dataset_name
51
- if column_metadata.nil? == false
52
- hash['columns'] = {}
53
- column_metadata.each do |column|
54
- hash['columns'].merge!(column.to_hash)
55
- end
56
- end
57
- hash['joins'] = []
58
- joins.each do |join|
59
- hash['joins'] << join.to_hash
60
- end
61
- hash.to_json
62
- end
63
- end
64
- end
1
+ module NexosisApi
2
+ # class to hold the parsed results of a view
3
+ # @since 1.2.0
4
+ class ViewDefinition
5
+ def initialize(view_hash)
6
+ view_hash.each do |k, v|
7
+ if k == 'viewName'
8
+ @view_name = v unless v.nil?
9
+ elsif k == 'dataSetName'
10
+ @dataset_name = v unless v.nil?
11
+ elsif k == 'columns'
12
+ next if v.nil?
13
+ @column_metadata = v.reject { |value| value.nil? } .map { |col_name, col_hash| NexosisApi::Column.new(col_name, col_hash)}
14
+ elsif k == 'joins'
15
+ next if v.nil?
16
+ @joins = v.reject(&:nil?).map { |join| NexosisApi::Join.new(join) }
17
+ elsif k == 'isTimeSeries'
18
+ @is_timeseries = v
19
+ end
20
+ end
21
+ end
22
+
23
+ # The name of the view uploaded and saved
24
+ # @return [String]
25
+ attr_accessor :view_name
26
+
27
+ # The name of the dataset on the left of the join
28
+ # @return [String]
29
+ attr_accessor :dataset_name
30
+
31
+ # Descriptive information about the columns
32
+ # @return [Array of NexosisApi::Column]
33
+ attr_accessor :column_metadata
34
+
35
+ # The join configuration for this view
36
+ # @return [Array of NexosisApi::Join]
37
+ attr_accessor :joins
38
+
39
+ # Is this view based on time series data?
40
+ # @since 1.3.0
41
+ attr_accessor :is_timeseries
42
+
43
+ # Is this view based on time series data?
44
+ # @since 1.3.0
45
+ alias_method :timeseries?, :is_timeseries
46
+
47
+ # Provides a custom hash which matches json of api request
48
+ def to_json
49
+ hash = {}
50
+ hash['dataSetName'] = dataset_name
51
+ if column_metadata.nil? == false
52
+ hash['columns'] = {}
53
+ column_metadata.each do |column|
54
+ hash['columns'].merge!(column.to_hash)
55
+ end
56
+ end
57
+ hash['joins'] = []
58
+ joins.each do |join|
59
+ hash['joins'] << join.to_hash
60
+ end
61
+ hash.to_json
62
+ end
63
+ end
64
+ end