nixspamsum
changeset 3 6b0d09cdfbdb
parent 2 a72ea07394cc
child 4 ae58d9881be5
equal deleted inserted replaced
2:a72ea07394cc 3:6b0d09cdfbdb
    91     doms = sorted(domains.items(), lambda d,c: cmp(d[k],c[k]), reverse=k)
    91     doms = sorted(domains.items(), lambda d,c: cmp(d[k],c[k]), reverse=k)
    92     dlen = getDomLen(domains.keys())+1
    92     dlen = getDomLen(domains.keys())+1
    93     clen = len(str(max(domains.values())))
    93     clen = len(str(max(domains.values())))
    94     total = sum(domains.values())
    94     total = sum(domains.values())
    95     if percent:
    95     if percent:
    96         format = '%%%ds  %%%dd  %%5.2f %%%%\n' % (dlen, clen)
    96         format = ' %%%ds  %%%dd  %%6.2f %%%%\n' % (-dlen, clen)
    97         for d, c in doms:
    97         for d, c in doms:
    98             dfrac = 100./total*c
    98             dfrac = 100./total*c
    99             output.write(format % (d, c, dfrac))
    99             output.write(format % (d, c, dfrac))
       
   100         output.write('%s\n' % ((clen+dlen+14)*'-'))
       
   101         output.write(format % ('total', total, 100))
   100     else:
   102     else:
   101         format = '%%%ds  %%%dd\n' % (dlen, clen)
   103         format = ' %%%ds  %%%dd\n' % (-dlen, clen)
   102         for d in doms:
   104         for d in doms:
   103             output.write(format % d)
   105             output.write(format % d)
       
   106         output.write('%s\n' % ((clen+dlen+4)*'-'))
       
   107         output.write(format % ('total', total))
   104 
   108 
   105 def showResult(nixspamsum, options):
   109 def showResult(nixspamsum, options):
   106     from cStringIO import StringIO
   110     from cStringIO import StringIO
   107     output = StringIO()
   111     output = StringIO()
   108     if options.countByDom:
   112     if options.countByDom: