collate.py :  » Web-Server » SkunkWEB » skunkweb-3.4.4 » util » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Server » SkunkWEB 
SkunkWEB » skunkweb 3.4.4 » util » collate.py
#  
#  Copyright (C) 2001 Andrew T. Csillag <drew_csillag@geocities.com>
#  
#      You may distribute under the terms of either the GNU General
#      Public License or the SkunkWeb License, as specified in the
#      README file.
#   
#!/usr/local/bin/python
#
# Take the results generated by 'test_read_write' thing and collate into 
# HTML tables, for easy side-by-side comparrison
#
# Roman, Starmedia, 2000

import sys, cPickle, pprint

_outfile = 'results.html'

if len(sys.argv) == 1:
    print 'Usage: %s <result_file_1> <result_file_2> ...'
    print 'Output will be saved to file "%s"' % _outfile

    sys.exit(1)

_res = []
for f in sys.argv[1:]:
    try:
        data = cPickle.load ( open ( f, 'r' ) )
    except IOError:
        print 'Error: cannot read file %s' % f
        sys.exit(1)
    except PickleError:
        print 'Error: file %s doesn\'t seem to contain results data'
        sys.exit(1)

    _res.append ( data )

    print 'File %s: data for %s' % ( f, data[0] )

# Sort the results
_res.sort ( lambda x, y: cmp ( x[1], y[1] ))

out = open ( _outfile, 'w' )

def gen_headers ( out, res ):
    """
    Generate the headers
    """

    out.write ( '  <tr>\n' )
    out.write ( '    <th>File (kb)</th>\n' )
    out.write ( '    <th>Operation</th>\n' )
    for r in res:
        out.write ( '    <th align=center>%s</th>\n' % r[0])
    out.write ( '  </tr>\n\n' )

_fields = ( 'write', 'rename', 'write_rename', 'read', 'stat' )
def gen_size_data ( out, size, res ):
    """
    Generate data for a single size
    """
    out.write ( '  <tr>\n' )
    out.write ( '  <td align=center rowspan=%d><b>%.1f</b></tr>\n' % 
                (len(_fields) + 1, float(size) / 1024 ))

    for f in _fields:
        out.write ( '    <td>%s</td>\n' % f)

        for r in res:
            out.write ( '    <td align=right>%.6fs</td>\n' % r[size][f])

        out.write ( '  </tr>\n' )
        out.write ( '  <tr>\n' )

    # Do the totals
    out.write ( '    <td><b><i>%s</b></i></td>\n' % 'Total')

    for r in res:
        out.write ( '    <td align=right><b>%.3fs<b></td>\n' % r[size]['total'])

    out.write ( '  </tr>\n\n' )

#
# Ok, now - begin generating the HTML table
#
out.write ( '<html>\n' )
out.write ( '<title>Disk benchmark results</title>\n' )
out.write ( '<body color="blue" bgcolor="white">\n' )
out.write ( '<table border=3 width=100%>\n' )

# Generate the header data
gen_headers ( out, _res )

# Get the list of sizes
datas = map ( lambda x : x[2], _res )
sizes = datas[0].keys()                  # Assume all data is homogeneous
sizes.sort()

for s in sizes:
    gen_size_data ( out, s, datas )

# Close the table
out.write ( '  <tr>\n' ) 
out.write ( '     <td colspan=2><b>Total time:</b></td>\n' ) 

for r in _res:
    out.write ( '    <td align=right><b>%.4f sec</b></td>\n' % r[1] )

out.write ( '  </tr>\n' )

# Close the table
out.write ( '</table>\n</html>\n' )

out.close()
# All done!
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.