# 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
        unit *= base
        power += 1

    size = size / unit
    ceil_size = ceil(size)
    ceil_size_10 = ceil(size * 10.0) / 10.0

    if power > 0 and size < 10.0 and ceil_size_10 < 10.0:
        result = "%.1f" % ceil_size_10
    elif ceil_size == base and power < len(powers) - 1:
        power += 1
        result = "1.0"
    else:
        result = str(ceil_size)

    return result + powers[power]


def format_duration(duration):
    if duration is None:
        return ''
        # return "<unknown>"

    try:
        duration = timedelta(seconds=round(duration))
    except OverflowError:
        return "<overflow>"
    return str(duration)



# 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

        unit *= base
        power += 1

    size = size / unit
    ceil_size = ceil(size)
    ceil_size_10 = ceil(size * 10.0) / 10.0

    if power > 0 and size < 10.0 and ceil_size_10 < 10.0:
        result = "%.1f" % ceil_size_10
    elif ceil_size == base and power < len(powers) - 1:
        power += 1
        result = "1.0"
    else:
        result = str(ceil_size)

    return result + powers[power]


def format_duration(duration):
    if duration is None:
        return ''
        # return "<unknown>"

    try:
        duration = timedelta(seconds=round(duration))
    except OverflowError:
        return "<overflow>"
    return str(duration)



def format_size(size, human_readable=False):