def test_open_test_file(self): expected = [[100.0, 0], [90.0, 10], [80.0, 15], [70.0, 50], [60.0, 80], [50.0, 100], [40.0, 80], [30.0, 45], [20.0, 35], [10.0, 15], [0.0, 5]] actual = pixel_to_embryo_length.pixel_to_embryo_length(csv_functions.csv_open('test_1.csv')) self.assertEqual(expected, actual) expected = [[100.0, 0], [90.0, 20], [80.0, 30], [70.0, 100], [60.0, 160], [50.0, 200], [40.0, 160], [30.0, 90], [20.0, 70], [10.0, 30], [0.0, 10]] actual = pixel_to_embryo_length.pixel_to_embryo_length(csv_functions.csv_open('test_2.csv')) self.assertEqual(expected, actual)
def test_stdev(self): file1 = csv_functions.csv_open('test_1.csv') file2 = csv_functions.csv_open('test_2.csv') file_list = [pixel_to_embryo_length.pixel_to_embryo_length(file1), pixel_to_embryo_length.pixel_to_embryo_length(file2)] expected = 56.994056802640 actual = round(stats.st_dev(file_list)[2], 12) self.assertEqual(expected, actual)
def test_averager(self): file_list = [ pixel_to_embryo_length.pixel_to_embryo_length( csv_functions.csv_open('test_1.csv')), pixel_to_embryo_length.pixel_to_embryo_length( csv_functions.csv_open('test_2.csv')) ] actual = _averager.averager(file_list) expected = [[100.0, 150], [90.0, 135], [80.0, 127.5], [70.0, 75], [60.0, 30], [50.0, 0], [40.0, 30], [30.0, 82.5], [20.0, 97.5], [10.0, 127.5], [0.0, 142.5]] self.assertEqual(expected, actual)
def test_open_test_file(self): expected = [['X', 'Y'], ['0', '0'], ['1', '10'], ['2', '15'], ['3', '50'], ['4', '80'], ['5', '100'], ['6', '80'], ['7', '45'], ['8', '35'], ['9', '15'], ['10', '5']] actual = csv_functions.csv_open('test_1.csv') self.assertEqual(expected, actual) expected = [['X', 'Y'], ['0', '0'], ['1', '20'], ['2', '30'], ['3', '100'], ['4', '160'], ['5', '200'], ['6', '160'], ['7', '90'], ['8', '70'], ['9', '30'], ['10', '10']] actual = csv_functions.csv_open('test_2.csv') self.assertEqual(expected, actual)
def test_percentify(self): expected = [[100.0, 0.0], [90.0, 10.0], [80.0, 15.0], [70.0, 50.0], [60.0, 80.0], [50.0, 100.0], [40.0, 80.0], [30.0, 45.0], [20.0, 35.0], [10.0, 15.0], [0.0, 5.0]] actual = csv_functions.csv_open('test_1.csv') actual = pixel_to_embryo_length.pixel_to_embryo_length(actual) percentify.percentify(actual) self.assertEqual(expected, actual) expected = [[100.0, 0.0], [90.0, 10.0], [80.0, 15.0], [70.0, 50.0], [60.0, 80.0], [50.0, 100.0], [40.0, 80.0], [30.0, 45.0], [20.0, 35.0], [10.0, 15.0], [0.0, 5.0]] actual = csv_functions.csv_open('test_2.csv') actual = pixel_to_embryo_length.pixel_to_embryo_length(actual) percentify.percentify(actual) self.assertEqual(expected, actual)
def test_normalizer(self): norm_file = csv_functions.csv_open('test_norm.csv') expected = [[100.0, 0], [90.0, 5], [80.0, 7.5], [70.0, 25], [60.0, 40], [50.0, 50], [40.0, 40], [30.0, 22.5], [20.0, 17.5], [10.0, 7.5], [0.0, 2.5]] actual = csv_functions.csv_open('test_1.csv') actual = pixel_to_embryo_length.pixel_to_embryo_length(actual) normalizer.normalize(actual, norm_file) self.assertEqual(expected, actual) expected = [[100.0, 0], [90.0, 4], [80.0, 6], [70.0, 20], [60.0, 32], [50.0, 40], [40.0, 32], [30.0, 18], [20.0, 14], [10.0, 6], [0.0, 2]] actual = csv_functions.csv_open('test_2.csv') actual = pixel_to_embryo_length.pixel_to_embryo_length(actual) normalizer.normalize(actual, norm_file) self.assertEqual(expected, actual)
def main(): while True: # main loop file_list = list() file_path = '' # user input section while True: # file paths loop try: while True: # asking for file paths loop file_path = input( f'\nEnter path to File {len(file_list) + 1}' + '\n(Press Enter when done or \'restart\' to restart):') file_list.append(csv_functions.csv_open(file_path)) except FileNotFoundError: if file_path != '' and file_path.lower() != 'restart': print('\nFile not found, recheck name or path') finally: if file_path.lower() == 'restart': print('restarting... \n\n\n') os.execl(sys.executable, os.path.abspath(__file__), *sys.argv) if file_path == '': print('All Files Selected') break while True: # asking for normalization loop answer_norm = input( '\nWould you like to normalize your file? (y/n)') if answer_norm in ('y', 'n'): break else: print('\nPlease enter either \'y\' (yes) or \'n\' (no)') continue file_norm = '' if answer_norm == 'y': # opening normalizing file while True: # asking for normalizing file path loop file_norm = input('\nName or Path of File to Normalize to?') try: file_norm = csv_functions.csv_open( file_norm ) # file_norm is a list of every line in the file (also a list) (a list of lists) break except FileNotFoundError: print('\nFile not found, recheck name or path') continue while True: # asking for percentify loop answer_percentify = input( "\nWould you like to percentify your file? (y/n)") if answer_percentify in ('y', 'n'): break else: print('\nPlease enter either \'y\' (yes) or \'n\' (no)') continue # analysis section start_time = time.process_time() ret_list = list() for file in file_list: # normalization and percentification ret_file = pixel.pixel_to_embryo_length(file) if answer_norm == 'y': normalizer.normalize(ret_file, file_norm) if answer_percentify == 'y': percentify.percentify(ret_file) ret_list.append(ret_file) ret_list = averager.averager(ret_list) stop_time = time.process_time() print('\nFinished in', round((stop_time - start_time), 5), 'seconds!') if len(file_list) == 0: print('\nIf you didn\'t want to do anything, why did you run me?') sys.exit() # final section new_name = input('New .csv file name?') while True: new_path = input('\nPath to new .csv file?') try: if new_name[-1] == "/": csv_functions.make_new_csv(new_path + new_name, ret_list) else: csv_functions.make_new_csv(new_path + "/" + new_name, ret_list) print(f'File {new_name} created at {new_path}') break except: print('Error creating new .csv, try different path') while True: # asking to continue loop answer_continue = input('\nDo you have more to analyze (y/n): ') if answer_continue in ('y', 'n'): break else: print('\nPlease enter either y (yes) or n (no)') continue if answer_continue == 'n': print('\nGoodbye') sys.exit()