Example #1
0
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),
    )
Example #2
0
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",
    )
Example #3
0
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",
    )
Example #4
0
    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)
Example #5
0
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,
    )
Example #6
0
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,
    )
Example #7
0
 def find_game(self, gametime):
     return find(lambda g: g.message_timestamp == gametime, self.games)
Example #8
0
 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()
Example #9
0
 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()
Example #10
0
 def remove(self, stat, user, voter):
     found = find(lambda s: s.has(stat, user, voter), self.stats)
     if found:
         self.stats.remove(found)
Example #11
0
    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))