From 22f6402bceecf822a5738d0fc7add2097b5178c8 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Sat, 11 Feb 2017 22:14:34 +0100 Subject: [PATCH] Add nick-history functionality hover a nickname to show previous nicks --- tsstats/client.py | 1 + tsstats/log.py | 6 +++++- tsstats/template.py | 8 +++++++- tsstats/templates/stats.jinja2 | 2 +- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tsstats/client.py b/tsstats/client.py index 9335c4a..78835f5 100644 --- a/tsstats/client.py +++ b/tsstats/client.py @@ -70,6 +70,7 @@ class Client(object): # public self.identifier = identifier self.nick = nick + self.nick_history = set() self.connected = 0 self.onlinetime = datetime.timedelta() self.kicks = 0 diff --git a/tsstats/log.py b/tsstats/log.py index 2db8873..d391869 100644 --- a/tsstats/log.py +++ b/tsstats/log.py @@ -143,7 +143,11 @@ def _parse_details(log_path, ident_map=None, clients=None, online_dc=True): continue nick, clid = match.group('nick'), match.group('clid') client = clients.setdefault(clid, Client(clid, nick)) - client.nick = nick # set nick to display changes + # set current nick + client.nick = nick + # add nick to history + client.nick_history.add(nick) + action = match.group('action') if action == 'connected': client.connect(logdatetime) diff --git a/tsstats/template.py b/tsstats/template.py index 94b6e9b..59cc13e 100644 --- a/tsstats/template.py +++ b/tsstats/template.py @@ -20,7 +20,7 @@ def prepare_clients(clients, onlinetime_threshold=-1): ''' Prepare `clients` for rendering - sort them and convert onlinetime to string + 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 @@ -31,6 +31,12 @@ def prepare_clients(clients, onlinetime_threshold=-1): :return: `clients` sorted by onlinetime, kics, pkicks, bans and pbans :rtype: tsstats.template.SortedClients ''' + # drop current nick from nick-history + [ + c.nick_history.remove(c.nick) + for c in clients + if c.nick in c.nick_history + ] # sort by onlinetime onlinetime_ = sort_clients( clients, lambda c: c.onlinetime.total_seconds() diff --git a/tsstats/templates/stats.jinja2 b/tsstats/templates/stats.jinja2 index 31ab433..bb67f5c 100644 --- a/tsstats/templates/stats.jinja2 +++ b/tsstats/templates/stats.jinja2 @@ -13,7 +13,7 @@ {% for client, value in clients %} {% set id = [headline_id, client.nick|striptags]|join('.') %}
  • - {{ client.nick }}{{ " (" + client.identifier + ")" if debug }} + {{ client.nick }}{{ " (" + client.identifier + ")" if debug }} {{ value }}
  • {% endfor %}