Esempio n. 1
0
 def test_render_html_table(self):
     assert (html_table([[
         1, 2
     ]]).__html__() == '<table><tr><td>1</td><td>2</td></tr></table>')
     assert (html_table([[1, 2]], columns=[
         'a', 'b'
     ]).__html__() == '<table><thead><tr><th>a</th><th>b</th></tr></thead>'
             '<tbody><tr><td>1</td><td>2</td></tr></tbody></table>')
Esempio n. 2
0
def render_dataframe(df,
                     index=False,
                     *,
                     datatable=False,
                     class_=(),
                     col_display=None,
                     **kwargs):
    """
    Convert a Pandas dataframe to a hyperpython structure.

    Args:
        df (DataFrame):
            Input data frame.
        col_display (map):
            An optional mapping from column names in a dataframe to their
            corresponding human friendly counterparts.
        datatable (bool):
            If True, prepare data to be handled by the Data table js library.

    Additional attributes (such as class, id, etc) can be passed as keyword
    arguments.
    """
    if datatable:
        class_ = [*class_, 'display', 'cell-border', 'compact']

    data = np.array(df.astype(object))
    columns = df.columns

    if index:
        data = np.hstack([df.index[:, None], df])
        columns = [df.index.name or '', *columns]

    columns = as_display_values(columns, col_display)
    return html_table(data, columns=columns, class_=class_, **kwargs)
Esempio n. 3
0
def render_dataframe(df, index=False, *, col_display=None, **kwargs):
    """
    Convert a Pandas dataframe to a hyperpython structure.

    Args:
        df (DataFrame):
            Input data frame.
        col_display (map):
            An optional mapping from column names in a dataframe to their
            corresponding human friendly counterparts.
        index (bool):
            If given, add index as the first column.

    Additional attributes (such as class, id, etc) can be passed as keyword
    arguments.
    """
    data = np.array(df.astype(object))
    columns = df.columns

    if index:
        data = np.hstack([df.index[:, None], df])
        columns = [df.index.name or "index", *columns]

    if col_display:
        columns = [col_display.get(x, x) for x in columns]
    return html_table(data, columns=columns, style="width: 100%", **kwargs)
Esempio n. 4
0
def votes_table(comments):
    if comments:
        data = [
            [i, comment, vote_options(comment)]
            for i, comment in enumerate(comments, 1)
        ]
        return html_table(data, columns=['', _('Comment'), _('Options')], class_='table')
    else:
        return None
Esempio n. 5
0
def cluster_info(cluster):
    stereotypes = cluster.stereotypes.all()
    user_data = [(user.username, user.name) for user in cluster.users.all()]
    return {
        'size':
        cluster.users.count(),
        'stereotypes':
        stereotypes,
        'stereotype_links': [
            a(str(stereotype),
              href=reverse('cluster:stereotype-vote',
                           kwargs={
                               'conversation': cluster.conversation,
                               'stereotype': stereotype,
                           })) for stereotype in stereotypes
        ],
        'users':
        html_table(user_data, columns=[_('Username'), _('Name')])
    }
Esempio n. 6
0
def map_to_html_table(cols):
    array = map_to_table(cols)
    cols, body = array
    cols = [__(col) for col in cols]
    return html_table([body], columns=cols, class_='ReportTable table')
Esempio n. 7
0
def map_to_table(data):
    array = np.array(list(data.items())).T
    cols, body = array
    return html_table([body], columns=[__(col) for col in cols], class_='ReportTable')