Module: NexosisApi::Client::Sessions
- Included in:
- NexosisApi::Client
- Defined in:
- lib/nexosis_api/client/sessions.rb
Overview
Session-based API operations
Instance Method Summary collapse
-
#create_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil) ⇒ NexosisApi::SessionResponse
Initiate a new forecast session based on a named dataset.
-
#create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil) ⇒ NexosisApi::SessionResponse
Analyze impact for an event with data already saved to the API.
-
#estimate_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY) ⇒ NexosisApi::SessionResponse
Estimate the cost of a forecast from data already saved to the API.
-
#estimate_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY) ⇒ NexosisApi::SessionResponse
Estimate the cost of impact analysis for an event with data already saved to the API.
-
#get_session(session_id) ⇒ NexosisApi::Session
Get a specific session by id.
-
#get_session_results(session_id, as_csv = false) ⇒ NexosisApi::SessionResult
Get the results of the session.
-
#list_sessions(query_options = {}, page = 0, pageSize = 50) ⇒ Array of NexosisApi::SessionResponse
List sessions previously submitted.
-
#remove_session(session_id) ⇒ Object
Remove a session.
-
#remove_sessions(query_options = {}) ⇒ Object
Remove sessions that have been run.
Instance Method Details
#create_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil) ⇒ NexosisApi::SessionResponse
The time interval selected must be greater than or equal to the finest granularity of the data provided. For instance if your data includes many recoreds per hour, then you could request hour, day, or any other result interval. However, if your data includes only a few records per day or fewer, then a request for an hourly result interval will produce poor results.
Initiate a new forecast session based on a named dataset.
89 90 91 |
# File 'lib/nexosis_api/client/sessions.rb', line 89 def create_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, = nil) create_session(dataset_name, start_date, end_date, target_column, false, nil, "forecast", result_interval, ) end |
#create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, column_metadata = nil) ⇒ NexosisApi::SessionResponse
Analyze impact for an event with data already saved to the API.
115 116 117 |
# File 'lib/nexosis_api/client/sessions.rb', line 115 def create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY, = nil) create_session(dataset_name, start_date, end_date, target_column, false, event_name, "impact", result_interval, ) end |
#estimate_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY) ⇒ NexosisApi::SessionResponse
Estimate the cost of a forecast from data already saved to the API.
101 102 103 |
# File 'lib/nexosis_api/client/sessions.rb', line 101 def estimate_forecast_session(dataset_name, start_date, end_date, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY) create_session(dataset_name, start_date, end_date, target_column, true, nil, "forecast", result_interval) end |
#estimate_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY) ⇒ NexosisApi::SessionResponse
Estimate the cost of impact analysis for an event with data already saved to the API.
128 129 130 |
# File 'lib/nexosis_api/client/sessions.rb', line 128 def estimate_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil, result_interval = NexosisApi::TimeInterval::DAY) create_session(dataset_name, start_date, end_date, target_column, true, event_name, "impact", result_interval) end |
#get_session(session_id) ⇒ NexosisApi::Session
Get a specific session by id.
161 162 163 164 165 166 167 168 169 |
# File 'lib/nexosis_api/client/sessions.rb', line 161 def get_session(session_id) session_url = "/sessions/#{session_id}" response = self.class.get(session_url, @options) if(response.success?) NexosisApi::Session.new(response.parsed_response) else raise HttpException.new("There was a problem getting the session: #{response.code}.", "getting session #{session_id}" ,response) end end |
#get_session_results(session_id, as_csv = false) ⇒ NexosisApi::SessionResult
Get the results of the session.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/nexosis_api/client/sessions.rb', line 137 def get_session_results(session_id, as_csv = false) session_result_url = "/sessions/#{session_id}/results" if as_csv @headers["Accept"] = "text/csv" end response = self.class.get(session_result_url, @options) @headers.delete("Accept") if(response.success?) if(as_csv) response.body else NexosisApi::SessionResult.new(response.parsed_response) end else raise HttpException.new("There was a problem getting the session: #{response.code}.", "get results for session #{session_id}" ,response) end end |
#list_sessions(query_options = {}, page = 0, pageSize = 50) ⇒ Array of NexosisApi::SessionResponse
query parameters hash members are dataset_name, event_name, requested_before_date, and requested_after_date. After and before dates refer to the session requested date.
List sessions previously submitted
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nexosis_api/client/sessions.rb', line 21 def list_sessions( = {}, page = 0, pageSize = 50) sessions_url = '/sessions' query = { "dataSetName" => [:dataset_name], "eventName" => [:event_name], "requestedAfterDate" => [:requested_after_date], "requestedBeforeDate" => [:requested_before_date], "type" => [:type], "page" => page, "pageSize" => pageSize } response = self.class.get(sessions_url, :headers => @headers, :query => query) if(response.success?) all_responses = [] response.parsed_response["items"].each do |session_hash| response_hash = {"session" => session_hash}.merge(response.headers) all_responses << NexosisApi::SessionResponse.new(response_hash) end all_responses else raise HttpException.new("Could not retrieve sessions","Get all sessions with query #{.to_s}",response) end end |
#remove_session(session_id) ⇒ Object
Remove a session
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/nexosis_api/client/sessions.rb', line 47 def remove_session(session_id) if(session_id.to_s.empty?) raise ArgumentError 'session_id cannot be empty or nil' end session_url = '/session/#{session_id.to_s}' response = self.class.delete(session_url) if(response.success?) return else raise HttpException.new("Could not delete session with given id","remove session with id #{session_id.to_s}",response) end end |
#remove_sessions(query_options = {}) ⇒ Object
query parameters hash members are type, dataset_name, event_name, start_date, and end_date. Start and end dates refer to the session requested date. Results are not removed but then can only be accessed by dataset name
Remove sessions that have been run. All query options are optional and will be used to limit the sessions removed.
67 68 69 70 71 72 73 74 75 |
# File 'lib/nexosis_api/client/sessions.rb', line 67 def remove_sessions( = {}) sessions_url = '/sessions' response = self.class.delete(sessions_url, :headers => @headers, :query => ()) if(response.success?) return else raise HttpException.new("Could not remove sessions","Remove sessions with query #{.to_s}",response) end end |