def _set_log_file_path(logging_specification_document): log_file_base_path = Screen().input( "Input the log file base path and press [Enter]: ") log_file_name = Screen().input("Input the log file name and [Enter]: ") logging_specification_document.set_log_file_base_path(log_file_base_path) logging_specification_document.set_log_file_name(log_file_name) Screen().input("Log file path updated. Press [Enter] to continue")
def _remove_test_property(logging_specification_document): test_property_name = Screen().input( "Input the name of the test property to remove and press [Enter]: ") try: logging_specification_document.remove_test_property(test_property_name) Screen().input("Test property removed. Press [Enter] to continue") except FlexLoggerError: Screen().input( 'Test property could not be removed, possibly because no test property is named "' + test_property_name + '". Press [Enter] to continue')
def update(name, col_search=None, val_search=None): try: cols = [] vals = [] val = 0 if col_search == None: col_search = columns[name][SelectionMenu.get_selection( [i for i in columns[name]], show_exit_option=False, title="Choose column to search", )] if val_search == None: val_search = Screen().input("Enter value to update: ") Screen().println( 'Enter columns, text values must be surrounded by "\'"') Screen().println("Empty lines will be ignored") for i in range(1, len(columns[name])): col = columns[name][i] val = Screen().input(f"{(col)}: ") if bool(val and not val.isspace()): cols.append(col) vals.append(val) ens = db.update(name, cols, vals, col_search, val_search) if isinstance(ens, Exception): Screen().input(f"Derror: {ens}") return else: Screen().input(f"Updated { ens } items") except Exception as e: Screen().input("\n".join( [f"CError: {e}", "Press any key to continue..."]))
def process_data(name, data, page, nested=None): if isinstance(data, Exception): Screen().input(f"DError: {data}") return subtitle = "".join(f"{i} " for i in columns[name]) arr = [f" Page {page - 1}", f" Page {page + 1}"] for en in data: arr.append(" ".join(map(str, en))) sel = SelectionMenu.get_selection(arr, subtitle) if sel in range(2, len(arr)): subtitle = "" for i in range(len(columns[name])): subtitle += f"{columns[name][i]}: {data[sel - 2][i]}; " menu = ConsoleMenu("Item actions", subtitle) if name == "Seller" and nested == None: menu.append_item( FunctionItem("Find products", find_products, [data[sel - 2][0], 1])) elif name == "Product" and nested == None: menu.append_item( FunctionItem("Find sellers", find_sellers, [data[sel - 2][0], 1])) menu.append_item( FunctionItem("Edit", update, [name, columns[name][0], data[sel - 2][0]])) menu.append_item( FunctionItem("Delete", delete, [name, columns[name][0], data[sel - 2][0]])) menu.show() elif sel < 2: return sel + 1
def _set_test_property(logging_specification_document): property_name = Screen().input( "Input the name of the test property to create or modify and press [Enter]: " ) property_value = Screen().input( "Input the value for the test property and press [Enter]: ") prompt_on_start_input = (Screen().input( "Input if the user should be prompted to set the value of this " "property on test start (y|n) and press [Enter]: ").lower().strip()) if prompt_on_start_input[0] == "y": prompt_on_start = True else: prompt_on_start = False logging_specification_document.set_test_property(property_name, property_value, prompt_on_start) Screen().input("Test property set. Press [Enter] to continue")
def _show_test_properties(logging_specification_document): test_properties = logging_specification_document.get_test_properties() table = PrettyTable(["Name", "Value", "Prompt on start"]) for test_property in test_properties: table.add_row([ test_property.name, test_property.value, test_property.prompt_on_start ]) print(table) Screen().input("Press [Enter] to continue")
def _monitor_test_time(test_session): print("Monitoring test time. Press [Enter] to stop monitoring. . .") thread_exit_event = threading.Event() monitor_test_thread = threading.Thread(target=_monitor_test_time_thread, args=(test_session, thread_exit_event)) monitor_test_thread.start() Screen().input() thread_exit_event.set() monitor_test_thread.join()
def delete(name, col_search=None, val_search=None): try: if col_search == None: col_search = columns[name][SelectionMenu.get_selection( [i for i in columns[name]], show_exit_option=False, title="Choose column to search", )] if val_search == None: val_search = Screen().input("Enter value to delete: ") ens = db.delete(name, col_search, val_search) if isinstance(ens, Exception): Screen().input(f"Derror: { ens }") return else: Screen().input(f"Deleted { ens } items") except Exception as e: Screen().input("\n".join( [f"CError: {e}", "Press any key to continue..."]))
def _set_channel_value(channel_specification_document): channel_name = Screen().input( "Input the name of the channel to set and press [Enter]: ") channel_value = Screen().input( "Input the value for the channel and press [Enter]: ") try: channel_specification_document.set_channel_value( channel_name, float(channel_value)) Screen().input("Channel value set. Press [Enter] to continue") except FlexLoggerError: Screen().input( 'Channel value could not be set, possibly because no channel is named "' + channel_name + '". Press [Enter] to continue') except ValueError: Screen().input( "A value of " + channel_value + " could not be set on " + channel_name + " because it could not be converted to a floating point value." + " Press [Enter] to continue")
def action_plot(X, Y): linear_values = minimum_squares(X, Y) plot(X, Y, ajust=True, line=linear_values["reta"], line_label='Ajuste linear', line_color='red') Screen().input('Press [Enter] to continue')
def generate(name=None): try: count = "" string = "" while not count.isdigit(): count = Screen().input("Enter count: ") if name is None: ret = db.generate(count) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return string = f"Generated {ret[0]} sel, {ret[1]} prod. {ret[2]} sel-prod rel, {ret[3]} cust, {ret[4]} orders" elif name is "Seller": ret = db.generate_seller(count) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return string = f"Generated {ret} sellers" elif name is "Product": ret = db.generate_product(count) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return string = f"Generated {ret} products" elif name is "SellerProduct": ret = db.generate_selpr(count) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return string = f"Generated {ret} seller-product relations" elif name is "Order": ret = db.generate_order(count) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return string = f"Generated {ret} orders" elif name is "Customer": ret = db.generate_customer(count) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return string = f"Generated {ret} customers" Screen().input(string) except Exception as e: Screen().input("\n".join( [f"CError: {e}", "Press any key to continue..."]))
def _show_test_property(logging_specification_document): test_property_name = Screen().input( "Input the name of the test property to show and press [Enter]: ") try: test_property = logging_specification_document.get_test_property( test_property_name) print("The test property name is: " + test_property.name) print("The test property value is: " + test_property.value) if test_property.prompt_on_start: print( "The user will be prompted to set the value of this property on test start." ) else: print( "The user will not be prompted to set the value of this property on test start." ) Screen().input("Press [Enter] to continue") except FlexLoggerError: Screen().input( 'Test property could not be retrieved, possibly because no test property is named "' + test_property_name + '". Press [Enter] to continue')
def find_like(name): try: page = 1 per_page = 15 col = columns[name][SelectionMenu.get_selection( [i for i in columns[name]], show_exit_option=False, title="Choose column to search", )] val = Screen().input("Enter search: ") while True: data = db.find_like(name, col, val, (page - 1) * per_page, per_page) proc = process_data(name, data, page) if proc == 1 and page > 1: page -= 1 elif proc == 2: page += 1 else: break except Exception as e: Screen().input("\n".join( [f"CError: {e}", "Press any key to continue..."]))
def find_sellers(prod_id, nested): try: page = 1 per_page = 15 while True: data = db.find_sellers(prod_id, (page - 1) * per_page, per_page) proc = process_data("Seller", data, page, nested) if proc == 1 and page > 1: page -= 1 elif proc == 2: page += 1 else: break except Exception as e: Screen().input("\n".join( [f"CError: {e}", "Press any key to continue..."]))
def show_table(self, db_name): db_paths = [] if db_name == 'all': db_paths = [ self.config['Database']['contacts'], self.config['Database']['routines'], self.config['Database']['employers'], self.config['Database']['zoom'], self.config['Database']['research'] ] else: db_paths = [self.config['Database'][db_name]] list_of_tables = self.create_db_tables(db_paths) for table in list_of_tables: console.print(table) Screen().input('Press [Enter] to continue')
def find_all(name): try: page = 1 per_page = 15 while True: data = db.find_all(name, (page - 1) * per_page, per_page) proc = process_data(name, data, page) if proc == 1 and page > 1: page -= 1 elif proc == 2: page += 1 else: break except Exception as e: Screen().input("\n".join( [f"CError: {e}", "Press any key to continue..."]))
def _show_log_file_path(logging_specification_document): log_file_base_path = logging_specification_document.get_log_file_base_path( ) print("The log file base path is: " + log_file_base_path) if "{" in log_file_base_path: resolved_log_file_base_path = ( logging_specification_document.get_resolved_log_file_base_path()) print("The resolved log file base path is: " + resolved_log_file_base_path) log_file_name = logging_specification_document.get_log_file_name() print("The log file name is: " + log_file_name) if "{" in log_file_name: resolved_log_file_name = logging_specification_document.get_resolved_log_file_name( ) print("The resolved log file file name is: " + resolved_log_file_name) Screen().input("Press [Enter] to continue")
def _show_channel_values(channel_specification_document): channel_names = channel_specification_document.get_channel_names() table = PrettyTable(["Channel name", "Value", "Timestamp"]) for channel_name in channel_names: try: channel_data_point = channel_specification_document.get_channel_value( channel_name) table.add_row([ channel_data_point.name, channel_data_point.value, # Convert the timestamp from UTC to local time channel_data_point.timestamp.astimezone(None), ]) except FlexLoggerError: # Getting a channel that is not available, configured or enabled will raise # an exception. Ignore those exceptions and continue to the next channel. pass print(table) Screen().input("Press [Enter] to continue")
def clear(name=None): try: string = "" answer = Screen().input("Are you sure?(yes/no): ") if answer != "yes": Screen().input(answer) return if name is None: ret = db.clear() if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return ret2 = db.reset_serial() if isinstance(ret2, Exception): Screen().input(f"Gerror: {ret2}") return string = f"Deleted all" elif name is "Seller": ret = db.clear(name) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return ret2 = db.reset_serial(0) if isinstance(ret2, Exception): Screen().input(f"Gerror: {ret2}") return string = f"Deleted {ret} sellers" elif name is "Product": ret = db.clear(name) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return ret2 = db.reset_serial(1) if isinstance(ret2, Exception): Screen().input(f"Gerror: {ret2}") return string = f"Deleted {ret} products" elif name is "SellerProduct": ret = db.clear(name) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return ret2 = db.reset_serial(2) if isinstance(ret2, Exception): Screen().input(f"Gerror: {ret2}") return string = f"Deleted {ret} sel-pr relations" elif name is "Order": ret = db.clear(name) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return ret2 = db.reset_serial(3) if isinstance(ret2, Exception): Screen().input(f"Gerror: {ret2}") return string = f"Deleted {ret} orders" elif name is "Customer": ret = db.clear(name) if isinstance(ret, Exception): Screen().input(f"Gerror: {ret}") return ret2 = db.reset_serial(4) if isinstance(ret2, Exception): Screen().input(f"Gerror: {ret2}") return string = f"Deleted {ret} customers" Screen().input(string) except Exception as e: Screen().input("\n".join( [f"CError: {e}", "Press any key to continue..."]))
def _resume_test(test_session): print("Resuming test. . . ") test_session.resume() Screen().input("Test resumed. Press [Enter] to continue")
def _pause_test(test_session): print("Pausing test. . . ") test_session.pause() Screen().input("Test paused. Press [Enter] to continue")
def _stop_test(test_session): print("Stopping test. . . ") test_session.stop() Screen().input("Test stopped. Press [Enter] to continue")
def _add_note(test_session): note = Screen().input( "Input the note to log and press [Enter] when the note is complete: ") print("Adding note. . . ") test_session.add_note(note) Screen().input("Note added. Press [Enter] to continue")
def _start_test(test_session): print("Starting test. . . ") test_session.start() Screen().input("Test started. Press [Enter] to continue")
def insert(name): try: cols = [] vals = [] val = 0 Screen().println( 'Enter columns, text values must be surrounded by "\'"') Screen().println("Empty lines will be ignored") for i in range(1, len(columns[name])): col = columns[name][i] val = Screen().input(f"{(col)}: ") if bool(val and not val.isspace()): cols.append(col) vals.append(val) en = db.insert(name, cols, vals) if isinstance(en, Exception): Screen().input(f"Derror: {en}") return if name == "Seller": prod_ids = Screen().input( "Enter products id's, separated by commas: ") ens_arr = [] for prod_id in prod_ids.split(","): ens_arr.append(f"""( { prod_id }, { str(en[0][0]) } )""") ens = db.insert("SellerProduct", ["product_id", "seller_id"], [ens_arr]) if isinstance(ens, Exception): Screen().input(f"Derror: {ens}") return else: Screen().println(f"Inserted { len(ens) } items") elif name == "Product": sell_ids = Screen().input( "Enter sellers id's, separated by commas: ") ens_arr = [] for sell_id in sell_ids.split(","): ens_arr.append(f"""( { sell_id }, { str(en[0][0]) } )""") ens = db.insert( "SellerProduct", ["seller_id", "product_id"], [ens_arr], ) if isinstance(ens, Exception): Screen().input(f"Derror: {ens}") return else: Screen().println(f"Inserted { ens } items") except Exception as e: Screen().input("\n".join( [f"CError: {e}", "Press any key to continue..."]))
from consolemenu import ConsoleMenu, Screen from consolemenu.items import FunctionItem from consolemenu.prompt_utils import PromptUtils import os import glob import datetime import astro import s3 from util import getToday, mkdir, run, log, clearDir from config import getConfig screen = Screen() DIR_S3 = "../data/s3" DIR_S3_NODES = "../data/s3/**" DIR_PROCESSED = "../data/processed" DIR_PROCESSED_NODES = "../data/processed/**" DIR_GIF_OUTPUT = "../data/gifs" GIF_DELAY = 3 framerate = "30" def deleteDarkImages(node, date): log('Deleting dark images') sunrise, sunset = astro.getTimes(date) files = glob.glob(f'../data/processed/{node}/temp/*') for file in files: fileName = os.path.basename(os.path.normpath(file)) dotSplit = fileName.split('.') underscoreSplit = dotSplit[0].split('_') time = underscoreSplit[1].replace('-', '')
def app(): np.set_printoptions(precision=2) #get path from SO project_path = os.path.dirname(os.path.realpath(__file__)) # # Import data from pandas data = pd.read_csv(project_path + '\\app\\data\\dados_07.csv') print("\n\n--------- Algelin II - UFRJ --------- ") print("------- Trabalho de analise de Iris -------- ") Screen().input('\n\nPress [Enter] to continue') print('\nQuestão 01:') print('- Método dos mínimos quadrados, Coeficiesntes. 01:') print('--- Iris-setosa: ---') print('--- Dados de Sepal') action_minimum_squares( extraction_colunms_value(data, 'Iris-setosa', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-setosa', 'SepalWidthCm')) Screen().input('\n\nPress [Enter] to plot example Sepal') action_plot(extraction_colunms_value(data, 'Iris-setosa', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-setosa', 'SepalWidthCm')) print('\n--- Dados de Petal') action_minimum_squares( extraction_colunms_value(data, 'Iris-setosa', 'PetalLengthCm'), extraction_colunms_value(data, 'Iris-setosa', 'PetalWidthCm')) print('\n') print('--- Iris-versicolor: ---') print('--- Dados de Sepal') action_minimum_squares( extraction_colunms_value(data, 'Iris-versicolor', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'SepalWidthCm')) Screen().input('\n\nPress [Enter] to plot example Petal') action_plot( extraction_colunms_value(data, 'Iris-versicolor', 'PetalLengthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'PetalWidthCm')) print('\n--- Dados de Petal') action_minimum_squares( extraction_colunms_value(data, 'Iris-versicolor', 'PetalLengthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'PetalWidthCm')) print('\n') print('--- Iris-virginica: ---') print('--- Dados de Sepal') action_minimum_squares( extraction_colunms_value(data, 'Iris-virginica', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'SepalWidthCm')) Screen().input('\n\nPress [Enter] to plot example Sepal') action_plot( extraction_colunms_value(data, 'Iris-virginica', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'SepalWidthCm')) print('\n--- Dados de Petal') action_minimum_squares( extraction_colunms_value(data, 'Iris-virginica', 'PetalLengthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'PetalWidthCm')) print('\n') print('\n--- Implementação de PLU ---') print('--- Iris-setosa ---\n') action_plu( constructor_matrix([ extraction_colunms_value(data, 'Iris-setosa', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-setosa', 'SepalWidthCm'), extraction_colunms_value(data, 'Iris-setosa', 'PetalLengthCm'), extraction_colunms_value(data, 'Iris-setosa', 'PetalWidthCm') ])) print('\n') Screen().input('\n\nPress [Enter] to continue') print('--- Iris-versicolor ---\n') action_plu( constructor_matrix([ extraction_colunms_value(data, 'Iris-versicolor', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'SepalWidthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'PetalLengthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'PetalWidthCm') ])) print('\n') Screen().input('\n\nPress [Enter] to continue') print('--- Iris-virginica ---\n') action_plu( constructor_matrix([ extraction_colunms_value(data, 'Iris-virginica', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-virginica', 'SepalWidthCm'), extraction_colunms_value(data, 'Iris-virginica', 'PetalLengthCm'), extraction_colunms_value(data, 'Iris-virginica', 'PetalWidthCm') ])) print('\n') Screen().input('\n\nPress [Enter] to continue') #bksub #q02 decespec #q03 print('\n- Decomposição em valores singulares (SVD) ') print('--- Iris-setosa ---\n') action_pvd( constructor_matrix([ extraction_colunms_value(data, 'Iris-setosa', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-setosa', 'SepalWidthCm'), extraction_colunms_value(data, 'Iris-setosa', 'PetalLengthCm'), extraction_colunms_value(data, 'Iris-setosa', 'PetalWidthCm') ])) print('\n') Screen().input('\n\nPress [Enter] to continue') print('--- Iris-versicolor ---\n') action_pvd( constructor_matrix([ extraction_colunms_value(data, 'Iris-versicolor', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'SepalWidthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'PetalLengthCm'), extraction_colunms_value(data, 'Iris-versicolor', 'PetalWidthCm') ])) print('\n') Screen().input('\n\nPress [Enter] to continue') print('--- Iris-virginica ---\n') action_pvd( constructor_matrix([ extraction_colunms_value(data, 'Iris-virginica', 'SepalLengthCm'), extraction_colunms_value(data, 'Iris-virginica', 'SepalWidthCm'), extraction_colunms_value(data, 'Iris-virginica', 'PetalLengthCm'), extraction_colunms_value(data, 'Iris-virginica', 'PetalWidthCm') ])) print('\n') Screen().input('\n\nPress [Enter] to continue') return
def setUp(self): self.mock_screen = Mock(spec=Screen()) self.mock_screen.input.return_value = 4 '''