From 42afa12765278c469f6e79c7d03415eceea8d5f5 Mon Sep 17 00:00:00 2001 From: Daniel DiPaolo Date: Wed, 3 Dec 2003 03:14:40 +0000 Subject: [PATCH] Time to *really* finish up the stuff in the RFE and not just close it without completely finishing it off ;) --- plugins/ChannelDB.py | 24 +++++++++++++++++++----- test/test_ChannelDB.py | 5 +++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/plugins/ChannelDB.py b/plugins/ChannelDB.py index ce8a6778d..55a92c48a 100644 --- a/plugins/ChannelDB.py +++ b/plugins/ChannelDB.py @@ -72,7 +72,10 @@ class ChannelDB(plugins.ChannelDBHandler, [('self-stats', plugins.ConfigurableBoolType, True, """Determines whether the bot will keep channel statistics on itself, possibly skewing the channel stats (especially in cases where he's - relaying between channels on a network.""")] + relaying between channels on a network."""), + ('wordstats-top-n', plugins.ConfigurableIntType, 3, + """Determines the maximum number of top users to show for a given + wordstat when you request the wordstats for a particular word.""")] ) def __init__(self): callbacks.Privmsg.__init__(self) @@ -564,21 +567,32 @@ class ChannelDB(plugins.ChannelDBHandler, else: # It's a word, not a user word = arg1 + numUsers = self.configurables.get('wordstats-top-n', + msg.args[0]) cursor.execute("""SELECT word_stats.count, word_stats.user_id FROM words, word_stats WHERE words.word=%s AND words.id=word_stats.word_id - ORDER BY word_stats.count DESC""", word) + ORDER BY word_stats.count DESC""", + word) if cursor.rowcount == 0: irc.error(msg, 'No one has said %r' % word) return results = cursor.fetchall() - maxResults = 3 + numResultsShown = min(cursor.rowcount, numUsers) + cursor.execute("""SELECT sum(word_stats.count) + FROM words, word_stats + WHERE words.word=%s AND + words.id=word_stats.word_id""", + word) + total = int(cursor.fetchone()[0]) ers = '%rer' % word - ret = 'Top %s: ' % utils.nItems(maxResults, ers) + ret = 'Top %s ' % utils.nItems(numResultsShown, ers) + ret += '(out of a total of %s seen):' % \ + utils.nItems(total, repr(word)) L = [] - for (count, id) in results[:maxResults]: + for (count, id) in results[:numResultsShown]: username = ircdb.users.getUser(id).name L.append('%s: %s' % (username, count)) try: diff --git a/test/test_ChannelDB.py b/test/test_ChannelDB.py index c608153db..fb2fa1d9b 100644 --- a/test/test_ChannelDB.py +++ b/test/test_ChannelDB.py @@ -130,6 +130,11 @@ if sqlite is not None: self.assertRegexp('wordstats lol', '3.*%s: 10.*%s: 5.*foo: 3' % (userNick2, userNick1)) + # Check for the extra-swanky stuff too + self.assertRegexp('wordstats lol', + 'total.*19 \'lol\'s.*%s: 10.*%s: 5.*foo: 4.*' + 'ranked 3 out of 3 \'lol\'ers' % \ + (userNick2, userNick1)) def testWordStatsUserWord(self): self.assertNotError('addword lol')