# 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.
#         '''
# 
# 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)


from operator import itemgetter
from six import print_, itervalues
from marathoner.commands.base import BaseCommand
from marathoner.utils.print_table import print_table
import re
    syntax = 'tag'
    help = 'print list of existing tags'

    cmd_re = re.compile(r'^\s*tags?\s*$', re.IGNORECASE)
    def is_match(self, command):
        return self.cmd_re.match(command)

    def handle(self, command):
        header = [['Tag', 'Seeds', 'Avg. score', 'Created']]
        current_tag = self.project.current_tag
        table = []
        best_score = 0.0
        for tag in itervalues(self.project.tags):
            avg_score = tag.get_avg_relative_score()
            best_score = max(best_score, avg_score)
            row = [
                ('(*) ' if current_tag is tag else '') + tag.name,
                len(tag.scores),
                avg_score,
                tag.time_created.strftime('%Y-%m-%d %X')]
            table.append(row)

        # format avg scores
        for row in table:
            avg_score = row[2]
            if avg_score == best_score:
                row[2] = '(!) %.5f' % avg_score
            else:
                row[2] = '%.5f' % avg_score


# 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.
#         '''
# 
# 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/tag.py
from operator import itemgetter
from six import print_, itervalues
from marathoner.commands.base import BaseCommand
from marathoner.utils.print_table import print_table
import re

    syntax = 'tag'
    help = 'print list of existing tags'

    cmd_re = re.compile(r'^\s*tags?\s*$', re.IGNORECASE)
    def is_match(self, command):
        return self.cmd_re.match(command)

    def handle(self, command):
        header = [['Tag', 'Seeds', 'Avg. score', 'Created']]
        current_tag = self.project.current_tag
        table = []
        best_score = 0.0
        for tag in itervalues(self.project.tags):
            avg_score = tag.get_avg_relative_score()
            best_score = max(best_score, avg_score)
            row = [
                ('(*) ' if current_tag is tag else '') + tag.name,
                len(tag.scores),
                avg_score,
                tag.time_created.strftime('%Y-%m-%d %X')]
            table.append(row)

        # format avg scores
        for row in table:
            avg_score = row[2]
            if avg_score == best_score:
                row[2] = '(!) %.5f' % avg_score
            else:
                row[2] = '%.5f' % avg_score


        if table: