def get_groups1(course, html, profs_row_num): soup = BS(html, 'html.parser') rows = soup.find_all('tr') for row_num, num_of_tirguls in profs_row_num: group = Group() group.lectures = load_lectures(course, is_lecture=True, row=rows[row_num]) for row in rows[row_num:row_num + num_of_tirguls]: group.tirguls.append(load_tirgul(course, is_lecture=False, row=row)) yield group
def generate_node(parent, config, group_name, registers, nodes, address=0x0000, index=None): """Generate a dictionary of output data to be passed to jinja2.""" if group_name not in config: print "ERROR group", group_name, "not defined." sys.exit(1) dictionary = config[group_name] number = dictionary['number'] if 'number' in dictionary else 1 if number == 1: node = Group(parent, dictionary, group_name, index) else: node = Sequence(parent, dictionary, group_name, number, index) # print node.__dict__ # link up if parent is not None: parent.nodes.append(node) node.nodes = [] nodes[node.full_name] = node # print "N",node.full_name # add offset to base and use as offset node.address = address if hasattr(node, 'offset'): address += node.offset for index in range(number): if not node.is_sequence: index = -1 # single entry # go over entries in group for entry in node.entries: # add offset to address and use as address if 'offset' in entry: address = (node.address + entry['offset']) if 'ref' in entry: # reference to other group subnode, address = generate_node(node, config, entry['ref'], registers, nodes, address, index) else: # register definition reg, address = generate_register(node, entry, registers, nodes, address, index) return node, address
def update_model(class_dict, cfg, model): for section in cfg: for name in cfg[section]: entry = cfg[section][name] # groups if section == "groups": item = Group(name) # layers elif section == "layers": item = get_spawn_method( class_dict, entry["class"])(name) # items # elif section == "items": # item = get_spawn_method( # class_dict, entry["class"]) else: item = entry if section != "populate": model[name] = item
def __init__(self, name): super(PauseMenuLayer, self).__init__(name) self._game_paused = False self._frame_advance = False self.pause_menu = None self.pause_layers = [] self.groups = [Group("pause menu group")]
def setActiveModule(Module): r"""Helps with collecting the members of the imported modules. """ module_name = Module.__name__ if module_name not in ModuleMembers: ModuleMembers[module_name] = [] ModulesQ.append(module_name) Group(Module, {}) # brand the module with __ec_member__ state.ActiveModuleMemberQ = ModuleMembers[module_name]
def generate_n_groups(time: int, dist: List[int], ngroups: int) -> List[Group]: """Generate ngroups groups according to dist. Time is the arrival time Assumptions: len(dist) == const.MAX_GROUP_SIZE - 1 """ sizes = random.choices(list(range(1, const.MAX_GROUP_SIZE + 1)), dist, k=ngroups) return [Group(n, time) for n in sizes]
def ld_timetable(cls, file_name): """Загрузка расписания""" with codecs.open(file_name, encoding='utf-8') as fl: data = fl.readlines() tt = Timetable(6, '09:00', 7, 95, 15) for lesson in data[1:]: day, class_number, subject_id = lesson.strip().split(';') subject_id = int(subject_id) for subject in cls.lst_subjects: if subject.subject_id == subject_id: tt.add_class(day, class_number, subject) break group = Group(data[0].strip(), tt) cls.lst_groups.append(group)
def slice_run(card_list, phase, valid_plays): """Get valid runs from slicing generated runs.""" # set definitions elements = len(card_list) phase_type = {4: 8, 5: 4} # generate slice positions for i in range(phase_type[phase], elements + 1): # do slice and check group validity given current phase temp = card_list[0 + i - phase_type[phase]:i] if Group(temp).group == phase: valid_plays.append((3, [temp])) if len(valid_plays): return True
def group(__decorated__, **Config): r"""A decorator to make groups out of classes. Config: * name (str): The name of the group. Defaults to __decorated__.__name__. * desc (str): The description of the group (optional). * alias (str): The alias for the group (optional). """ _Group = Group(__decorated__, Config) if isclass( __decorated__ ): # conver the method of the class to static methods so that they could be accessed like object methods; ir: g1/t1(...). static(__decorated__) state.ActiveModuleMemberQ.insert(0, _Group) return _Group.Underlying
def find_groups(self, wf, dif, blw): maxi=np.nonzero(np.logical_and(wf[:-1]<-blw, np.logical_and(dif[:-1]<0,dif[1:]>0)))[0] vals=np.nonzero(np.logical_and(dif[:-1]>0,dif[1:]<0))[0] for m in maxi[np.logical_and(maxi>self.init, maxi<self.fin)]: if np.any(vals<m): left=np.amax(vals[vals<m]) else: left=0 if np.any(vals>m): right=np.amin(vals[vals>m]) else: right=len(wf)-1 if left<self.init: self.init=left if right>self.fin: self.fin=right if -wf[m]>min_hit_height: self.groups.append(Group(m, left, right, -wf[m]))
def longest_run(player): """Get longest natural run to determine hold and discard logic.""" # initialise collectors unique_cards = ([], []) card_vals = ([], []) longest = [[], []] max_length = [0, 0] # separate card into colours for card in player.hand: if not card.value == 25: if card.value not in card_vals[card.colour]: unique_cards[card.colour].append(card.name) card_vals[card.colour].append(card.value) # iterate through all combinations curr_colour = -1 for colour in unique_cards: curr_colour += 1 elements = len(colour) # generate slice positions for i in range(2, elements + 1): for j in range(0, i): # do slice and determine length of run temp = colour[j:i] check_val = [Card(card).value for card in temp] length = Group(temp).check_run(check_val) # hold longest run length if length > max_length[curr_colour]: max_length[curr_colour] = length longest[curr_colour] = temp # determine if max length is equal, else hold both coloured runs if max_length[0] == max_length[1]: l_colour = (0, 1) elif max_length[0] > max_length[1]: l_colour = (0, ) else: l_colour = (1, ) return max_length, longest, l_colour
def check_4s(table, logical_plays, valid_plays): """Check validity of play, return first valid play.""" # define group types for each phase phase_groups = { 1: (1, 1), 2: (2, None), 3: (3, 3), 4: (4, None), 5: (5, 3) } # iterate through generated plays for validity for play in logical_plays: pid, gid = play[1][1][0], play[1][1][1] card, pos = play[1][0], play[1][1][2] phase = table.status[pid].phase group_type = phase_groups[phase][gid] group_cards = table.status[pid].group[gid].cards cards = [card.name for card in group_cards] if group_type is None: pass elif Group(cards, group_type).check_add(pos, card, group_type): valid_plays.append(play)
def list_nodes_recursively(node, doc=False, list=None): """ List the input group recursively. Groups are listed before their children. Bitfield are NOT listed. If 'doc' is true, then registers with the 'nodoc' attribute (sequences) are not in the list, but an artificial group with name (...) is inserted where registers are left out. The latter is used for documentation. """ if list is None: list = [] list.append(node) if hasattr(node, 'nodes'): done = False for item in node.nodes: if doc and item.parent.is_sequence and item.index > 0 and item.index < item.parent.number - 1: if (not done) and (item.index == 1): list.append(Group(node, {}, "...", 0)) done = True else: list_nodes_recursively(item, doc, list) return list
def phase_play(player, table, discard): """Return valid groups within hand for specified type.""" # get current player status phase = player.phase + 1 hand = player.hand_list # set collector list valid_plays = [] # definitions of groups in phases lengths = {1: (6, 3), 2: 7, 3: (8, 4), 5: (8, 4)} groups = {1: (1, 1), 2: 2, 3: (3, 3), 5: (5, 3)} # phase 1 or 3 if phase == 1 or phase == 3: # generate combinations for each group super_set = itertools.combinations(hand, lengths[phase][0]) for sub_set in super_set: for g1 in itertools.combinations(sub_set, lengths[phase][1]): # continue only if first group valid if Group(list(g1)).group == groups[phase][0]: g1, g2 = list(g1), list(sub_set) # determine second group for card in g1: g2.remove(card) # check second group if Group(g2).group == groups[phase][1]: valid_plays.append((3, [g1, g2])) # phase 2 if phase == 2: # generate combinations super_set = itertools.combinations(hand, lengths[phase]) # check group validity for g1 in super_set: if Group(list(g1)).group == groups[phase]: valid_plays.append((3, [list(g1)])) # phase 4 if phase == 4: # initialise collector lists unique_cards = [] wild_cards = [] card_vals = [] # pre-process hand for run generation for card in player.hand: if card.value not in card_vals and not card.value == 25: if card.name not in unique_cards: unique_cards.append(card.name) card_vals.append(card.value) if card.value == 25: wild_cards.append(card.name) # do run check only when minimum card elements met if len(unique_cards) + len(wild_cards) >= 8: make_run(unique_cards, wild_cards, phase, valid_plays) # phase 5 if phase == 5: # pre-process card list for run generation with collector lists unique_cards = ([], []) card_vals = ([], []) wild_cards = [] test_plays = ([], []) # split hand into separate colours and wilds for card in player.hand: if not card.value == 25: if card.value not in card_vals[card.colour]: unique_cards[card.colour].append(card.name) card_vals[card.colour].append(card.value) if card.value == 25: wild_cards.append(card.name) # do run check only when minimum card elements met if len(unique_cards[0]) + len(wild_cards) >= 4: make_run(unique_cards[0], wild_cards, phase, test_plays[0]) if len(unique_cards[1]) + len(wild_cards) >= 4: make_run(unique_cards[1], wild_cards, phase, test_plays[1]) # for each run, check remainder for valid group 3 test_plays = test_plays[0] + test_plays[1] for play in test_plays: g1 = play[1][0] curr_hand = hand[:] for card in g1: curr_hand.remove(card) for g2 in itertools.combinations(curr_hand, lengths[phase][1]): if Group(list(g2)).group == groups[phase][1]: valid_plays.append((3, [g1, list(g2)])) # play set with greatest score if len(valid_plays): best_score = 0 for play in valid_plays: score = Set(play[1][0]).score if score > best_score: best_play = play best_score = score return best_play # discard if no valid play else: return (5, discard[0])
def phasedout_group_type(group): """phasedout_group_type returns the group type of a list of cards.""" return Group(group).group
# user = User(user_info[0]['uid'], pickle.dumps(group_ids)) # db.session.add(user) count = 0 # requests counter images = [] for i in concrete_group_ids: search_query = api.groups.getById(group_id=str(i))[0]['name'] try: search_query = str(search_query.split(' ')[0]) + ' ' + str( search_query.split(' ')[1]) except: str(search_query.split(' ')[0]) song = api.audio.search(q=search_query, performer_only=1, count=1) bepop = BePopular(i, pickle.dumps(song)) db.session.add(bepop) audios = api.audio.search(q=search_query, performer_only=1, sort=0, count=10) groups_info = api.groups.getById(group_id=i, count=1, fields=['members_count', 'contacts']) group = Group(i, pickle.dumps(groups_info)) db.session.add(group) feed = Feed(i, pickle.dumps(audios)) db.session.add(feed) count += 2 if count % 4 == 0: time.sleep(3) db.session.commit()