[Spambayes-checkins] spambayes/utilities pop3graph.py,1.1,1.2

Anthony Baxter anthonybaxter at users.sourceforge.net
Tue Jan 28 19:23:37 EST 2003


Update of /cvsroot/spambayes/spambayes/utilities
In directory sc8-pr-cvs1:/tmp/cvs-serv9465/utilities

Modified Files:
	pop3graph.py 
Log Message:
Whitespace n11n
(if localization can be l10n, normalization can be n11n :)


Index: pop3graph.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/utilities/pop3graph.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pop3graph.py	17 Jan 2003 06:45:37 -0000	1.1
--- pop3graph.py	29 Jan 2003 03:23:35 -0000	1.2
***************
*** 15,88 ****
  
  def usage():
!    print __doc__
  
  def main(argv):
!    opts, args = getopt.getopt(argv, "h", ["help"])
!    for opt, arg in opts:
!       if opt in ("-h", "--help"):
!          usage()
!          return
  
!    # Create the corpuses and the factory that reads the messages.
!    if options.pop3proxy_cache_use_gzip:
!        messageFactory = GzipFileMessageFactory()
!    else:
!        messageFactory = FileMessageFactory()
!    spamCorpus = FileCorpus(messageFactory, options.pop3proxy_spam_cache)
!    hamCorpus = FileCorpus(messageFactory, options.pop3proxy_ham_cache)
  
!    # Read in all the trained messages.
!    allTrained = {}
!    for corpus, disposition in [(spamCorpus, 'Yes'), (hamCorpus, 'No')]:
!       for m in corpus:
!          message = mboxutils.get_message(m.getSubstance())
!          message._pop3CacheDisposition = disposition
!          allTrained[m.key()] = message
  
!    # Sort the messages into the order they arrived, then work out a scaling
!    # factor for the graph - 'limit' is the widest it can be in characters.
!    keys = allTrained.keys()
!    keys.sort()
!    limit = 70
!    if len(keys) < limit:
!       scale = 1
!    else:
!       scale = len(keys) // (limit//2)
  
!    # Build the data - an array of cumulative success indexed by count.
!    count = successful = 0
!    successByCount = []
!    for key in keys:
!       message = allTrained[key]
!       disposition = message[options.hammie_header_name]
!       if (message._pop3CacheDisposition == disposition):
!          successful += 1
!       count += 1
!       if count % scale == (scale-1):
!          successByCount.append(successful // scale)
  
!    # Build the graph, as a list of rows of characters.
!    size = count // scale
!    graph = [[" " for i in range(size+3)] for j in range(size)]
!    for c in range(size):
!       graph[c][1] = "|"
!       graph[c][c+3] = "."
!       graph[successByCount[c]][c+3] = "*"
!    graph.reverse()
  
!    # Print the graph.
!    print "\n   Success of the classifier over time:\n"
!    print "   . - Number of messages over time"
!    print "   * - Number of correctly classified messages over time\n\n"
!    for row in range(size):
!       line = ''.join(graph[row])
!       if row == 0:
!          print line + " %d" % count
!       elif row == (count - successful) // scale:
!          print line + " %d" % successful
!       else:
!          print line
!    print " " + "_" * (size+2)
  
  if __name__ == '__main__':
!    main(sys.argv[1:])
--- 15,88 ----
  
  def usage():
!     print __doc__
  
  def main(argv):
!     opts, args = getopt.getopt(argv, "h", ["help"])
!     for opt, arg in opts:
!         if opt in ("-h", "--help"):
!             usage()
!             return
  
!     # Create the corpuses and the factory that reads the messages.
!     if options.pop3proxy_cache_use_gzip:
!         messageFactory = GzipFileMessageFactory()
!     else:
!         messageFactory = FileMessageFactory()
!     spamCorpus = FileCorpus(messageFactory, options.pop3proxy_spam_cache)
!     hamCorpus = FileCorpus(messageFactory, options.pop3proxy_ham_cache)
  
!     # Read in all the trained messages.
!     allTrained = {}
!     for corpus, disposition in [(spamCorpus, 'Yes'), (hamCorpus, 'No')]:
!         for m in corpus:
!             message = mboxutils.get_message(m.getSubstance())
!             message._pop3CacheDisposition = disposition
!             allTrained[m.key()] = message
  
!     # Sort the messages into the order they arrived, then work out a scaling
!     # factor for the graph - 'limit' is the widest it can be in characters.
!     keys = allTrained.keys()
!     keys.sort()
!     limit = 70
!     if len(keys) < limit:
!         scale = 1
!     else:
!         scale = len(keys) // (limit//2)
  
!     # Build the data - an array of cumulative success indexed by count.
!     count = successful = 0
!     successByCount = []
!     for key in keys:
!         message = allTrained[key]
!         disposition = message[options.hammie_header_name]
!         if (message._pop3CacheDisposition == disposition):
!             successful += 1
!         count += 1
!         if count % scale == (scale-1):
!             successByCount.append(successful // scale)
  
!     # Build the graph, as a list of rows of characters.
!     size = count // scale
!     graph = [[" " for i in range(size+3)] for j in range(size)]
!     for c in range(size):
!         graph[c][1] = "|"
!         graph[c][c+3] = "."
!         graph[successByCount[c]][c+3] = "*"
!     graph.reverse()
  
!     # Print the graph.
!     print "\n   Success of the classifier over time:\n"
!     print "   . - Number of messages over time"
!     print "   * - Number of correctly classified messages over time\n\n"
!     for row in range(size):
!         line = ''.join(graph[row])
!         if row == 0:
!             print line + " %d" % count
!         elif row == (count - successful) // scale:
!             print line + " %d" % successful
!         else:
!             print line
!     print " " + "_" * (size+2)
  
  if __name__ == '__main__':
!     main(sys.argv[1:])





More information about the Spambayes-checkins mailing list