From 5d7c90635605c7c3c1818bb9b16787db02299fc5 Mon Sep 17 00:00:00 2001 From: cedricbonhomme Date: Wed, 28 Apr 2010 08:11:19 +0200 Subject: Added tag cloud. Some improvements. --- pyAggr3g470r.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'pyAggr3g470r.py') diff --git a/pyAggr3g470r.py b/pyAggr3g470r.py index 8c33f7dc..42536371 100755 --- a/pyAggr3g470r.py +++ b/pyAggr3g470r.py @@ -11,6 +11,7 @@ import os import time import sqlite3 import cherrypy +import operator import threading from cherrypy.lib.static import serve_file @@ -173,7 +174,7 @@ class Root: return html - def management(self): + def management(self, word_size=6): """ Management of articles. """ @@ -211,6 +212,9 @@ class Root: html += "
\n" if self.articles: + self.top_words = utils.top_words(self.articles, n=50, size=int(word_size)) + if "pylab" not in utils.IMPORT_ERROR: + utils.create_histogram(self.top_words[:10]) html += "

Statistics

\n
\n" if "oice" not in utils.IMPORT_ERROR: nb_french = 0 @@ -223,16 +227,25 @@ class Root: nb_english += 1 nb_other = self.nb_articles - nb_french - nb_english + html += "Minimum size of a word: " + html += """
\n""" html += "\n" html += '" html += "
' html += "

Tag cloud

\n" html += '
' + \ - utils.tag_cloud(utils.top_words(self.articles, 50)) + '
' + utils.tag_cloud(self.top_words) + '' html += "
" html += "

Words count

\n" html += "
    \n" - for word, frequency in self.top_words: + for word, frequency in sorted(self.top_words, key=operator.itemgetter(1), reverse=True)[:10]: html += """\t
  1. %s: %s
  2. \n""" % \ (word, word, frequency) html += "
\n" @@ -740,7 +753,7 @@ class Root: self.articles, self.feeds = utils.load_feed() self.nb_articles = sum([feed[0] for feed in self.feeds.values()]) if self.articles != {}: - self.top_words = utils.top_words(self.articles, 10) + self.top_words = utils.top_words(self.articles, 10, size=6) if "pylab" not in utils.IMPORT_ERROR: utils.create_histogram(self.top_words) print "Base (%s) loaded" % utils.sqlite_base -- cgit