def get_y_pred_from_y_proba(y_proba: DataFrame) -> Series: return pipe( y_proba.iterrows(), partial( map, decorate_unpack( lambda _, row: statements( max_value := max(list(row.values)), find(lambda value: value[1] == max_value, row.items())[0], ) ) ), partial(Series, index=y_proba.index), )
def get_published(tree): published_node = functional.find(is_published, tree.children, None) if published_node == None: return None return datetime.datetime.strptime( published_node.children[0], "%Y-%m-%dT%H:%M:%S", )
def handle_reaction(self, reaction, removed = False): emoji = reaction.emoji msg_when = reaction.original_msg_time reacting_user = self.lookup_user(reaction.reacting_user) game = find(lambda g: g.message.timestamp == msg_when, self.games) if game: self.handle_game_reaction(game, reacting_user, emoji, removed) self.maybe_record_stat(msg_when, reaction.channel.name, reacting_user, emoji, removed) self.maybe_record_useroption(reaction, removed, reacting_user)
def from_sml(s, **kwargs): link = kwargs['link'] tree = sml.read(s) assert tree.tag == 'post' title = functional.find(is_title, tree.children).children[0] authors = [a.children[0] for a in filter(is_author, tree.children)] keywords = [k.children[0] for k in filter(is_keyword, tree.children)] description = functional.find(is_description, tree.children).children[0] body = functional.find(is_body, tree.children) published = get_published(tree) return Post( title = title, authors = authors, keywords = keywords, description = description, body = body, published = published, link_filename = link, )
def from_sml(s, **kwargs): link = kwargs['link'] tree = sml.read(s) assert tree.tag == 'post' title = functional.find(is_title, tree.children).children[0] authors = [a.children[0] for a in filter(is_author, tree.children)] keywords = [k.children[0] for k in filter(is_keyword, tree.children)] description = functional.find(is_description, tree.children).children[0] body = functional.find(is_body, tree.children) published = get_published(tree) return Post( title=title, authors=authors, keywords=keywords, description=description, body=body, published=published, link_filename=link, )
def find_game(self, gametime): return find(lambda g: g.message_timestamp == gametime, self.games)
def cancel_game(self, game): found = find(lambda g: g.message_timestamp == game.message.timestamp, self.games) if not found: return self.games.remove(found) self.save()
def add_game(self, game): if find(lambda g: g.message_timestamp == game.message.timestamp, self.games): return self.games.append(game.to_historic()) self.save()
def remove(self, stat, user, voter): found = find(lambda s: s.has(stat, user, voter), self.stats) if found: self.stats.remove(found)
def add(self, stat, user, voter): already = find(lambda s: s.has(stat, user, voter), self.stats) if already: return self.stats.append(Stats.Stat(stat, user, voter))