# Path: marathoner/commands/base.py
# class BaseCommand(object):
#     syntax = ''
#     help = ''
# 
#     def __init__(self, project, executor):
#         self.project = project
#         self.executor = executor
#         self.contest = project.contest
# 
#     def is_match(self, command):
#         '''Given is the text that user typed into command line, return True
#         if this command should execute.
#         '''
#         raise NotImplementedError()
# 
#     def handle(self, command):
#         '''Given is the text that user typed into command line, execute the
#         command.
#         '''
# 
# class CommandSyntaxError(Exception):
#     pass
# 
# Path: marathoner/utils/print_table.py
# def print_table(*tables):
#     '''Print tabular data in format:
# 
#     If `tables` is: [header, data, footer], then print:
#         ----------|---------|-----|
#         | header1 | header2 | ... |
#         | headerx | headery | ... |
#         |---------|---------|-----|
#         |   data1 |   data2 | ... |
#         |   datax |   datay | ... |
#         |---------|---------|-----|
#         | footer1 | footer2 | ... |
#         | footerx | footery | ... |
#         |---------|---------|-----|
# 
#     '''
#     # calculate length for each column
#     column_width = [0] * len(tables[0][0])
#     def update_column_widths(row):
#         for i, data in enumerate(row):
#             column_width[i] = max(column_width[i], len(str(data)))
#     for table in tables:
#         for row in table:
#             update_column_widths(row)
# 
#     # create formatting string
#     format = '| %s |' %  ' | '.join('%%%ss' % width for width in column_width)
#     hline = '|-%s-|' % '-|-'.join('-' * width for width in column_width)  # horizontal line
# 
#     print_(hline)
#     for table in tables:
#         print_('\n'.join(format % tuple(row) for row in table))
#         print_(hline)


import re
from six import print_
from six.moves import xrange
from marathoner.commands.base import BaseCommand, CommandSyntaxError
from marathoner.utils.print_table import print_table




class Command(BaseCommand):
    syntax = 'best [<seed1>] [<seed2>]'
    help = 'print best score for the selected seeds'

    cmd_re = re.compile(r'^\s*best(?:\s+(\d+)(?:\s+(\d+))?)?\s*$', re.IGNORECASE)
    match_re = re.compile(r'\s*best\b', re.IGNORECASE)

    def is_match(self, command):
        return self.match_re.match(command)

    def handle(self, command):
        header = [['Seed', 'Score', 'Run time']]
        table = []
        def add_seed(seed):
            score = self.project.scores[seed]
            table.append([seed, '%.2f' % score.score, '%.2f' % score.run_time])


# Path: marathoner/commands/base.py
# class BaseCommand(object):
#     syntax = ''
#     help = ''
# 
#     def __init__(self, project, executor):
#         self.project = project
#         self.executor = executor
#         self.contest = project.contest
# 
#     def is_match(self, command):
#         '''Given is the text that user typed into command line, return True
#         if this command should execute.
#         '''
#         raise NotImplementedError()
# 
#     def handle(self, command):
#         '''Given is the text that user typed into command line, execute the
#         command.
#         '''
# 
# class CommandSyntaxError(Exception):
#     pass
# 
# Path: marathoner/utils/print_table.py
# def print_table(*tables):
#     '''Print tabular data in format:
# 
#     If `tables` is: [header, data, footer], then print:
#         ----------|---------|-----|
#         | header1 | header2 | ... |
#         | headerx | headery | ... |
#         |---------|---------|-----|
#         |   data1 |   data2 | ... |
#         |   datax |   datay | ... |
#         |---------|---------|-----|
#         | footer1 | footer2 | ... |
#         | footerx | footery | ... |
#         |---------|---------|-----|
# 
#     '''
#     # calculate length for each column
#     column_width = [0] * len(tables[0][0])
#     def update_column_widths(row):
#         for i, data in enumerate(row):
#             column_width[i] = max(column_width[i], len(str(data)))
#     for table in tables:
#         for row in table:
#             update_column_widths(row)
# 
#     # create formatting string
#     format = '| %s |' %  ' | '.join('%%%ss' % width for width in column_width)
#     hline = '|-%s-|' % '-|-'.join('-' * width for width in column_width)  # horizontal line
# 
#     print_(hline)
#     for table in tables:
#         print_('\n'.join(format % tuple(row) for row in table))
#         print_(hline)


# Path: marathoner/commands/best.py
import re
from six import print_
from six.moves import xrange
from marathoner.commands.base import BaseCommand, CommandSyntaxError
from marathoner.utils.print_table import print_table





class Command(BaseCommand):
    syntax = 'best [<seed1>] [<seed2>]'
    help = 'print best score for the selected seeds'

    cmd_re = re.compile(r'^\s*best(?:\s+(\d+)(?:\s+(\d+))?)?\s*$', re.IGNORECASE)
    match_re = re.compile(r'\s*best\b', re.IGNORECASE)

    def is_match(self, command):
        return self.match_re.match(command)

    def handle(self, command):
        header = [['Seed', 'Score', 'Run time']]
        table = []
        def add_seed(seed):
            score = self.project.scores[seed]
            table.append([seed, '%.2f' % score.score, '%.2f' % score.run_time])


        match = self.cmd_re.match(command)