示例#1
0
def generate_results_table(results):
	"""Generate a results table"""

	total_votes = get_total_votes(results)

	results_data = []
	ordered_results = sorted(results.iteritems(), key=lambda x: x[1])
	ordered_results.reverse()

	for party, votes in ordered_results:
		results_data.append([
			party,
			votes,
			'%.2f %%' % ((float(votes) / float(total_votes)) * 100.0),
		])

	t = Table(results_data)
	t.headers = ('Party', 'Votes', 'Percentage')
	t.col_separator = ' | '
	t.header_separator = '-'
	t.print_table()
示例#2
0
def main():
    import sys

    if len(sys.argv) < 2 or sys.argv[1] == '-':
        problem_file = sys.stdin
    else:
        try:
            problem_file = open(sys.argv[1])
        except IOError:
            sys.stderr.write("Couldn't open file %s\n" % problem_file)
            sys.exit(-1)

    csp = CrewSchedulingProblem(problem_file)

    if problem_file == sys.stdin:
        print '--- Problem from stdin ---'
    else:
        print '--- Problem: %s ---' % (sys.argv[1])
    
    print 'Problem size: %d' % len(csp.tasks)
    print 'Time limit: %d  ' % csp.time_limit
    print 'Transitions: %d ' % len(csp.transition_costs)
    print

    try:
        from ptable import Table
    except ImportError:
        pass
    else:
        t = Table(csp.generate_rotations())
        t.headers = ('Rotation', 'Cost', 'Duration')
        t.align = 'lrr'
        t.col_separator = ' | '
        t.repeat_headers_after = 25
        t.header_separator = True
        t.print_table()
    print '# of rotations: %d' % (len(t.data))