def import_csv_row(self, row): if self.year in empty_strings and row['Year'] not in empty_strings: self.year = float(row['Year']) if self.x in empty_strings and row['x'] not in empty_strings: self.x = float(row['x']) family = row['Family'] if self.family in empty_strings and family not in empty_strings: family = remove_last_character_if(string=family, char=';') self.family = family if self.parent in empty_strings and row['Parent'] not in empty_strings: self.set_parent(name=row['Parent']) if row['Ancestors'] not in empty_strings: if row['Ancestors'][-1] != ';': row['Ancestors'] += ';' ancestor_strings = utils.split_string(row['Ancestors']) for ancestor in ancestor_strings: if ancestor[-1] == ' ': ancestor = ancestor[:-1] if ancestor not in empty_strings: self.add_ancestor(ancestor) if row['Descendants'] not in empty_strings: if row['Descendants'][-1] != ';': row['Descendants'] += ';' descendant_strings = utils.split_string(row['Descendants']) for descendant in descendant_strings: if descendant[-1] == ' ': descendant = descendant[:-1] if descendant not in empty_strings: self.add_descendant(descendant)
def get_fkio(self): sio_string_list = split_string(integer2string(self.sio)) # self.fkio=sattoloCycle(sio_string_list,self._key) self.fkio = sattoloCycle(sio_string_list, self.generate_key()) # self.fkio = sattoloCycle(sio_string_list, self.cioL) self.fkio = "".join(self.fkio) self.fkio = string2integer(self.fkio) return self.fkio
def _process_platforms(self, platforms_string): platform_strings = utils.split_string(platforms_string) platforms = [] if 'windows' in platform_strings: platforms.append(utils.Platform.Windows) if 'linux' in platform_strings: platforms.append(utils.Platform.Linux) if 'osx' in platform_strings: platforms.append(utils.Platform.OSX) return platforms
def _form_bjam_module_list(self, module): if not module: return "" if not module.get_attribute('build_components'): return "" components_string = module.get_attribute('build_components').value component_strings = utils.split_string(components_string) command_line = '' for component in component_strings: command_line = command_line + " --with-" + component return command_line
def CalulateSecondHalvesWithHomomorphicFeature(self): XoredFirstHalves_string_list = split_string( integer2string(self.XoredFirstHalves)) # XoredSecondHalvesWithHomomorphicFeature=sattoloCycle(XoredFirstHalves_string_list,self._key) XoredSecondHalvesWithHomomorphicFeature = sattoloCycle( XoredFirstHalves_string_list, self.key) XoredSecondHalvesWithHomomorphicFeature = "".join( XoredSecondHalvesWithHomomorphicFeature) self.XoredSecondHalvesWithHomomorphicFeature = string2integer( XoredSecondHalvesWithHomomorphicFeature) return self.XoredSecondHalvesWithHomomorphicFeature
# m.connect() input_path = "input.txt" if len(sys.argv) > 1: input_path = sys.argv[1] with open(input_path, 'r') as file: data = file.read() sender = Sender(m, transm_global_params.TRANSMISSION_PROTOCOL_TYPE, True) sender.wait_for_connection() start_time = datetime.datetime.now() sender.send(list(split_string(data, frames_count))) finish_time = datetime.datetime.now() # with open('sender_results.txt', 'a') as file: # file.write( # str(transm_global_params.TRANSMISSION_PROTOCOL_TYPE) # + " " # + str(transm_global_params.ERROR_PROBABILITY) # + " " # + str(get_delta_ms(start_time, finish_time)) # + " ms" # + " total_sent: " # + str(sender.total_sent_) # + " total_received_ack: " # + str(sender.total_received_ack_)
def solving(self, string): loc_s = list(string) for i in enumerate(loc_s): loc_s[i[0]] = i[1].replace(' ', '') if '\n' in loc_s: return '\n' from MapScene import walls for i in enumerate(list(self.namespace.vars.keys())): print(i, 'i') try: it = re.finditer( '[^A-z](' + i[1] + ')[^A-z]|^' + i[1] + '|$' + i[1], string) except: continue for j in it: if not isinstance(self.namespace.vars[i[1]], FUNCTION): string = split_string( string, j.start(), str(self.namespace.vars[j.group().replace( ' ', '').replace('(', '').replace(')', '')].val), j.end()) if isinstance(self.namespace.vars[i[1]], STRING) or isinstance( self.namespace.vars[i[1]], CHAR): return string #TODO func with string else: example = self.namespace.vars[j.group().replace(' ', '')] try: args = re.findall(r'\(.+\)', string)[0].replace( ' ', '').replace('(', '').replace(')', '').replace(',', ' ').split() except: #TODO exception call function without () args = [] for i in enumerate(example.args.keys()): try: example.args[i[1]].append(args[i[0]]) except: pass #TODO exception low amount of arg's example.reinit() ret = self.parse(str(example), example.namespace, is_function=True, args=example.args) if not example.is_func: if isinstance(ret, dict): for k in ret.keys(): self.namespace.vars[k] = ret[k] return 0 else: end = re.search(r'\)', string).end() string = split_string(string, j.start(), str(ret), end) try: pass except: print(string) for i in enumerate(list(CHARCH)): try: it = re.finditer('[^A-z](' + i[1] + ')[^A-z]', string) for j in it: string = split_string(string, j.start(), j.group(), j.end()) except: pass s = string.split() f = False Hor_dir = False for i in enumerate(s): if i[1] == 'сверху': f = True Hor_dir = True s[i[0]] = str([self.hero.pos[0], self.hero.pos[1]]) elif i[1] == 'справа': f = True s[i[0]] = str([self.hero.pos[0] + 30, self.hero.pos[1]]) elif i[1] == 'слева': f = True s[i[0]] = str([self.hero.pos[0], self.hero.pos[1]]) elif i[1] == 'снизу': f = True Hor_dir = True s[i[0]] = str([self.hero.pos[0], self.hero.pos[1] + 30]) elif f == True: f = False if i[1] == 'не': s[i[0]] = str(' not in ') else: s.insert(i[0], ' in ') for i in enumerate(s): if i[1] == 'стена': if Hor_dir: s[i[0]] = str(walls['horizontal']) else: s[i[0]] = str(walls['vertical']) string = ' '.join(s) st = '' try: if string[0] == ' ': st += ' ' except: pass for i in string.split(): if i in list(self.namespace.vars.keys()): st += str(self.namespace.vars[i]) elif i in list(to_replace.keys()): st += to_replace.get(i) else: st += i st += ' ' try: return str(eval(st)) except: #TODO exception unrecognised expression str(st)
def render(self): """Renders a game or games depending on the configuration. Infinitely loops up to 15 minutes before a refresh of the list of games is required. """ self.canvas.Fill(*ledcolors.scoreboard.fill) current_game_index = self.__get_game_from_args() game = self.games[current_game_index] starttime = time.time() while True: try: if self.data_needs_refresh: overview = mlbgame.overview(game.game_id) self.data_needs_refresh = False # If a game_id can't be found, we fail gracefully and try the next game except ValueError as e: if str(e) == "Could not find a game with that id.": error_strings = ["Game ID","Not","Found"] + [game.game_id] self.__handle_error(e, error_strings) current_game_index = bump_counter(current_game_index, self.games) game = self.games[current_game_index] else: error_strings = split_string(str(e), self.canvas.width/4) self.__handle_error(e, error_strings) continue # Catch everything else. except: err_type, error, traceback = sys.exc_info() error_strings = split_string(str(error), self.canvas.width/4) self.__handle_error(error, error_strings) continue self.__refresh_game(game, overview) if self.config.scroll_until_finished == False: self.scroll_finished = True refresh_rate = SCROLL_TEXT_FAST_RATE if self.config.slowdown_scrolling == True: refresh_rate = SCROLL_TEXT_SLOW_RATE if overview.status == IN_PROGRESS: refresh_rate = self.config.live_rotate_rate self.data_needs_refresh = True self.scroll_finished = True time.sleep(refresh_rate) endtime = time.time() if endtime - self.creation_time >= FIFTEEN_MINUTES: return time_delta = endtime - starttime self.canvas.Fill(*ledcolors.scoreboard.fill) rotate_rate = self.config.live_rotate_rate # Always use the default 15 seconds for our pregame rotations if overview.status == PRE_GAME or overview.status == SCHEDULED: rotate_rate = self.config.pregame_rotate_rate if overview.status == FINAL or overview.status == GAME_OVER: rotate_rate = self.config.final_rotate_rate if time_delta >= rotate_rate and self.scroll_finished: starttime = time.time() self.data_needs_refresh = True self.scroll_finished = False self.current_scrolling_text_pos = self.canvas.width if self.__should_rotate_to_next_game(overview): current_game_index = bump_counter(current_game_index, self.games) game = self.games[current_game_index]