def picking_rescan_tray(): tray_id, file_data, num_racks = session['tray_data_list'][ session['current_tray_num']] edge_length = 25 if num_racks == 6 else 30 viewer = trayStatusViewer(edge_length, num_racks, TUBES_ALONG_X, TUBES_ALONG_Y) viewer.new_tray(file_data) scan_data_queue = scan(num_racks) #list of rack ids - index is rack location in tray rack_ids = [] for rack_index in range(num_racks): rack_ids.append(tray_data[tray_data['RackPositionInTray'] == rack_index].iloc[0]['RackID']) #You need to make the tray image (save it to the normal spot, static/traydisplay.jpg) #and set running_errors somewhere in here running_errors = viewer.make_post_run_scan_results(scan_data_queue, \ tray_data_pick, \ session['prev_scan_data'], \ num_racks, \ tray_id, rack_ids, os.path.join(WORKING_DIRECTORY, 'static/traydisplay.jpg'), \ os.path.join(UPLOAD_FOLDER, 'output.csv')) return render_template('picking/tray_ran.html', runningErrors=running_errors)
def picking_scan_tray(): tray_id, file_data, num_racks = session['tray_data_list'][ session['current_tray_num']] edge_length = 25 if num_racks == 6 else 30 viewer = trayStatusViewer(edge_length, num_racks, TUBES_ALONG_X, TUBES_ALONG_Y) viewer.new_tray(file_data) #The tray is scanned and the info is returned into data_queue scan_data_queue = scan(num_racks) #You need to make the tray image (save it to the normal spot, static/traydisplay.jpg) #and set desired_tubes_incorrect and total_tubes_correct #this might be run multiple times so it needs to be able to handle that img_save_path = os.path.join(WORKING_DIRECTORY, 'static/traydisplay.jpg') scan_data_by_rack, desired_tubes_incorrect, total_tubes_incorrect = viewer.make_pre_run_scan_results(scan_data_queue, \ file_data, \ num_racks, \ img_save_path) #save returned scan data dict to memory so we can tell what changed after running tray session['prev_scan_data'] = scan_data_by_rack #desired_tubes_incorrect = 0 #total_tubes_incorrect = 0 return render_template('picking/tray_scanned.html', desiredTubesIncorrect=desired_tubes_incorrect, totalTubesIncorrect=total_tubes_incorrect)
def run_tray(): tray_data_list = session.get('tray_data_list', None) if tray_data_list: #run the current tray tray_id, tray_data, num_racks = tray_data_list[ session['current_tray_num']] edge_length = 25 if num_racks == 6 else 30 viewer = trayStatusViewer(edge_length, num_racks, TUBES_ALONG_X, TUBES_ALONG_Y) viewer.new_tray(tray_data) motor.returnHome() tray_data_pick = tray_data[tray_data['Pick'] == 1] racks = unique(tray_data_pick['RackPositionInTray']) racks.sort() for rack_index in racks: rackData = tray_data_pick[tray_data_pick['RackPositionInTray'] == rack_index] columns = unique(rackData['TubeColumn']) columns.sort() for col in columns: #move to rack,column motor.moveToTube(int(rack_index), int(col)) colData = rackData[rackData['TubeColumn'] == col] for row in colData['TubeRow']: print(tray_id, rack_index, col, row) #activate soleniod solenoidArray.actuateSolenoid(int(row)) viewer.pick_tube(rack_index, col, row) motor.returnHome() motor.release() scan_data_queue = scan(num_racks) #list of rack ids - index is rack location in tray rack_ids = [] for rack_index in range(num_racks): rack_ids.append(tray_data[tray_data['RackPositionInTray'] == rack_index].iloc[0]['RackID']) #You need to make the tray image (save it to the normal spot, static/traydisplay.jpg) #and set running_errors somewhere in here running_errors = viewer.make_post_run_scan_results(scan_data_queue, \ tray_data_pick, \ session['prev_scan_data'], \ num_racks, \ tray_id, rack_ids, os.path.join(WORKING_DIRECTORY, 'static/traydisplay.jpg'), \ os.path.join(UPLOAD_FOLDER, 'output.csv')) return render_template('picking/tray_ran.html', runningErrors=running_errors)
def next_tray(): #increment to next tray session['current_tray_num'] += 1 print("Next Tray") #if we're out of tray_data, tell user tray is done if session['current_tray_num'] >= len(session['tray_data_list']): return render_template('picking/order_complete.html') tray_data_list = session['tray_data_list'] tray_id, tray_data, num_racks = tray_data_list[session['current_tray_num']] edge_length = 25 if num_racks == 6 else 30 viewer = trayStatusViewer(edge_length, num_racks, TUBES_ALONG_X, TUBES_ALONG_Y) viewer.new_tray(tray_data) #save image of tray in 'static/' to to be shown in run_tray viewer.save_image(os.path.join(WORKING_DIRECTORY, 'static/traydisplay.jpg')) return render_template('picking/scan_tray.html', nextTrayId=tray_id)
def scan_tray(): trayId, rackId0, rackId1, rackId2, rackId3, rackId4, rackId5 = session[ 'scanning_ids'] num_racks = 6 if rackId5 != -1 else 5 edge_length = 25 if num_racks == 6 else 30 rack_ids = [ id for id in [rackId0, rackId1, rackId2, rackId3, rackId4, rackId5] if id != -1 ] scan_data_queue = scan(num_racks) viewer = trayStatusViewer(edge_length, num_racks, TUBES_ALONG_X, TUBES_ALONG_Y) viewer.new_tray() #makes image and writes to output csv file viewer.make_just_scan_results(scan_data_queue, \ trayId, \ rack_ids, \ os.path.join(WORKING_DIRECTORY, 'static/traydisplay.jpg'),\ os.path.join(UPLOAD_FOLDER, 'output.csv'))\ return render_template('scanning/scanning_tray_scanned.html')
def get_csv_file(): os.system('rm ' + os.path.join(WORKING_DIRECTORY, 'static/traydisplay.jpg')) os.system('rm ' + os.path.join(WORKING_DIRECTORY, 'static/images/*.jpg')) if 'file' not in request.files: flash('No file part') return redirect(request.url) file = request.files['file'] if file.filename == '': flash('No selected file') return redirect(request.url) if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(UPLOAD_FOLDER, 'user_upload.csv')) #Bens stuff inputFile = os.path.join(UPLOAD_FOLDER, 'user_upload.csv') inputDataframe = pd.read_csv(inputFile, dtype={'SampleBarcode': str}) #remove rows where WellID is NaN inputDataframe.dropna(subset=['WellID'], axis='rows', inplace=True) #subtract 1 from each RackPositionInTray inputDataframe['RackPositionInTray'] = inputDataframe['RackPositionInTray'] \ .apply(lambda x: int(x) - 1) #split tubePositionsList into columns (first letter) and rows (second two numbers) tubePositionsList = [[convertRow(row[0]), int(row[1:]) - 1] for row in inputDataframe['WellID']] tubePositionsDf = pd.DataFrame(tubePositionsList, columns=['TubeColumn', 'TubeRow']) #remove old position column from original dataframe and append new columns inputDataframe = inputDataframe.drop(columns=['WellID']) inputDataframe = pd.concat([inputDataframe, tubePositionsDf], axis=1) tray_ids = list(unique(inputDataframe['TrayID'])) #data frames holding the rows associatedprint(num_racks) with each tray tray_dataframes = [ inputDataframe[inputDataframe['TrayID'] == tray_id] for tray_id in tray_ids ] #holds number of racks in each tray (5 or 6) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #CHANGE ME BACK TO 6 #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> num_racks_list = [(6 if 5 in set(tray_df['RackPositionInTray']) else 5) for tray_df in tray_dataframes] tray_data_zip = list(zip(tray_ids, tray_dataframes, num_racks_list)) session['tray_data_list'] = tray_data_zip for i, (tray_id, tray_dataframe, num_racks) in enumerate(tray_data_zip): #Maintains image showing the tubes in the tray which are present, #have already been picked, and still have to be picked edge_length = 25 if num_racks == 6 else 30 viewer = trayStatusViewer(edge_length, num_racks, TUBES_ALONG_X, TUBES_ALONG_Y) viewer.new_tray( tray_dataframe[tray_dataframe['TrayID'] == tray_id]) #save image of tray in 'static/images/' to to be shown in file_uploaded.html viewer.save_image( os.path.join(WORKING_DIRECTORY, f'static/images/traydisplay{i}.jpg')) if i == 0: #only show first image in pick_tubes viewer.save_image( os.path.join(WORKING_DIRECTORY, 'static/traydisplay.jpg')) # num_racks = self.globalNumRacks #current_tray_num is the index of tray_data_list with the current tray's data session['current_tray_num'] = 0 if 'tray_data_list' in session \ and len(session['tray_data_list']) > 0 \ and len(session['tray_data_list'][0]) > 0: next_tray_id = session['tray_data_list'][0][0] else: print('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') next_tray_id = None return render_template('picking/scan_tray.html', nextTrayId=next_tray_id)