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) ⇒ NexosisApi::SessionResponse
Forecast from data already saved to the API.
-
#create_forecast_session_csv(csv, start_date, end_date, target_column) ⇒ NexosisApi::SessionResponse
Forecast from CSV formatted data.
-
#create_forecast_session_data(json_data, start_date, end_date, target_column = nil) ⇒ NexosisApi::SessionResponse
Forecast from data posted in the request.
-
#create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil) ⇒ NexosisApi::SessionResponse
Analyze impact for an event with data already saved to the API.
-
#create_impact_session_data(json_data, start_date, end_date, event_name, target_column = nil) ⇒ NexosisApi::SessionResponse
Analyze impact for an event with data in json format.
-
#estimate_forecast_session(dataset_name, start_date, end_date, target_column = nil) ⇒ 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) ⇒ 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 = {}) ⇒ Object
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
permalink #create_forecast_session(dataset_name, start_date, end_date, target_column = nil) ⇒ NexosisApi::SessionResponse
Forecast from data already saved to the API.
78 79 80 |
# File 'lib/nexosis_api/client/sessions.rb', line 78 def create_forecast_session(dataset_name, start_date, end_date, target_column = nil) create_session(dataset_name, start_date, end_date, target_column) end |
permalink #create_forecast_session_csv(csv, start_date, end_date, target_column) ⇒ NexosisApi::SessionResponse
Forecast from CSV formatted data.
92 93 94 95 |
# File 'lib/nexosis_api/client/sessions.rb', line 92 def create_forecast_session_csv(csv, start_date, end_date, target_column) content = process_csv_to_s csv create_session(nil, start_date, end_date, target_column, false, nil, "forecast", content) end |
permalink #create_forecast_session_data(json_data, start_date, end_date, target_column = nil) ⇒ NexosisApi::SessionResponse
Forecast from data posted in the request.
105 106 107 108 |
# File 'lib/nexosis_api/client/sessions.rb', line 105 def create_forecast_session_data(json_data, start_date, end_date, target_column = nil) json_data = json_data.to_json unless json_data.is_a? String create_session nil, start_date, end_date, target_column, false, nil, "forecast", json_data, "application/json" end |
permalink #create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil) ⇒ NexosisApi::SessionResponse
Analyze impact for an event with data already saved to the API.
129 130 131 |
# File 'lib/nexosis_api/client/sessions.rb', line 129 def create_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil) create_session dataset_name, start_date, end_date, target_column, false, event_name, "impact" end |
permalink #create_impact_session_data(json_data, start_date, end_date, event_name, target_column = nil) ⇒ NexosisApi::SessionResponse
Analyze impact for an event with data in json format.
142 143 144 145 |
# File 'lib/nexosis_api/client/sessions.rb', line 142 def create_impact_session_data(json_data, start_date, end_date, event_name, target_column = nil) json_data = json_data.to_json unless json_data.is_a? String create_session nil, start_date, end_date, target_column, false, event_name, "impact", json_data, "application/json" end |
permalink #estimate_forecast_session(dataset_name, start_date, end_date, target_column = nil) ⇒ NexosisApi::SessionResponse
Estimate the cost of a forecast from data already saved to the API.
117 118 119 |
# File 'lib/nexosis_api/client/sessions.rb', line 117 def estimate_forecast_session(dataset_name, start_date, end_date, target_column = nil) create_session dataset_name, start_date, end_date, target_column, true end |
permalink #estimate_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil) ⇒ NexosisApi::SessionResponse
Estimate the cost of impact analysis for an event with data already saved to the API.
155 156 157 |
# File 'lib/nexosis_api/client/sessions.rb', line 155 def estimate_impact_session(dataset_name, start_date, end_date, event_name, target_column = nil) create_session dataset_name, start_date, end_date, target_column, true, event_name, "impact" end |
permalink #get_session(session_id) ⇒ NexosisApi::Session
Get a specific session by id.
188 189 190 191 192 193 194 195 196 |
# File 'lib/nexosis_api/client/sessions.rb', line 188 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 |
permalink #get_session_results(session_id, as_csv = false) ⇒ NexosisApi::SessionResult
Get the results of the session.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/nexosis_api/client/sessions.rb', line 164 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 |
permalink #list_sessions(query_options = {}) ⇒ Object
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
@return[Array of NexosisApi::SessionResponse] with all sessions matching the query or all if no query
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nexosis_api/client/sessions.rb', line 19 def list_sessions( = {}) sessions_url = '/sessions' query = { "dataSetName" => [:dataset_name], "eventName" => [:event_name], "requestedAfterDate" => [:requested_after_date], "requestedBeforeDate" => [:requested_before_date], "type" => [:type] } 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 |
permalink #remove_session(session_id) ⇒ Object
Remove a session
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nexosis_api/client/sessions.rb', line 43 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 |
permalink #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.
61 62 63 64 65 66 67 68 69 |
# File 'lib/nexosis_api/client/sessions.rb', line 61 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 |