def view_get_dataflow_results(request): """gRPC: Call from UI to GetDataflowResults""" success, raven_data_or_err = get_request_body(request) if not success: return JsonResponse(dict(status=False, message=raven_data_or_err)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='DescribeDataflow', request_msg=raven_data_or_err) # Let's call the TA2 and start the session! # json_str = get_data_flow_results(raven_data_or_err) # Convert JSON str to python dict - err catch here # - let it blow up for now--should always return JSON json_dict = json.loads(json_str, object_pairs_hook=OrderedDict) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) return JsonResponse(json_dict, safe=False)
def view_startsession(request): """gRPC: Call from UI to start session user_agent = can come from UI. Version id will originate on the server """ session_key = get_session_key(request) success, raven_data_or_err = get_request_body(request) if not success: return JsonResponse(dict(status=False, message=raven_data_or_err)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='start_session', request_msg=raven_data_or_err) # Let's call the TA2 and start the session! # json_str = start_session(raven_data_or_err) # Convert JSON str to python dict - err catch here # - let it blow up for now--should always return JSON json_dict = json.loads(json_str, object_pairs_hook=OrderedDict) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) return JsonResponse(json_dict, safe=False)
def view_get_execute_pipeline_results(request): """view for GetExecutePipelineResults""" session_key = get_session_key(request) success, raven_data_or_err = get_request_body(request) if not success: return JsonResponse(dict(status=False, message=raven_data_or_err)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='get_execute_pipeline_results', request_msg=raven_data_or_err) # Let's call the TA2! # json_str = get_execute_pipeline_results(raven_data_or_err) # Convert JSON str to python dict - err catch here # json_dict = json.loads(json_str, object_pairs_hook=OrderedDict) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) return JsonResponse(json_dict, safe=False)
def view_describe_solution(request): """gRPC: Call from UI with a DescribeSolutionRequest""" req_body_info = get_request_body(request) if not req_body_info.success: return JsonResponse(get_json_error(req_body_info.err_msg)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='DescribeSolution', request_msg=req_body_info.result_obj) # Let's call the TA2! # search_info = describe_solution(req_body_info.result_obj) #print('search_info', search_info) if not search_info.success: return JsonResponse(get_json_error(search_info.err_msg)) # Convert JSON str to python dict - err catch here # - let it blow up for now--should always return JSON json_dict = json.loads(search_info.result_obj, object_pairs_hook=OrderedDict) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) json_info = get_json_success('success!', data=json_dict) return JsonResponse(json_info, safe=False)
def view_set_problem_doc(request): """gRPC: Call from UI to SetProblemDoc""" session_key = get_session_key(request) success, raven_data_or_err = get_request_body(request) if not success: return JsonResponse(dict(status=False, message=raven_data_or_err)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='SetProblemDoc', request_msg=raven_data_or_err) # Let's call the TA2! # json_str = set_problem_doc(raven_data_or_err) # Convert JSON str to python dict - err catch here # json_dict = json.loads(json_str, object_pairs_hook=OrderedDict) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) return JsonResponse(json_dict, safe=False)
def view_hello(request): """gRPC: Call from UI as a hearbeat""" user_info = get_authenticated_user(request) if not user_info.success: return JsonResponse(get_json_error(user_info.err_msg)) # -------------------------------- # Behavioral logging # -------------------------------- log_data = dict(session_key=get_session_key(request), feature_id=ta2_static.HELLO, activity_l1=bl_static.L1_SYSTEM_ACTIVITY, activity_l2=bl_static.L2_APP_LAUNCH) LogEntryMaker.create_ta2ta3_entry(user_info.result_obj, log_data) # note: this is just a heartbeat, so no params are sent # # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='Hello', request_msg=('no params for this call')) # Let's call the TA2! # resp_info = ta2_hello() if not resp_info.success: return JsonResponse(get_json_error(resp_info.err_msg)) json_str = resp_info.result_obj # Convert JSON str to python dict - err catch here # - let it blow up for now--should always return JSON json_format_info = json_loads(json_str) if not json_format_info.success: return JsonResponse(get_json_error(json_format_info.err_msg)) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_format_info.result_obj) json_info = get_json_success('success!', data=json_format_info.result_obj) return JsonResponse(json_info, safe=False)
def view_list_primitives(request): """gRPC: Call from UI with a ListPrimitivesRequest""" user_info = get_authenticated_user(request) if not user_info.success: return JsonResponse(get_json_error(user_info.err_msg)) # -------------------------------- # (2) Begin to log D3M call # -------------------------------- call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='ListPrimitives', request_msg='no params for this call') # -------------------------------- # (2a) Behavioral logging # -------------------------------- log_data = dict(session_key=get_session_key(request), feature_id=ta2_static.LIST_PRIMITIVES, activity_l1=bl_static.L1_SYSTEM_ACTIVITY, activity_l2=bl_static.L2_ACTIVITY_BLANK) LogEntryMaker.create_ta2ta3_entry(user_info.result_obj, log_data) # Let's call the TA2! # search_info = list_primitives() #print('search_info', search_info) if not search_info.success: return JsonResponse(get_json_error(search_info.err_msg)) # Convert JSON str to python dict - err catch here # json_format_info = json_loads(search_info.result_obj) if not json_format_info.success: return JsonResponse(get_json_error(json_format_info.err_msg)) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_format_info.result_obj) json_info = get_json_success('success!', data=json_format_info.result_obj) return JsonResponse(json_info, safe=False)
def view_execute_pipeline(request): """ This is a more complex request that does 2 things: (1) Writes the data portion of the JSON from the UI to a file in "temp_storage_root" - e.g. create a directory and add the file with a unique name (2) Send a gRPC request message replacing "some uri" with reference to the file written in - e.g. `file://{temp_storage_root}/the_file_with_data.json` {"context": {"sessionId": "session_01"}, "pipelineId": "pipeline_1", "predictFeatures": [{"featureId": "cylinders", "dataUri": "<<DATA_URI>>"}, {"featureId": "displacement", "dataUri": "<<DATA_URI>>"}, {"featureId": "horsepower", "dataUri": "<<DATA_URI>>"}, {"featureId": "weight", "dataUri": "<<DATA_URI>>"}, {"featureId": "acceleration", "dataUri": "<<DATA_URI>>"}, {"featureId": "model", "dataUri": "<<DATA_URI>>"}, {"featureId": "class", "dataUri": "<<DATA_URI>>"}], "data": [[5.4496644295302, 5.4496644295302], [192.81711409396, 192.81711409396], [103.211604095563, 103.211604095563], [2978.70469798658, 2978.70469798658], [15.6577181208054, 15.6577181208054], [76.0771812080537, 76.0771812080537], [1.5738255033557, 1.5738255033557], [23.5268456375839, 23.5268456375839]]} """ session_key = get_session_key(request) success, raven_data_or_err = get_request_body(request) if not success: return JsonResponse(dict(status=False, message=raven_data_or_err)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='execute_pipeline', request_msg=raven_data_or_err) # Let's call the TA2 and start the session! # fmt_request, json_str_or_err = execute_pipeline(raven_data_or_err) if fmt_request is None: if call_entry: call_entry.save_d3m_response(json_str_or_err) return JsonResponse(dict(status=False, message=json_str_or_err)) # Convert JSON str to python dict - err catch here # json_dict = {} json_dict['grpcResp'] = json.loads(json_str_or_err) json_dict['data2'] = json.loads(fmt_request) # request with updated file uris # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) return JsonResponse(json_dict, safe=False)
def view_score_solutions(request): """gRPC: Call from UI with a GetScoreSolutionResultsRequest""" user_info = get_authenticated_user(request) if not user_info.success: return JsonResponse(get_json_error(user_info.err_msg)) req_body_info = get_request_body(request) if not req_body_info.success: return JsonResponse(get_json_error(req_body_info.err_msg)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='GetScoreSolutionResults', request_msg=req_body_info.result_obj) # Let's call the TA2! # # websocket id: trying username for now, may change this in the future # websocket_id = user_info.result_obj.username search_info = get_score_solutions_results(\ req_body_info.result_obj, user_info.result_obj, websocket_id=websocket_id) #print('search_info', search_info) if not search_info.success: return JsonResponse(get_json_error(search_info.err_msg)) # Convert JSON str to python dict - err catch here # - let it blow up for now--should always return JSON json_dict = search_info.result_obj #json.loads(search_info.result_obj, object_pairs_hook=OrderedDict) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) json_info = get_json_success('success!', data=json_dict) return JsonResponse(json_info, safe=False)
def view_stop_search_solutions(request): """gRPC: Call from UI with a StopSearchSolutions""" user_info = get_authenticated_user(request) if not user_info.success: return JsonResponse(get_json_error(user_info.err_msg)) req_body_info = get_request_body(request) if not req_body_info.success: return JsonResponse(get_json_error(req_body_info.err_msg)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type=ta2_static.STOP_SEARCH_SOLUTIONS, request_msg=req_body_info.result_obj) # -------------------------------- # Behavioral logging # -------------------------------- log_data = dict(session_key=get_session_key(request), feature_id=ta2_static.STOP_SEARCH_SOLUTIONS, activity_l1=bl_static.L1_SYSTEM_ACTIVITY, activity_l2=bl_static.L2_ACTIVITY_BLANK) LogEntryMaker.create_ta2ta3_entry(user_info.result_obj, log_data) # Let's call the TA2! # search_info = stop_search_solutions(req_body_info.result_obj) #print('search_info', search_info) if not search_info.success: return JsonResponse(get_json_error(search_info.err_msg)) # Convert JSON str to python dict - err catch here # - let it blow up for now--should always return JSON json_dict = json.loads(search_info.result_obj, object_pairs_hook=OrderedDict) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) json_info = get_json_success('success!', data=json_dict) return JsonResponse(json_info, safe=False)
def view_get_produce_solution_results(request): """gRPC: Call from UI with a GetProduceSolutionResultsRequest""" user_info = get_authenticated_user(request) if not user_info.success: return JsonResponse(get_json_error(user_info.err_msg)) req_body_info = get_request_body(request) if not req_body_info.success: return JsonResponse(get_json_error(req_body_info.err_msg)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='GetProduceSolutionResults', request_msg=req_body_info.result_obj) # Let's call the TA2! # # websocket id: trying username for now, may change this in the future # websocket_id = user_info.result_obj.username search_info = get_produce_solution_results(\ req_body_info.result_obj, user_info.result_obj, websocket_id=websocket_id) #print('search_info', search_info) if not search_info.success: return JsonResponse(get_json_error(search_info.err_msg)) json_dict = search_info.result_obj # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) json_info = get_json_success('success!', data=json_dict) return JsonResponse(json_info, safe=False)
def view_export_pipeline(request): """gRPC: Call from UI to export pipeline session_id = from UI; originally from startsession commmand example string: { "context":{ "session_id":"session_0" }, "pipelineId":"pipe1", "pipelineExecUri":"<<EXECUTABLE_URI>>" } """ session_key = get_session_key(request) success, raven_data_or_err = get_request_body(request) if not success: return JsonResponse(dict(status=False, message=raven_data_or_err)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='export_pipeline', request_msg=raven_data_or_err) # Let's call the TA2 and start the session! # json_str = export_pipeline(raven_data_or_err, call_entry) #print('json_str: [%s]' % json_str) # Convert JSON str to python dict - err catch here # json_dict = json.loads(json_str, object_pairs_hook=OrderedDict) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) return JsonResponse(json_dict, safe=False)
def view_delete_pipelines(request): """gRPC: Call from UI to delete pipelines session_id = from UI; originally from startsession commmand example string: '{ "context": { "session_id": "session_0" }, "delete_pipeline_ids" : ["pipeline_01", "pipeline_02"] };' """ session_key = get_session_key(request) success, raven_data_or_err = get_request_body(request) if not success: return JsonResponse(dict(status=False, message=raven_data_or_err)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='DeletePipelines', request_msg=raven_data_or_err) # Let's call the TA2 and start the session! # json_str = delete_pipelines(raven_data_or_err) # Convert JSON str to python dict - err catch here # json_dict = json.loads(json_str, object_pairs_hook=OrderedDict) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_dict) return JsonResponse(json_dict, safe=False)
def view_produce_solution(request): """gRPC: Call from UI with a ProduceSolutionRequest""" req_body_info = get_request_body(request) if not req_body_info.success: return JsonResponse(get_json_error(req_body_info.err_msg)) # Begin to log D3M call # call_entry = None if ServiceCallEntry.record_d3m_call(): call_entry = ServiceCallEntry.get_dm3_entry(\ request_obj=request, call_type='ProduceSolution', request_msg=req_body_info.result_obj) # Let's call the TA2! # search_info = produce_solution(req_body_info.result_obj) #print('search_info', search_info) if not search_info.success: return JsonResponse(get_json_error(search_info.err_msg)) # Convert JSON str to python dict - err catch here # json_format_info = json_loads(search_info.result_obj) if not json_format_info.success: return JsonResponse(get_json_error(json_format_info.err_msg)) # Save D3M log # if call_entry: call_entry.save_d3m_response(json_format_info.result_obj) json_info = get_json_success('success!', data=json_format_info.result_obj) return JsonResponse(json_info, safe=False)