# Path: gauged/utilities.py
# def table_repr(columns, rows, data, padding=2):
#     """Generate a table for cli output"""
#     padding = ' ' * padding
#     column_lengths = [len(column) for column in columns]
#     for row in rows:
#         for i, column in enumerate(columns):
#             item = str(data[row][column])
#             column_lengths[i] = max(len(item), column_lengths[i])
#     max_row_length = max(len(row) for row in rows) if len(rows) else 0
#     table_row = ' ' * max_row_length
#     for i, column in enumerate(columns):
#         table_row += padding + column.rjust(column_lengths[i])
#     table_rows = [table_row]
#     for row in rows:
#         table_row = row.rjust(max_row_length)
#         for i, column in enumerate(columns):
#             item = str(data[row][column])
#             table_row += padding + item.rjust(column_lengths[i])
#         table_rows.append(table_row)
#     return '\n'.join(table_rows)
# 
# def to_datetime(milliseconds):
#     """Convert a timestamp in milliseconds to a datetime"""
#     return datetime.fromtimestamp(milliseconds // 1000)


from ..utilities import table_repr, to_datetime
"""
Gauged
https://github.com/chriso/gauged (MIT Licensed)
Copyright 2014 (c) Chris O'Hara <cohara87@gmail.com>
"""



class TimeSeries(object):
    """A representation of a time series with a fixed interval"""

    def __init__(self, points):
        """Initialise the time series. `points` is expected to be either a list
        of tuples where each tuple represents a point (timestamp, value), or a
        dict where the keys are timestamps. Timestamps are expected to be in
        milliseconds"""
        if isinstance(points, dict):
            points = points.items()
        self.points = sorted(points)

    @property
    def timestamps(self):
        """Get all timestamps from the series"""
        return [point[0] for point in self.points]

    @property
    def dates(self):
        """Get all dates from the time series as `datetime` instances"""

# Path: gauged/utilities.py
# def table_repr(columns, rows, data, padding=2):
#     """Generate a table for cli output"""
#     padding = ' ' * padding
#     column_lengths = [len(column) for column in columns]
#     for row in rows:
#         for i, column in enumerate(columns):
#             item = str(data[row][column])
#             column_lengths[i] = max(len(item), column_lengths[i])
#     max_row_length = max(len(row) for row in rows) if len(rows) else 0
#     table_row = ' ' * max_row_length
#     for i, column in enumerate(columns):
#         table_row += padding + column.rjust(column_lengths[i])
#     table_rows = [table_row]
#     for row in rows:
#         table_row = row.rjust(max_row_length)
#         for i, column in enumerate(columns):
#             item = str(data[row][column])
#             table_row += padding + item.rjust(column_lengths[i])
#         table_rows.append(table_row)
#     return '\n'.join(table_rows)
# 
# def to_datetime(milliseconds):
#     """Convert a timestamp in milliseconds to a datetime"""
#     return datetime.fromtimestamp(milliseconds // 1000)


# Path: gauged/results/time_series.py
from ..utilities import table_repr, to_datetime

"""
Gauged
https://github.com/chriso/gauged (MIT Licensed)
Copyright 2014 (c) Chris O'Hara <cohara87@gmail.com>
"""



class TimeSeries(object):
    """A representation of a time series with a fixed interval"""

    def __init__(self, points):
        """Initialise the time series. `points` is expected to be either a list
        of tuples where each tuple represents a point (timestamp, value), or a
        dict where the keys are timestamps. Timestamps are expected to be in
        milliseconds"""
        if isinstance(points, dict):
            points = points.items()
        self.points = sorted(points)

    @property
    def timestamps(self):
        """Get all timestamps from the series"""
        return [point[0] for point in self.points]

    @property
    def dates(self):
        """Get all dates from the time series as `datetime` instances"""

        return [to_datetime(timestamp) for timestamp, _ in self.points]