コード例 #1
0
def render_result(cursor):
    column_names = [c.name for c in cursor.description]
    column_align = ">" * len(column_names)
    column_sizes = ["max"] * len(column_names)
    rows = cursor.fetchall()

    return render_table(column_names, column_align, column_sizes, rows)
コード例 #2
0
def render_source(source):
    """
    Renders a data 'source' in the form of a table-like object:

    [
        ('column_1', 'column_2', 'column_3', ...),
        (1, 2, 3,...),
        (4, 5, 6,...),
        ...
    ]
    """
    column_names = head(source)
    column_align = ">" * len(column_names)
    column_sizes = ["max"] * len(column_names)
    rows = tail(source)

    return render_table(column_names, column_align, column_sizes, rows)
コード例 #3
0
def render_datapackage(datapackage):
    """
    Renders a data 'source' in the form of a table-like object:

    [
        ('column_1', 'column_2', 'column_3', ...),
        (1, 2, 3,...),
        (4, 5, 6,...),
        ...
    ]
    """
    column_names = datapackage.trend_names
    column_align = ">" * len(column_names)
    column_sizes = ["max"] * len(column_names)
    rows = [(r[0], datapackage.timestamp) + tuple(r[1]) for r in datapackage.rows]

    return render_table(column_names, column_align, column_sizes, rows)
コード例 #4
0
def render_function_set_table(function_sets):
    def make_table_row(function_set):
        enabled = 'Yes' if function_set.enabled else 'No'

        return [function_set.id, function_set.name, function_set.source_entitytype().name,
                function_set.source_granularity(), "->", function_set.dest_trendstore.entitytype.name,
                function_set.dest_trendstore.granularity, enabled]

    rows = map(make_table_row, function_sets)

    column_names = ["id", "name", "src entitytype", "src granularity", "->",
            "dest entitytype", "dest granularity", "enabled"]
    column_align = "><<><<><"
    column_sizes = ["max"] * len(column_names)

    table = render_table(column_names, column_align, column_sizes, rows)

    lines = table + ["({} function sets)".format(len(function_sets))]

    return "\n".join(lines)