Esempio n. 1
0
def prepare_clients(clients, onlinetime_threshold=-1):
    '''
    Prepare `clients` for rendering

    sort them, clean their nick-history and convert onlinetime to string

    :param clients: List of clients to prepare
    :param onlinetime_threshold: threshold for clients onlinetime

    :type clients: tsstats.client.Clients
    :type onlinetime_treshold: int

    :return: `clients` sorted by onlinetime, kics, pkicks, bans and pbans
    :rtype: tsstats.template.SortedClients
    '''
    # sort by onlinetime
    onlinetime_ = sort_clients(
        clients, lambda c: c.onlinetime.total_seconds()
    )
    # filter clients not matching threshold
    onlinetime_ = filter_threshold(onlinetime_, onlinetime_threshold)
    # convert timespans to text
    onlinetime = [
        (client, seconds_to_text(int(onlinetime)))
        for client, onlinetime in onlinetime_
    ]
    return SortedClients(
        onlinetime=onlinetime,
        kicks=sort_clients(clients, lambda c: c.kicks),
        pkicks=sort_clients(clients, lambda c: c.pkicks),
        bans=sort_clients(clients, lambda c: c.bans),
        pbans=sort_clients(clients, lambda c: c.pbans)
    )
Esempio n. 2
0
def prepare_clients(clients, onlinetime_threshold=-1):
    '''
    Prepare `clients` for rendering

    sort them and convert onlinetime to string

    :param clients: List of clients to prepare
    :param onlinetime_threshold: threshold for clients onlinetime

    :type clients: tsstats.client.Clients
    :type onlinetime_treshold: int

    :return: `clients` sorted by onlinetime, kics, pkicks, bans and pbans
    :rtype: tsstats.template.SortedClients
    '''
    # sort by onlinetime
    onlinetime_ = sort_clients(
        clients, lambda c: c.onlinetime.total_seconds()
    )
    # filter clients not matching threshold
    onlinetime_ = filter_threshold(onlinetime_,
                                   onlinetime_threshold)
    # convert timespans to text
    onlinetime = [
        (client, seconds_to_text(int(onlinetime)))
        for client, onlinetime in onlinetime_
    ]
    return SortedClients(
        onlinetime=onlinetime,
        kicks=sort_clients(clients, lambda c: c.kicks),
        pkicks=sort_clients(clients, lambda c: c.pkicks),
        bans=sort_clients(clients, lambda c: c.bans),
        pbans=sort_clients(clients, lambda c: c.pbans)
    )
Esempio n. 3
0
def test_onlinetime(soup):
    # move this into a (parameterized) fixture or function
    items = soup.find("ul", id="1.onlinetime").find_all("li")
    nick_data = {}
    for item in items:
        nick, data = item.find_all("span")
        nick_data[nick.text] = data.text
    # seperate between uuid and id-clients or merge them some way
    # => assert len(items) == len(clients.id)
    assert len(items) == 2
    for client in clients:
        if client.nick in nick_data and client.onlinetime > timedelta(0):
            # remove this clause after splitting cients
            # (uuid-clients will never have a online-time, because
            #  they're only used for bans and kicks)
            assert nick_data[client.nick] == seconds_to_text(int(client.onlinetime.total_seconds()))