# Path: muninn/schema.py
# class Timestamp(Type):
#     @classmethod
#     def validate(cls, value):
#         if type(value) is not datetime.datetime:
#             raise ValueError("invalid value %r for type %r" % (value, cls.name()))
# 
# Path: muninn/database/sql.py
# AGGREGATE_FUNCTIONS = collections.OrderedDict([
#     (Long, ['min', 'max', 'sum', 'avg']),
#     (Integer, ['min', 'max', 'sum', 'avg']),
#     (Real, ['min', 'max', 'sum', 'avg']),
#     # (Boolean, []),
#     (Text, ['min', 'max']),
#     (Timestamp, ['min', 'max']),
#     # (UUID, []),
#     # (Geometry, []),
#     (None, ['min', 'max', 'sum', 'avg']),  # special case: validity_duration
# ])
# 
# GROUP_BY_FUNCTIONS = collections.OrderedDict([
#     (Long, [None, ]),
#     (Integer, [None, ]),
#     # (Real, []),
#     (Boolean, [None, ]),
#     (Text, [None]),  # (Text, [None, 'length']),
#     (Timestamp, ['year', 'month', 'yearmonth', 'date', 'day', 'hour', 'minute', 'second', 'time']),
#     # (UUID, []),
#     # (Geometry, []),
# ])
# 
# Path: muninn/tools/utils.py
# def create_parser(*args, **kwargs):
#     parser = argparse.ArgumentParser(*args, parents=[version_parser], **kwargs)
#     parser.add_argument("--verbose", action="store_true", help="display debug information")
#     return parser
# 
# def parse_args_and_run(parser, func):
#     args, unused_args = version_parser.parse_known_args()
#     if args.version:
#         version(os.path.basename(sys.argv[0]))
#         sys.exit(0)
# 
#     args = parser.parse_args(unused_args)
# 
#     log_level = logging.DEBUG if args.verbose else logging.INFO
#     logging.basicConfig(level=log_level, format="%(levelname)s: %(message)s")
# 
#     try:
#         return func(args)
#     except SystemExit:
#         raise
#     except KeyboardInterrupt:
#         sys.exit(1)
#     except muninn.Error as error:
#         logging.error(error)
#         sys.exit(1)
#     except Exception:
#         log_internal_error()
#         sys.exit(1)
#     finally:
#         logging.shutdown()


import re
import argparse
import muninn
    import tabulate
from datetime import timedelta
from muninn.schema import Timestamp
from muninn.database.sql import AGGREGATE_FUNCTIONS, GROUP_BY_FUNCTIONS
from .utils import create_parser, parse_args_and_run

    return human_readable_size(float(size))


# Support multiple table output formats

class PlainWriter(object):
    def __init__(self, header, human_readable=False):
        self._header = [re.sub('^core.', '', item) for item in header]
        self._duration_fields = []
        self._size_fields = []
        self.human_readable = human_readable
        for i, name in enumerate(header):
            if name.startswith('core.validity_duration'):
                self._duration_fields.append(i)
            elif name.startswith('core.size'):
                self._size_fields.append(i)

    def header(self):
        print("|", " | ".join(self._header), "|")

    def _format_items(self, values):
        result = []
        for i, value in enumerate(values):
            if i in self._duration_fields:
                result.append(format_duration(value))
            elif i in self._size_fields:
                result.append(format_size(value, self.human_readable))
            else:
                result.append(value)

# Path: muninn/schema.py
# class Timestamp(Type):
#     @classmethod
#     def validate(cls, value):
#         if type(value) is not datetime.datetime:
#             raise ValueError("invalid value %r for type %r" % (value, cls.name()))
# 
# Path: muninn/database/sql.py
# AGGREGATE_FUNCTIONS = collections.OrderedDict([
#     (Long, ['min', 'max', 'sum', 'avg']),
#     (Integer, ['min', 'max', 'sum', 'avg']),
#     (Real, ['min', 'max', 'sum', 'avg']),
#     # (Boolean, []),
#     (Text, ['min', 'max']),
#     (Timestamp, ['min', 'max']),
#     # (UUID, []),
#     # (Geometry, []),
#     (None, ['min', 'max', 'sum', 'avg']),  # special case: validity_duration
# ])
# 
# GROUP_BY_FUNCTIONS = collections.OrderedDict([
#     (Long, [None, ]),
#     (Integer, [None, ]),
#     # (Real, []),
#     (Boolean, [None, ]),
#     (Text, [None]),  # (Text, [None, 'length']),
#     (Timestamp, ['year', 'month', 'yearmonth', 'date', 'day', 'hour', 'minute', 'second', 'time']),
#     # (UUID, []),
#     # (Geometry, []),
# ])
# 
# Path: muninn/tools/utils.py
# def create_parser(*args, **kwargs):
#     parser = argparse.ArgumentParser(*args, parents=[version_parser], **kwargs)
#     parser.add_argument("--verbose", action="store_true", help="display debug information")
#     return parser
# 
# def parse_args_and_run(parser, func):
#     args, unused_args = version_parser.parse_known_args()
#     if args.version:
#         version(os.path.basename(sys.argv[0]))
#         sys.exit(0)
# 
#     args = parser.parse_args(unused_args)
# 
#     log_level = logging.DEBUG if args.verbose else logging.INFO
#     logging.basicConfig(level=log_level, format="%(levelname)s: %(message)s")
# 
#     try:
#         return func(args)
#     except SystemExit:
#         raise
#     except KeyboardInterrupt:
#         sys.exit(1)
#     except muninn.Error as error:
#         logging.error(error)
#         sys.exit(1)
#     except Exception:
#         log_internal_error()
#         sys.exit(1)
#     finally:
#         logging.shutdown()


# Path: muninn/tools/summary.py
import re
import argparse
import muninn
    import tabulate
from datetime import timedelta
from muninn.schema import Timestamp
from muninn.database.sql import AGGREGATE_FUNCTIONS, GROUP_BY_FUNCTIONS
from .utils import create_parser, parse_args_and_run


    return human_readable_size(float(size))


# Support multiple table output formats

class PlainWriter(object):
    def __init__(self, header, human_readable=False):
        self._header = [re.sub('^core.', '', item) for item in header]
        self._duration_fields = []
        self._size_fields = []
        self.human_readable = human_readable
        for i, name in enumerate(header):
            if name.startswith('core.validity_duration'):
                self._duration_fields.append(i)
            elif name.startswith('core.size'):
                self._size_fields.append(i)

    def header(self):
        print("|", " | ".join(self._header), "|")

    def _format_items(self, values):
        result = []
        for i, value in enumerate(values):
            if i in self._duration_fields:
                result.append(format_duration(value))
            elif i in self._size_fields:
                result.append(format_size(value, self.human_readable))
            else:
                result.append(value)

        return result