def processFile(flowfile:str, watsonSDKVersion:str): basefilename = os.path.basename(flowfile).split('.')[0] flow = pd.read_csv(flowfile, delimiter='\t' ) # This bit widens the output on screen. pd.set_option('display.max_columns', 10000) pd.set_option('display.width', 10000) #print('Flow to run:') #print(flow) #print() ft = flowtest_v1.FlowTestV1(username=USERNAME, password=PASSWORD, version=conversation_version) # print('Creating blank template: ') # blank_flow = ft.createBlankTemplate() # print(blank_flow) # print() # print('Creating blank report') # report = ft.createBlankReport(alternate_intents=True) # print(report) # print() print() print('Running Conversational Flow: {} ({})'.format(flowfile, flow.shape[0])) results = ft.runFlowTest(workspace_id=workspace_id, flow=flow, show_progress=True, version=watsonSDKVersion) print() #Full esults are hard to read, instead we let step by step progress report failures as they happen #print('Results:') #print(results) #print() filename = os.path.join(OUTPUT_FOLDER, '{}_report.tsv'.format(basefilename)) print('Writing full test results to: {}'.format(filename)) results.to_csv(filename, sep='\t', encoding='utf-8') print() #Can also run this way #print('Running Conversational Flow as JSON: {} ({})'.format(flowfile, flow.shape[0])) #results = ft.runFlowTest(workspace_id=workspace_id, flow=flow, show_progress=True,json_dump=True) #print() #print('Results:') #for r in results: # print(r) #print() # Json is a list. So you save differently. filename = os.path.join(OUTPUT_FOLDER, '{}_report.json'.format(basefilename)) with open(filename, 'w') as file_handler: for item in results: file_handler.write("{}\n".format(item))
def processFile(flowfile: str, watsonSDKVersion: str): basefilename = os.path.basename(flowfile).split('.')[0] if flowfile.endswith("json"): flow = json.load(open(flowfile)) flow = pd.DataFrame(flow) else: flow = pd.read_csv(flowfile, delimiter='\t') # This bit widens the output on screen. pd.set_option('display.max_columns', 10000) pd.set_option('display.width', 10000) #print('Flow to run:') #print(flow) #print() ft = flowtest_v1.FlowTestV1(password=PASSWORD, version=conversation_version, url=WA_URL) # print('Creating blank template: ') # blank_flow = ft.createBlankTemplate() # print(blank_flow) # print() # print('Creating blank report') # report = ft.createBlankReport(alternate_intents=True) # print(report) # print() print() print('Running Conversational Flow: {} ({})'.format(flowfile, len(flow))) results = ft.runFlowTest(workspace_id=workspace_id, flow=flow, show_progress=True, version=watsonSDKVersion) print() #Full esults are hard to read, instead we let step by step progress report failures as they happen #print('Results:') #print(results) #print() filename = os.path.join(OUTPUT_FOLDER, '{}_report.tsv'.format(basefilename)) print('Writing full test results to: {}'.format(filename)) results.to_csv(filename, sep='\t', encoding='utf-8') print() #Can also run this way #print('Running Conversational Flow as JSON: {} ({})'.format(flowfile, flow.shape[0])) #results = ft.runFlowTest(workspace_id=workspace_id, flow=flow, show_progress=True,json_dump=True) #print() #print('Results:') #for r in results: # print(r) #print() # Json is a list. So you save differently. filename = os.path.join(OUTPUT_FOLDER, '{}_report.json'.format(basefilename)) with open(filename, 'w', encoding='utf-8') as file_handler: compact = results.to_json(orient='records') readable = json.dumps(json.loads(compact), indent=2) file_handler.write(readable) #print('Report in by intent structure') #print(ft.convertReportToIntentPerRow(results,input_all_lines=False)) success = results[['Matched Output', 'Matched Intent', 'Matched Entity']].replace(to_replace=['', 'n/a'], value=True) return success.all().all()