def command_handler(message): status = ['/todo', '/doing', '/done'] command_bot = Command() if message.command == '/new': command_bot.command_new(message.chat, message.msg) elif message.command == '/rename': command_bot.command_rename(message.msg, message.user_name, message.chat) elif message.command == '/duplicate': command_bot.command_duplicate(message.msg, message.user_name, message.chat) elif message.command == '/delete': command_bot.command_delete(message.msg, message.user_name, message.chat) elif message.command in status: command_bot.command_status(message.msg, message.user_name, message.chat, message.command) elif message.command == '/list': command_bot.command_list(message.chat) elif message.command == '/dependson': command_bot.command_dependson(message.msg, message.user_name, message.chat) elif message.command == '/priority': command_bot.command_priotiry(message.msg, message.user_name, message.chat) elif message.command == '/start': helper = Help() send_message("Welcome! Here is a list of things you can do.", message.chat) send_message(helper.get_help(), message.chat) elif message.command == '/help': helper = Help() send_message("Here is a list of things you can do.", message.chat) send_message(helper.get_help(), message.chat) elif message.command == '/showPriority': command_bot.command_show_priority(message.chat) else: send_message( "I'm sorry " + message.user_name + ". I'm afraid I can't do that.", message.chat)
def build(self): self.icon = 'Image/icon.png' self.title = 'Mental_math' self.theme_cls.primary_palette = "Yellow" manager = ScreenManager() manager.add_widget(First(name='first')) manager.add_widget(Login(name='login')) manager.add_widget(Registration(name='registration')) manager.add_widget(MainScreen(name='mainscreen')) manager.add_widget(Introductory_lesson(name='introductory_lesson')) manager.add_widget(Lesson_one(name='lesson_one')) manager.add_widget(Lesson_two(name='lesson_two')) manager.add_widget(Lesson_three(name='lesson_three')) manager.add_widget(Lesson_four(name='lesson_four')) manager.add_widget(Lesson_five(name='lesson_five')) manager.add_widget(Lesson_six(name='lesson_six')) manager.add_widget(Lesson_seven(name='lesson_seven')) manager.add_widget(Lesson_eight(name='lesson_eight')) manager.add_widget(Lesson_nine(name='lesson_nine')) manager.add_widget(Soroban(name='soroban')) manager.add_widget(Flashcards(name='flashcards')) manager.add_widget(Stolb(name='stolb')) manager.add_widget(Help(name='help')) manager.add_widget(Audio_tren(name='audio_tren')) return manager
def process(self): self.manual = Help() if self.__help(): return Privileges.check_for_root_permissions() self.load_xml_description(self.command_args['--root']) package_requests = False if self.command_args['--add-package']: package_requests = True if self.command_args['--delete-package']: package_requests = True log.info('Updating system') self.system = System(self.xml_state, self.command_args['--root'], allow_existing=True) manager = self.system.setup_repositories() if not package_requests: self.system.update_system(manager) else: if self.command_args['--add-package']: self.system.install_packages( manager, self.command_args['--add-package']) if self.command_args['--delete-package']: self.system.delete_packages( manager, self.command_args['--delete-package'])
def create_standart_placement(self): helper = Help() code_words = list() for word in self.words: code_word = helper.mult_vector_for_matrix(word, self.G_matrix) code_words.append(code_word) ''' print("code_words:") for code_word in code_words: print(code_word) ''' self.standart_placement.append(code_words) depend_list = [0 for x in range(0, 2 ** self.n)] for code_word in code_words: dec = helper.convert_binary_to_decimal(code_word, self.n) depend_list[dec] = 1 for i in range(0, 2 ** self.r - 1): leader = helper.find_min_weight_in_depend_list(depend_list, self.n) #print("leader = ", leader) coset = list() for code_word in code_words: coset_word = helper.xor(leader, code_word) dec = helper.convert_binary_to_decimal(coset_word, self.n) depend_list[dec] = 1 #print("coset_word = ", coset_word) coset.append(coset_word) self.standart_placement.append(coset) #print("depend_list = ", depend_list) return
def check_for_depend(self): helper = Help() Comb = Combinatorics() for i in range(2, self.d): allCombinations = [] Comb.GenerationAllCombinations(allCombinations, self.n, i) for combination in allCombinations: new_vector = helper.sum_of_vectors(self.H_transpose, combination) #print("new_vector = ", new_vector) if (new_vector.count(1) == 0): print("False") print("count = ", new_vector.count(1)) print("combination = ", combination) for index in combination: print(self.H_transpose[index]) return print("True") Comb.GenerationAllCombinations(allCombinations, self.n, self.d) for combination in allCombinations: new_vector = helper.sum_of_vectors(self.H_transpose, combination) if (new_vector.count(1) == 0): print("depend for d") print("combination = ", combination) return return
def decode_recieve_mess(self): helper = Help() syndrom = helper.mult_matrix_for_vector(self.H_matrix, self.mess) leader = self.syndrom_and_leader.get(str(syndrom)) decode_mess = helper.xor(self.mess, leader) print("decode_mess = ", decode_mess[0:self.k]) print("prob = ", self.prob)
def process(self): self.manual = Help() if self.__help(): return Privileges.check_for_root_permissions() self.load_xml_description(self.command_args['--description']) if self.command_args['--set-repo']: (repo_source, repo_type, repo_alias, repo_prio) = \ self.quadruple_token(self.command_args['--set-repo']) self.xml_state.set_repository(repo_source, repo_type, repo_alias, repo_prio) if self.command_args['--add-repo']: for add_repo in self.command_args['--add-repo']: (repo_source, repo_type, repo_alias, repo_prio) = \ self.quadruple_token(add_repo) self.xml_state.add_repository(repo_source, repo_type, repo_alias, repo_prio) if os.path.exists('/.buildenv'): # This build runs inside of a buildservice worker. Therefore # the repo defintions is adapted accordingly self.xml_state.translate_obs_to_suse_repositories() elif self.command_args['--obs-repo-internal']: # This build should use the internal SUSE buildservice # Be aware that the buildhost has to provide access self.xml_state.translate_obs_to_ibs_repositories() log.info('Preparing system') system = System(self.xml_state, self.command_args['--root'], self.command_args['--allow-existing-root']) manager = system.setup_repositories() system.install_bootstrap(manager) system.install_system(manager) profile = Profile(self.xml_state) defaults = Defaults() defaults.to_profile(profile) setup = SystemSetup(self.xml_state, self.command_args['--description'], self.command_args['--root']) setup.import_shell_environment(profile) setup.import_description() setup.import_overlay_files() setup.call_config_script() setup.import_image_identifier() setup.setup_groups() setup.setup_users() setup.setup_keyboard_map() setup.setup_locale() setup.setup_timezone() system.pinch_system(manager)
def process(self): self.manual = Help() if self.__help(): return result_directory = os.path.normpath(self.command_args['--target-dir']) log.info('Listing results from %s', result_directory) result = Result.load(result_directory + '/kiwi.result') result.print_results()
def __init__(self, cmd=None): self.db = initdb() self.header_string = "Xapers" self.status_string = "s: search, q: kill buffer, Q: quit Xapers, ?: help and additional commands" self.view = urwid.Frame(urwid.SolidFill()) self.set_header() self.set_status() self.devnull = open('/dev/null', 'rw') if not cmd: cmd = ['search', '*'] if cmd[0] == 'search': query = ' '.join(cmd[1:]) self.buffer = Search(self, query) elif cmd[0] == 'bibview': query = ' '.join(cmd[1:]) self.buffer = Bibview(self, query) elif cmd[0] == 'help': target = None if len(cmd) > 1: target = cmd[1] if isinstance(target, str): target = None self.buffer = Help(self, target) else: self.buffer = Help(self) self.set_status("Unknown command '%s'." % (cmd[0])) self.merge_palette(self.buffer) self.view.body = urwid.AttrMap(self.buffer, 'body') self.mainloop = urwid.MainLoop( self.view, self.palette, unhandled_input=self.keypress, handle_mouse=False, ) self.mainloop.screen.set_terminal_properties(colors=88) self.mainloop.run()
def create_code(self): random.seed() helper = Help() code_word = helper.mult_vector_for_matrix(self.mess, self.G_matrix) if (self.e == None): for i in range(0, self.n): value = random.randint(0, 1) self.e.append(value) print("code_word = ", code_word) print("e = ", self.e) noise_word = helper.xor(code_word, self.e) print("noise_word = ", noise_word)
def write_dict_for_decode(self): helper = Help() print("dictionary_for_decoder:") for i in range(0, len(self.standart_placement)): syndrom_leader = self.syndrom_table[i] print("{", syndrom_leader, ": " , end = '') weight_list = list() for coset in self.standart_placement[i]: weight = helper.calculate_weight_for_vector(coset) if (weight <= self.t): weight_list.append(list(coset)) print(weight_list, "} ")
def create_depended_cols(self, size, depend_list): helper = Help() Comb = Combinatorics() for i in range(2, self.d): allCombinations = [] Comb.GenerationAllCombinations(allCombinations, size, i) for combination in allCombinations: new_vector = helper.sum_of_vectors(self.H_transpose, combination) dec = helper.convert_binary_to_decimal(new_vector, self.r) #print("dec = ", dec) depend_list[dec] = 1 return
def create_syndrom_table(self): helper = Help() for coset in self.standart_placement: leader = coset[0] syndrom = helper.mult_matrix_for_vector(self.H_matrix, leader) self.syndrom_table.append(syndrom) ''' print("syndrom_table:") for syndrom in self.syndrom_table: print(syndrom) ''' return
def identify_task(task_word): task = '' if 'song' == task_word: task = Find_song() if 'answer' == task_word: task = Find_answer() if 'spell' == task_word: task = Spell_word() if 'time' == task_word or 'date' == task_word: task = Say_date_time() if 'help' == task_word: task = Help() return task
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setupUi(self) self.initStyleSheet() self.tcp_server = TcpServer(self) self.tcp_clients = TcpClients(self) self.udp_server = UdpServer(self) self.help = Help(self) self.init_ui() self.init_connect() self.init_config()
def create_G_matrix(self): helper = Help() #G_0_transpose = list() G_0_transpose = [ list(self.H_matrix[i][0 : self.k]) for i in range(0, self.r) ] G_0 = helper.transpose_matrix(G_0_transpose) for i in range(0, self.k): curr_list = [0 for x in range(0, self.k)] curr_list[i] = 1 self.G_matrix.append(curr_list) for i in range(0, self.k): for j in range(0, len(G_0[i])): self.G_matrix[i].append(G_0[i][j]) #print("check_G_H_product = ", self.check_G_H_product()) return
def check_G_H_product(self): helper = Help() matrix = helper.mult_matrix_for_matrix(self.G_matrix, self.H_transpose) ''' print("G_H_product:") for row in matrix: print(row) ''' sum_ones = 0 for row in matrix: sum_ones = sum_ones + row.count(1) if (sum_ones == 0): return True else: return False
def build(self): self.progress=self.load_progress() self.grid_screen=LevelChooser() self.grid_screen.bind(on_level=self.level_choice) self.grid_screen.bind(on_wtf=self.wtf) self.grid_screen.color_progress(self.progress) self.level_screen=Level() self.wtf_screen=Help() self.level_screen.bind(on_pass=self.success) self.root=ScreenManager() self.root.add_widget(self.grid_screen) self.root.add_widget(self.level_screen) self.root.add_widget(self.wtf_screen) self.bind(on_start = self.post_build_init) return self.root
def __init__(self): super().__init__(command_prefix=self.get_prefix, case_insensitive=True, help_command=Help(), activity=discord.Activity( type=discord.ActivityType.watching, name='+help | New and Improved jeju!'), intents=intents) self.load_extension('jishaku') self.motor_client = AsyncIOMotorClient(os.getenv('MONGODB_URI'), io_loop=self.loop) self.db = self.motor_client.jeju_dev if self.is_env_dev( ) else self.motor_client.jeju self.start_time = datetime.now() self.loop.create_task(self.startup())
def calculate_dist(self): helper = Help() sum_combs = 1 i = 1 flag = True while flag: sum_combs = sum_combs + helper.calculate_comb(self.size - 1, i) if (sum_combs >= 2 ** self.r): flag = False else: i = i + 1 dist = i + 1 if (dist <= self.r - 1): return dist else: return self.r - 1
def __init__(self): self.client = zulip.Client(site="https://saharsh.zulipchat.com/api/") self.subscribe_all() self.trans = Translate() self.tw = Twimega() self.pnr = Pnr() self.weather = Weather() self.geo = Geocode() self.searching = Places() self.help = Help() print("Initialization Done ...") self.subkeys = [ "translate", "weather", "pnr", "post", "post_image", "twitter", "help", "search" ]
def __init__(self, chat_id, bot ): conn = sqlite3.connect(dataBaseDjangoDir) cursor = conn.cursor() cursor.execute("""select * from usuarios_usuario""") conn.commit() query = (cursor.fetchall()) for user in query: if user[4] == chat_id: self.name = user[1] self.email = user[4] self.authorize = True self.help = Help(chat_id) self.sensiTags = SensiTags(bot) self.graphic = Graphics() self.report = Reports() self.chat_id = chat_id
def check_for_liniar_code(self): helper = Help() i = 0 code_words = self.standart_placement[0] while i < len(code_words): j = i + 1 while j < len(code_words): sum_vector = helper.xor(code_words[i], code_words[j]) if (not(sum_vector in code_words)): print("code is not liniar") print("i = ", i) print("j = ", j) print(code_words[i]) print(code_words[j]) j = j + 1 i = i + 1 print("code is liniar") return
def calculate_probability(self): helper = Help() syn_leader_list = list() weight_and_count = dict() for i in range(0, self.t + 1): weight_and_count[i] = 0 i = 0 while i < len(self.standart_placement): leader = self.standart_placement[i][0] weight = helper.calculate_weight_for_vector(leader) if (weight <= self.t): weight_and_count[weight] = weight_and_count[weight] + 1 i = i + 1 prob_e_leader = 0 for weight in weight_and_count.keys(): prob = (self.p ** weight) * ((1 - self.p) ** (self.n - weight)) prob_e_leader = prob_e_leader + (weight_and_count[weight] * prob) prob_e_not_leader = 1 - prob_e_leader return prob_e_not_leader
def calculate_dist(self): helper = Help() sum_combs = 1 i = 1 flag = True #print("2**r = ", 2 ** self.r) while flag: #print("i = ", i, ": ", helper.calculate_comb(self.n - 1, i)) sum_combs = sum_combs + helper.calculate_comb(self.n - 1, i) #print("sum_combs = ", sum_combs) if (sum_combs >= 2 ** self.r): flag = False else: i = i + 1 dist = i + 1 if (dist <= self.r - 1): return dist else: return self.r - 1
def __init__(self, screen: pygame.Surface, data: dict, settings: dict, display: dict): """ une classe de jeu d'échecs Parameters ---------- screen : pygame.Surface la surface de jeu data : dict le dictionnaire des couleurs settings : dict les réglages de l'ia display : dict les réglages des graphiques """ self.pause = False # pour mettre le jeu en pause self.new_start = 0.0 # le temps pour redémarer les chronos après la pause self.running = True # le jeu tourne self.clock = Clock(-1, 0) # pour avoir la durée de la partie self.screen = screen self.data = data self.settings = settings self.display = display self.board = Board() self.playerB = Human(B, self) # joueur avec les pièces blanches self.playerN = Ai(N, self) # joueur avec les pièces noires self.cur_player = self.playerB self.score = self.board.get_score(self.board.board) self.all_scores = [self.score] self.all_moves = [] # str self.suggested = [(-11, -11), (-11, -11)] self.all_buttons = pygame.sprite.Group() self.all_buttons.add(Help(self)) self.all_buttons.add(Pause(self))
def menu(): try: while True: print('\n====================================') print('*** Bienvenido al juego CONNECT4 ***') print('====================================') while True: print('(1) INSTRUCCIONES') print('(2) PLAYER vs PLAYER') print('(3) PLAYER vs MACHINE') print('(4) MACHINE vs MACHINE') print('(5) HELP') print('(6) EXIT') try: option = int(input("Ingrese una opcion: ")) if option == 1: Inst() elif option == 2: PlayerVsPlayer() elif option == 3: PlayerVsMachine() elif option == 4: MachineVsMachine() elif option == 5: Help() elif option == 6: print('\nGracias por visitar Connect4 !!! ') print('Saliendo del juego ...') break else: print( '\nERROR: Opcion invalida! Solo hay opciones 1, 2, 3, 4, 5 y 6\n' ) except ValueError: print( '\nERROR: Opcion invalida! No ingreso un numero entero\n' ) break except: print()
def run(self): # Create a clock that will be used as a framerate monitor and limiter clock = pygame.time.Clock() app_running = True # While the user didn't exit the game, continue main loop (frames) while app_running: # Clear the screen by filling it with black color self.screen.fill(self.BACKGROUND_COLOR) # Handle events for event in pygame.event.get(): # Quit Event if event.type == pygame.QUIT: app_running = False # Mouse button down event elif event.type == pygame.MOUSEBUTTONDOWN: # If the play button was clicked, run the game if self.play_btn.rect.collidepoint(event.pos): if not MainWindow(self.screen).run(): return # If the help button was clicked, run the game elif self.help_btn.rect.collidepoint(event.pos): Help(self.screen).run() # Draw the credit in the menu self.draw_credit() # Update all the sprites self.sprites.update() # Update the display each frame pygame.display.update() # Limit to 60 fps clock.tick(self.MAX_FPS)
def init_ui(self): self.init_top_bar() self.init_side_bar() self._main_widget = QtWidgets.QStackedWidget(self) self._right_vlayout = QtWidgets.QVBoxLayout() self._right_vlayout.addLayout(self._top_bar_hlayout) self._right_vlayout.addWidget(self._main_widget) self._status_label = QtWidgets.QLabel(self) self._status_label.setIndent(10) self._status_label.setMinimumHeight(16) self._right_vlayout.addWidget(self._status_label) self._right_vlayout.setSpacing(0) self._right_vlayout.setContentsMargins(0, 0, 0, 0) self._main_Hlayout = QtWidgets.QHBoxLayout(self) self._main_Hlayout.addWidget(self._side_widget) self._main_Hlayout.addLayout(self._right_vlayout) self._main_Hlayout.setSpacing(0) self._main_Hlayout.setContentsMargins(0, 0, 0, 0) self.setLayout(self._main_Hlayout) self.tcp_server = TcpServer(self) self.tcp_clients = TcpClients(self) self.udp_server = UdpServer(self) self.udp_clients = UdpClients(self) self.help = Help(self) self._index_widget = { self.tcp_server: 0, self.tcp_clients: 1, self.udp_server: 2, self.udp_clients: 3, self.help: 4, } self._main_widget.addWidget(self.tcp_server) self._main_widget.addWidget(self.tcp_clients) self._main_widget.addWidget(self.udp_server) self._main_widget.addWidget(self.udp_clients) self._main_widget.addWidget(self.help)
def create_H_matrix(self): helper = Help() Comb = Combinatorics() depend_list = [0 for x in range(0, 2 ** self.r)] depend_list[0] = 1 for i in range(0, self.r): curr_list = [0 for x in range(0, self.r)] curr_list[i] = 1 dec = helper.convert_binary_to_decimal(curr_list, self.r) depend_list[dec] = 1 self.H_transpose.append(curr_list) size = self.r while size < self.n - 1: self.create_depended_cols(size, depend_list) zero_index = depend_list.index(0) new_vector = helper.convert_decimal_to_binary(zero_index, self.r) self.H_transpose.append(new_vector) depend_list[zero_index] = 1 size = size + 1 dep_combination = [j for j in range(0, self.d - 1)] new_vector = helper.sum_of_vectors(self.H_transpose, dep_combination) self.H_transpose.append(new_vector) helper.change_rows_order(self.H_transpose) self.H_matrix = helper.transpose_matrix(self.H_transpose)