def load_files(file_names): """Loads all files into the database. file_names : str All the file names to load into the database """ for file_name in file_names: print() print("Loading file {0}".format(file_name)) f.debug("Opening file handler for '{0}'".format(file_name)) with f.open_file(file_name) as file: try: read_and_load_file(file) print("File loaded.") except StopIteration: print("File is empty: {0}".format(file_name)) except Exception as err: f.error("Error while loading file into table: {0}".format( file.name)) exception, traceback = f.get_exception_details() f.error(exception) f.debug(traceback) cfg.data_loading_error = True print("Skipping file.") print()
def delete_entry(self): if len(self.lst_variables[0].get()) > 0: item_id = self.lst_variables[0].get() if fn.fetchRecordFromTable(item_id, self.page_name) is not None: fn.deleteDataFromTable(item_id, self.page_name) self.show_data() self.clear_entry() else: fn.error("Record isn't exist with Id - {}".format(item_id)) else: fn.error("Id field must be required!")
def validateUser(self): user = self.username.get() pswd = self.password.get() if user and pswd: if fn.isUserValidate(user, pswd): fn.createAuth(user) self.master.destroy() fn.startMain() else: fn.error("Please make sure that the details are correct!") else: fn.error("Please enter your login details!")
def get_clinical_research(medicament): if check_input(medicament) == False: return error() # Get an alphabet characters list. alphabet_list = parse(get_html(BASE_URL)) # Find a link for transition to the page with a particular letter. link_togo = get_first_letter_url(alphabet_list, medicament) if check_input(link_togo) == False: return error() # Get a list of medicaments. medicament_list = get_medicament_list(link_togo) # Get a list of medicaments that were find. medicament_link = find_medicament_matches(medicament_list, medicament) if check_input(medicament_link) == False: return error() # Create a bootstrap table to display data that was found. html = " <table class='table table-hover'><thead class='thead-dark'><tr><th scope='col'>Страница препарата в регистре лекарственных средств России</th><th scope='col'>Информация о клинических исследованиях</th></tr></thead>" search_result = "" warning = "" for i in medicament_link: link = "http:" + i['value'] medicament_page = get_html(link) clinical_trials = parse_clinical_trials(medicament_page) if clinical_trials == None: search_result = 'Не найдена' warning = "" else: search_result = 'Найдена' warning = "class='table-primary'" html = html + "<tr" + " " + warning + "><td align='left'><a href=" + "'" + link + "'" + " " + "target='_blank' class='text-dark'>" + i[ 'key'] + "<a></td>" + "<td align='center'>" + search_result + "</td></tr>" html = html + '</table>' mapping = {'page': html} body = render("index", mapping) return body
def estimate(word, pos_words=[], neg_words=[]): in_vector = np.zeros(vocab_size) in_vector[word_to_idx[word]] = 1 label = np.array([np.nan for _ in range(vocab_size)]) label[[word_to_idx[w] for w in pos_words]] = 1 label[[word_to_idx[w] for w in neg_words]] = 0 embedding, out_vector = feed_forward(in_vector) return embedding, error(out_vector, label)
def add_entry(self): dict_items = {} run_error = False for i in range(len(self.lst_entry)): if len(self.lst_variables[i].get()) > 0: if self.lst_entry[i] == 'password': self.lst_variables[i].set( bcrypt.hashpw(self.lst_variables[i].get().encode(), bcrypt.gensalt())) dict_items[self.lst_entry[i]] = self.lst_variables[i].get() else: run_error = True fn.error("All field are required!") break if not run_error: fn.addDataToTable(dict_items, self.page_name) self.show_data() self.clear_entry()
def train_one_step(word, pos_words, neg_words): in_vector = np.zeros(vocab_size) in_vector[word_to_idx[word]] = 1 label = np.array([np.nan for _ in range(vocab_size)]) label[[word_to_idx[w] for w in pos_words]] = 1 label[[word_to_idx[w] for w in neg_words]] = 0 hidden_vector, out_vector = feed_forward(in_vector) delta_hidden, delta_out = feed_back(out_vector, label) update_parameters(in_vector, hidden_vector, delta_hidden, delta_out) return error(out_vector, label)
def get_hostname(action_description): hostname = '' if variables.INSIDE_PROJECT_DIR: # Read the configuration of a project we're currently in. hostname = functions.get_hostname(yaml_data_loader.load_from_file(project_config_paths['main'])) if '' == hostname: functions.error( ( 'You are trying to %s the container but its hostname cannot ' 'be determined. Did you break the "site_url" variable in "%s"?' ) % ( action_description, project_config_paths['main'], ), 200 ) return hostname
def submit(): if folder_name.get(): if option == 'FOLDER': setting.FOLDER = folder_name.get() + '/' self.folder = folder_name.get() + '/' else: setting.AIM_FOLDER = folder_name.get() self.aim_folder = folder_name.get() print('{} : 已经成功获取文件夹路径'.format(__name__)) window.destroy() else: error_box = error(window=window, message="内容不能为空") error_box.place(x=100, y=50) time = 1 threading.Timer(time, lambda: remove_label(error_box)).start()
def save(): file = open('settings.cfg', 'w') cfg.add_section('Tasks') cfg.add_section('Other') cfg.set('Tasks', '1', entry_task1.get()) cfg.set('Tasks', '2', entry_task2.get()) cfg.set('Tasks', '3', entry_task3.get()) cfg.set('Tasks', '4', entry_task4.get()) cards = str(entry_howManyCards.get()) returns = str(entry_howManyReturns.get()) try: test1 = int(cards) cfg.set('Other', 'howManyCards', entry_howManyCards.get()) except: try: test2 = int(returns) cfg.set('Other', 'howManyReturns', entry_howManyReturns.get()) except: cfg.set('Other', 'howManyReturns', 'ERROR') cfg.write(file) file.close() settings.destroy() functions.error() cfg.set('Other', 'howManyCards', 'ERROR') cfg.write(file) file.close() settings.destroy() functions.error() try: test2 = int(returns) cfg.set('Other', 'howManyReturns', entry_howManyReturns.get()) except: cfg.write(file) file.close() settings.destroy() functions.error() cfg.write(file) file.close() settings.destroy() functions.restart() sys.exit()
except URLError as e: functions.soft_error("ERROR: We failed to reach a server.", settings["verbose"], 1, settings["ignore_error"]) functions.verbose(" - reason: {}".format(e.code), settings["verbose"], 1) else: functions.verbose("Opening file '{}'".format(input_file), settings["verbose"], 2) with open(input_file, mode='rb') as i_file: data[input_file] = functions.load_data_file(i_file) if not data[input_file]: del data[input_file] if len(data) == 0: functions.error("No input data were loaded.") functions.verbose("Validating input files data...", settings["verbose"], 2) suitable_data = [] "Checks data from input files - if the time is in correct format, order an if the values are numeric." for index_file, i_file in enumerate(data): lines = len(data[i_file]) prev = 0 suitable_data.append("") for index_line, line in enumerate(data[i_file]): if line == "": continue delim = line.rfind(" ") time = line[:delim].strip()
( action_description, project_config_paths['main'], ), 200 ) return hostname if args.check_updates: functions.check_updates(variables.dirs['lib']) sys.exit(0) if variables.INSIDE_VM_OR_CI and not variables.INSIDE_PROJECT_DIR: functions.error('The "%s" directory does not store CIKit project.' % variables.dirs['project'], errno.ENOTDIR) if '' == args.playbook: if not variables.INSIDE_VM_OR_CI: for group in ['env', 'host', 'matrix']: functions.playbooks_print(variables.dirs['self'], '%s/' % group) functions.playbooks_print(variables.dirs['scripts']) sys.exit(0) elif 'ssh' == args.playbook: options = ['-i'] runner = 'su root' if sys.stdout.isatty(): options.append('-t')
import opcodes import functions import sys import os.path # check for arguments if len(sys.argv) < 2: functions.error( "You need to specify an output file\nUsage: pyasm.py [output file]") elif len(sys.argv) > 2: functions.error( "You need to specify only an output file\nUsage: pyasm.py [output file]" ) else: pass output_file = open(sys.argv[1], "wb") print("Welcome to Pyasm!") print( "Press enter to exit, and remember, use 4 digits when moving to immediant register!" ) ## segment and offset segment = 0000 offset = 0000 ## dictionary to save labels labels = {}
Ui] = f.update(Uiold, Uinew, Ui, UT, theta, length, width, epsilon, T, mu, N, M, delta, k, acceptance_r, Cv, NT, kT, T2, T1) #%% thetadirec = np.linspace(-np.pi, np.pi, 360) Uidirec = -epsilon * (np.cos(2 * thetadirec) + mu * np.cos(thetadirec)) #%% Fitting specific heat x = np.zeros( (int(N / 2) - 1, NT) ) # x is confusing but it was meant as xi (and it is actually y data to make it even better :p) taucv = np.zeros(NT) sigmacv = np.zeros(NT) for i in range(NT): x[:, i] = f.error(Cv[int(N / 2):, i]) taucv[i], pp = curve_fit(f.function, np.linspace(1, N / 2 - 1, int(N / 2 - 1)), x[:, i]) sigmacv[i] = np.sqrt( 2 * taucv[i] / (N / 2) * (np.mean(Cv[int(N / 2):, i]**2) - np.mean(Cv[int(N / 2):, i])**2)) pf.specificheat(kT, Cv[-1, :], 3, sigmacv) x = np.zeros( (int(N / 2) - 1, NT) ) # x is confusing but it was meant as xi (and it is actually y data to make it even better :p) tauap = np.zeros(NT) sigmaap = np.zeros(NT) for i in range(NT):
import os import sys import json import functions ANSIBLE_EXECUTABLE = functions.which(functions.ANSIBLE_COMMAND) if '' == ANSIBLE_EXECUTABLE: functions.error( ( 'An executable for the "%s" command cannot be found. ' 'Looks like Python setup cannot provide Ansible operability.' ) % ( functions.ANSIBLE_COMMAND ) ) dirs = { 'lib': os.path.realpath(__file__ + '/..'), 'self': os.path.realpath(__file__ + '/../..'), 'project': os.environ.get('CIKIT_PROJECT_DIR'), } # It's an interesting trick for detecting Python interpreter. Sometimes it # may differ. Especially on MacOS, when Ansible installed via Homebrew. For # instance, "which python" returns the "/usr/local/Cellar/python/2.7.13/ # Frameworks/Python.framework/Versions/2.7/bin/python2.7", but this particular # setup may not have necessary packages for full Ansible operability. Since # Ansible - is a Python scripts, they must have a shadebag line with a path
def run(cmd): """Runs csv2db. This function is the main entry point for csv2db. Parameters ---------- cmd : str array The arguments passed Returns ------- int The exit code. """ args = parse_arguments(cmd) # Set verbose and debug output flags cfg.verbose = args.verbose if args.debug: cfg.verbose = True cfg.debug = True # Set table name cfg.table_name = args.table f.debug("Table name: {0}".format(cfg.table_name)) # Set column separator characters(s) cfg.column_separator = args.separator f.debug("Column separator: {0}".format(cfg.column_separator)) # Set quote character(s) cfg.quote_char = args.quote f.debug("Column escape character: {0}".format(cfg.quote_char)) # Find all files f.verbose("Finding file(s).") file_names = f.find_all_files(args.file) f.verbose("Found {0} file(s).".format(len(file_names))) # Exit program if no files found. if len(file_names) == 0: return f.ExitCodes.SUCCESS.value f.debug(file_names) # Generate CREATE TABLE SQL if args.command.startswith("gen"): f.verbose("Generating CREATE TABLE statement.") try: generate_table_sql(file_names, args.column_type) return f.ExitCodes.SUCCESS.value except Exception as err: f.error("Error generating statement: {0}".format(err)) return f.ExitCodes.GENERIC_ERROR.value # Load data else: # Set DB type f.debug("DB type: {0}".format(args.dbtype)) cfg.db_type = args.dbtype cfg.direct_path = args.directpath # Set DB default port, if needed if args.port is None: args.port = f.get_default_db_port(args.dbtype) f.debug("Using default port {0}".format(args.port)) # Set batch size f.debug("Batch size: {0}".format(args.batch)) cfg.batch_size = int(args.batch) # If batch size is lower than 10k and direct path has been specified, overwrite batch size to 10k. if cfg.direct_path and cfg.batch_size < 10000: f.debug( "Direct path was specified but batch size is less than 10000.") f.debug( "Overwriting the batch size to 10000 for direct-path load to make sense." ) cfg.batch_size = 10000 f.verbose("Establishing database connection.") f.debug("Database details:") f.debug({ "dbtype": args.dbtype, "user": args.user, "host": args.host, "port": args.port, "dbname": args.dbname }) if args.password is None: args.password = getpass.getpass() try: cfg.conn = f.get_db_connection(cfg.db_type, args.user, args.password, args.host, args.port, args.dbname) except Exception as err: f.error("Error connecting to the database: {0}".format(err)) return f.ExitCodes.DATABASE_ERROR.value try: load_files(file_names) f.verbose("Closing database connection.") cfg.conn.close() return f.ExitCodes.SUCCESS.value if not cfg.data_loading_error else f.ExitCodes.DATA_LOADING_ERROR.value except KeyboardInterrupt: print("Exiting program") cfg.conn.close() return f.ExitCodes.GENERIC_ERROR.value except Exception as err: f.error("Error loading file(s): {0}".format(err)) cfg.conn.close() return f.ExitCodes.GENERIC_ERROR.value
except HTTPError as e: functions.soft_error("ERROR: The server couldn\'t fulfill the request.", settings["verbose"], 1, settings["ignore_error"]) functions.verbose(" - error code: {}".format(e.code), settings["verbose"], 1) except URLError as e: functions.soft_error("ERROR: We failed to reach a server.", settings["verbose"], 1, settings["ignore_error"]) functions.verbose(" - reason: {}".format(e.code), settings["verbose"], 1) else: functions.verbose("Opening file '{}'".format(input_file), settings["verbose"], 2) with open(input_file, mode='rb') as i_file: data[input_file] = functions.load_data_file(i_file) if not data[input_file]: del data[input_file] if len(data) == 0: functions.error("No input data were loaded.") functions.verbose("Validating input files data...", settings["verbose"], 2) suitable_data = [] "Checks data from input files - if the time is in correct format, order an if the values are numeric." for index_file, i_file in enumerate(data): lines = len(data[i_file]) prev = 0 suitable_data.append("") for index_line, line in enumerate(data[i_file]): if line == "": continue delim = line.rfind(" ") time = line[:delim].strip()