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_end_search_solutions(request): """gRPC: Call from UI with a EndSearchSolutionsRequest""" print('view_end_search_solutions 1') user_info = get_authenticated_user(request) if not user_info.success: return JsonResponse(get_json_error(user_info.err_msg)) user = user_info.result_obj print('view_end_search_solutions 2') req_body_info = get_request_body(request) if not req_body_info.success: return JsonResponse(get_json_error(req_body_info.err_msg)) print('view_end_search_solutions 3') # -------------------------------- # Behavioral logging # -------------------------------- log_data = dict(session_key=get_session_key(request), feature_id=ta2_static.END_SEARCH_SOLUTIONS, activity_l1=bl_static.L1_SYSTEM_ACTIVITY, activity_l2=bl_static.L2_ACTIVITY_BLANK) LogEntryMaker.create_ta2ta3_entry(user, log_data) print('view_end_search_solutions 4') # Let's call the TA2 and end the session! # params = dict(user=user) search_info = end_search_solutions(req_body_info.result_obj, **params) if not search_info.success: return JsonResponse(get_json_error(search_info.err_msg)) # The session is over, write the log entries files # #LogEntryMaker.write_user_log_from_request(request) # User is done at this point! # Write out the log and delete it.... user_workspace = None ws_info = get_latest_user_workspace(request) if ws_info.success: user_workspace = ws_info.result_obj ResetUtil.write_and_clear_behavioral_logs(user, user_workspace) json_info = get_json_success('success!', data=search_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_test_csrf_required(request): """for testing csrf call""" req_body_info = get_request_body(request) if not req_body_info.success: return JsonResponse(get_json_error(req_body_info.err_msg)) # user info # user_msg = 'Sending back info from request body...' user_info = dict(is_authenticated=request.user.is_authenticated, username='******' % request.user) # full data returned # data_info = dict(user_info=user_info, orig_data_as_text=req_body_info.result_obj) return JsonResponse(get_json_success(\ user_msg, data=data_info))
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)