def list_file(path, query='', max_items=0, subtitle=tasks_msg): """ Creates object that represents XML items list of tasks in file given by `path` that contains `query` as substring. Max length of list is given by `max_items`, 0 means all tasks. """ alist = AlfredList() if len(sys.argv) > 1: query = sys.argv[1].lower() items_added = 0 with open(path, 'r') as f: for idx, line in enumerate(f): if is_not_done_task(line) and re.search(query, line.lower()): should_add = False if not only_tagged_today: should_add = True else: if today_tag in line: should_add = True line = line.replace(today_tag, '') # when user displays only tasks with @today tag displaying it is reduntant if should_add: items_added += 1 alist.append(create_arg(path, idx), format_line(line), subtitle) if max_items and max_items <= items_added: break return alist
def wait_results(results, f, log=False, datasets=None): clean_results = [] for dataset_name, portfolios in results.items(): # wait on everything for clf_name in portfolios.keys(): for i in range(0, len(portfolios[clf_name])): model_params, trading_params, res = portfolios[clf_name][i] res = compss_wait_on(res) pfs, total_time = res portfolios[clf_name][i] = (model_params, trading_params, res) if log: f.write(format_line(dataset_name, clf_name, datasets[dataset_name.split(':')[0]][1], trading_params, model_params, pfs, total_time) + '\n') params = (dataset_name, clf_name, model_params, trading_params, total_time) clean_results.append((params, pfs)) return clean_results
def read_data(file_name): x_file = open(file_name, "r") x_line = x_file.read().splitlines() global sentences_index for line in x_line: line_ = format_line(line) sub_words = all_sub_words(line_) sentences[sentences_index] = sentence_path(line, file_name) for word in sub_words: # prevent duplication of sentences if line not in [ sentences[sentence_.id].sentence for sentence_ in data_dict[word] ]: if len(data_dict[word]) < 5: data_dict[word].append( subString(sentences_index, 0, line_.index(word))) else: is_best_score(word, data_dict[word]) sentences_index += 1
def read_data(file_name): x_file = open(file_name, "r") x_line = x_file.read().splitlines() global sentences_id line_number = 1 for line in x_line: line_ = format_line(line) sub_words = all_sub_words(line_) sentences[sentences_id] = sentence_path(line, file_name) for word in sub_words: # prevent duplication of sentences if line not in [ sentences[sentence_.id].sentence for sentence_ in data_dict[word] ]: if len(data_dict[word]) < RESULT_LEN: data_dict[word].append( subString(sentences_id, 0, line_number)) sentences_id += 1 line_number += 1
integrator = FirstOrderHold(m, K) problem = SCProblem(m, K) last_nonlinear_cost = None converged = False for it in range(iterations): t0_it = time() print('-' * 50) print('-' * 18 + f' Iteration {str(it + 1).zfill(2)} ' + '-' * 18) print('-' * 50) t0_tm = time() A_bar, B_bar, C_bar, S_bar, z_bar = integrator.calculate_discretization( X, U, sigma) print(format_line('Time for transition matrices', time() - t0_tm, 's')) problem.set_parameters(A_bar=A_bar, B_bar=B_bar, C_bar=C_bar, S_bar=S_bar, z_bar=z_bar, X_last=X, U_last=U, sigma_last=sigma, weight_nu=w_nu, weight_sigma=w_sigma, tr_radius=tr_radius) while True: error = problem.solve(verbose=verbose_solver,
The next feature will save the data in an file(Probably of the json type) """ from offline import init from utils import format_line from online import get_best_k_completions if __name__ == '__main__': STOP_INPUT = '#' print("Loading the file and preparing the system....") init() string_to_complete = input("The system is ready. Enter your text:") while string_to_complete: if string_to_complete[-1] != STOP_INPUT: string_to_complete = format_line(string_to_complete) suggestions = get_best_k_completions(string_to_complete) if suggestions: print(f"There are {len(suggestions)} suggestions") for i in range(len(suggestions)): print( f'{i + 1}. {suggestions[i].get_complete_sentence()} , path = {suggestions[i].get_source_text()}' ) else: print("There are'nt suggestions") print(string_to_complete, end='') string_to_complete += input()
integrator = Integrator(m, K) problem = SCProblem(m, K) last_linear_cost = None converged = False for it in range(iterations): t0_it = time() print('-' * 50) print('-' * 18 + f' Iteration {str(it + 1).zfill(2)} ' + '-' * 18) print('-' * 50) t0_tm = time() A_bar, B_bar, C_bar, S_bar, z_bar = integrator.calculate_discretization( X, U, sigma) print(format_line('Time for transition matrices', time() - t0_tm, 's')) problem.set_parameters(A_bar=A_bar, B_bar=B_bar, C_bar=C_bar, S_bar=S_bar, z_bar=z_bar, X_last=X, U_last=U, sigma_last=sigma, weight_sigma=w_sigma, weight_nu=w_nu, weight_delta=w_delta, weight_delta_sigma=w_delta_sigma) while True: