Exemplo n.º 1
0
def render_desc_info(q: Q, selected_row_index: Optional[int]):
    churn_rate = churn_predictor.get_churn_rate(selected_row_index)
    q.page['churn_rate'] = ui.tall_gauge_stat_card(
        box='top-stats',
        title='Churn Rate'
        if selected_row_index else 'Average Churn Prediction',
        value=
        '={{intl churn minimum_fraction_digits=2 maximum_fraction_digits=2}}%',
        aux_value='',
        progress=churn_rate / 100,
        plot_color=q.client.secondary_color,
        data=dict(churn=churn_rate))

    total_charges = df['Total Charges']
    charge = total_charges[
        selected_row_index] if selected_row_index is not None else total_charges.mean(
            axis=0)
    rank = df['Total Charges'].rank(
        pct=True
    ).values[selected_row_index] if selected_row_index is not None else df[
        'Total Charges'].rank(pct=True).mean(axis=0)
    q.page['total_charges'] = ui.tall_gauge_stat_card(
        box='top-stats',
        title='Total Charges'
        if selected_row_index else 'Average Total Charges',
        value=
        "=${{intl charge minimum_fraction_digits=2 maximum_fraction_digits=2}}",
        aux_value=
        '={{intl rank style="percent" minimum_fraction_digits=0 maximum_fraction_digits=0}}',
        plot_color=q.client.secondary_color,
        progress=rank,
        data=dict(charge=charge, rank=rank),
    )
Exemplo n.º 2
0
def get_objects(n_callcenters):
    ''' Returns a mapping from names to objects representing the cards used in the ui '''
    n_categories = 3

    objects = dict()

    objects['outcomes'] = ui.plot_card(box='1 1 12 5',
                                       title='Outcomes by Call Center',
                                       data=data('country callcenter count',
                                                 n_callcenters * n_categories),
                                       plot=ui.plot([
                                           ui.mark(type='interval',
                                                   x='=callcenter',
                                                   y='=count',
                                                   color='=country',
                                                   stack='auto',
                                                   y_min=0)
                                       ]))

    for i in range(n_callcenters):
        col = (i % 12) + 1
        row = (i // 12) * 2 + 6
        objects[f'utilcc{i}'] = ui.tall_gauge_stat_card(
            box=f'{col} {row} 1 2',
            title=f'CC {i:02d} util.',
            value=
            '={{intl perc style="percent" minimum_fraction_digits=2 maximum_fraction_digits=2}}',
            aux_value='',
            plot_color='$green',
            progress=0,
            data=dict(perc=0))
    return objects
Exemplo n.º 3
0
def add_gauge_card(box, key, value):
    return ui.tall_gauge_stat_card(
        box=box,
        title=key,
        value=
        '={{intl value minimum_fraction_digits=2 maximum_fraction_digits=2}}',
        aux_value='',
        plot_color='$red',
        progress=value,
        data=dict(value=value),
    )
Exemplo n.º 4
0
def tall_stat_card_dollars(df, cust_id, x_variable, box, company_color):

    df = df.copy()
    df["rank"] = df[x_variable].rank(pct=True)
    cust = df[df["Phone_No"] == cust_id]

    card = ui.tall_gauge_stat_card(
        box=box,
        title=x_variable,
        value="=${{intl charge minimum_fraction_digits=2 maximum_fraction_digits=2}}",
        aux_value='={{intl rank style="percent" minimum_fraction_digits=0 maximum_fraction_digits=0}}',
        plot_color=company_color,
        progress=df["rank"].values[0],
        data=dict(charge=cust[x_variable].values[0], rank=df["rank"].values[0]),
    )
    return card
Exemplo n.º 5
0
async def show_grey_dashboard(q: Q):
    q.page['meta'] = ui.meta_card(box='', layouts=[
        ui.layout(
            breakpoint='xl',
            min_width='800px',
            zones=[
                ui.zone('header', size='0'),
                ui.zone('body', size='1000px', zones=[
                    ui.zone('title', size='0'),
                    ui.zone('top', direction=ui.ZoneDirection.ROW, size='25%'),
                    ui.zone('middle', direction=ui.ZoneDirection.ROW, size='25%'),
                    ui.zone('middle2', direction=ui.ZoneDirection.ROW, size='25%'),
                    ui.zone('bottom', direction=ui.ZoneDirection.ROW, size='20%'),
                ]),
                ui.zone('footer', size='0'),
            ]
        )
    ])

    q.page['header'] = ui.header_card(box='header', title='H2O Wave Demo', subtitle='Grey Dashboard',
                                      nav=global_nav)
    q.page['section'] = ui.section_card(
        box='title',
        title=next(sample_title),
        subtitle=next(sample_caption),
        items=[
            ui.label(label='Start:'),
            ui.date_picker(name='target_date', label='', value='2020-12-20'),
            ui.label(label='End:'),
            ui.date_picker(name='target_date', label='', value='2020-12-25'),
        ],
    )

    stock_dates = generate_time_series(10000)
    stock_prices = generate_random_walk()

    q.page['small'] = ui.small_stat_card(
        box=ui.box('top', order=1),
        title=next(sample_term),
        value=next(sample_dollars),
    )
    q.page['small_series'] = ui.small_series_stat_card(
        box=ui.box('top', order=2),
        title=next(sample_term),
        value=next(sample_dollars),
        plot_category='date',
        plot_value='price',
        plot_data=data(
            fields=['date', 'price'],
            rows=[(next(stock_dates), next(stock_prices)) for i in range(30)],
            pack=True,
        ),
    )
    q.page['small_series_interval'] = ui.small_series_stat_card(
        box=ui.box('top', order=3),
        title=next(sample_term),
        value=next(sample_dollars),
        plot_category='date',
        plot_value='price',
        plot_type=ui.SmallSeriesStatCardPlotType.INTERVAL,
        plot_data=data(
            fields=['date', 'price'],
            rows=[(next(stock_dates), next(stock_prices)) for i in range(30)],
            pack=True,
        ),
    )
    q.page['wide_series'] = ui.wide_series_stat_card(
        box=ui.box('middle', order=1),
        title=next(sample_term),
        value=next(sample_dollars),
        aux_value=next(sample_percent),
        plot_category='date',
        plot_value='price',
        plot_data=data(
            fields=['date', 'price'],
            rows=[(next(stock_dates), next(stock_prices)) for i in range(30)],
            pack=True,
        ),
    )
    q.page['wide_bar'] = ui.wide_bar_stat_card(
        box=ui.box('middle', order=2),
        title=next(sample_term),
        value=next(sample_dollars),
        aux_value=next(sample_percent),
        progress=random.random(),
    )
    q.page['wide_gauge'] = ui.wide_gauge_stat_card(
        box=ui.box('middle', order=3),
        title=next(sample_term),
        value=next(sample_dollars),
        aux_value=next(sample_percent),
        progress=random.random(),
    )
    q.page['tall_series'] = ui.tall_series_stat_card(
        box=ui.box('middle2', order=1),
        title=next(sample_term),
        value=next(sample_dollars),
        aux_value=next(sample_percent),
        plot_category='date',
        plot_value='price',
        plot_data=data(
            fields=['date', 'price'],
            rows=[(next(stock_dates), next(stock_prices)) for i in range(30)],
            pack=True,
        ),
    )
    q.page['tall_gauge'] = ui.tall_gauge_stat_card(
        box=ui.box('middle2', order=2),
        title=next(sample_term),
        value=next(sample_dollars),
        aux_value=next(sample_percent),
        progress=random.random(),
    )
    q.page['large'] = ui.large_stat_card(
        box=ui.box('bottom', order=1),
        title=next(sample_term),
        value=next(sample_dollars),
        aux_value=next(sample_percent),
        caption=next(sample_caption),
    )
    q.page['large_bar'] = ui.large_bar_stat_card(
        box=ui.box('bottom', order=2),
        title=next(sample_term),
        value=next(sample_dollars),
        value_caption=next(sample_term),
        aux_value=next(sample_dollars),
        aux_value_caption=next(sample_term),
        progress=random.random(),
        caption=next(sample_caption),
    )

    q.page['footer'] = ui.footer_card(box='footer', caption='(c) 2021 H2O.ai. All rights reserved.')

    await q.page.save()
Exemplo n.º 6
0
def create_dashboard(update_freq=0.0):
    page = site['/demo']

    simples = []
    for i in range(1, 7):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'a{i}',
            ui.small_stat_card(
                box=f'{i} 1 1 1',
                title=fake.cryptocurrency_name(),
                value=f'${val:.2f}',
            ))
        simples.append((f, c))

    simples_colored = []
    for i in range(1, 7):
        f = FakeCategoricalSeries()
        cat, val, pc = f.next()
        c = page.add(
            f'aa{i}',
            ui.small_series_stat_card(
                box=f'{6 + i} 1 1 1',
                title=fake.cryptocurrency_code(),
                value=
                '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                data=dict(qux=val, quux=pc / 100),
                plot_category='foo',
                plot_value='qux',
                plot_color=next_color(),
                plot_data=data('foo qux', -15),
                plot_zero_value=0,
                plot_curve=next_curve(),
            ))
        simples_colored.append((f, c))

    lines = []
    for i in range(1, 13, 2):
        f = FakeCategoricalSeries()
        cat, val, pc = f.next()
        c = page.add(
            f'b{i}',
            ui.wide_series_stat_card(
                box=f'{i} 2 2 1',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl quux style="percent" minimum_fraction_digits=1 maximum_fraction_digits=1}}',
                data=dict(qux=val, quux=pc / 100),
                plot_category='foo',
                plot_value='qux',
                plot_color=next_color(),
                plot_data=data('foo qux', -15),
                plot_zero_value=0,
                plot_curve=next_curve(),
            ))
        lines.append((f, c))

    bars = []
    for i in range(1, 13, 2):
        f = FakeCategoricalSeries()
        cat, val, pc = f.next()
        c = page.add(
            f'c{i}',
            ui.wide_series_stat_card(
                box=f'{i} 3 2 1',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl quux style="percent" minimum_fraction_digits=1 maximum_fraction_digits=1}}',
                data=dict(qux=val, quux=pc),
                plot_type='interval',
                plot_category='foo',
                plot_value='qux',
                plot_color=next_color(),
                plot_data=data('foo qux', -25),
                plot_zero_value=0))
        bars.append((f, c))

    large_pcs = []
    for i in range(1, 13):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'd{i}',
            ui.tall_gauge_stat_card(
                box=f'{i} 4 1 2',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl foo minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl bar style="percent" minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                plot_color=next_color(),
                progress=pc,
                data=dict(foo=val, bar=pc / 100),
            ))
        large_pcs.append((f, c))

    large_lines = []
    for i in range(1, 13):
        f = FakeCategoricalSeries()
        cat, val, pc = f.next()
        c = page.add(
            f'e{i}',
            ui.tall_series_stat_card(
                box=f'{i} 6 1 2',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl quux style="percent" minimum_fraction_digits=1 maximum_fraction_digits=1}}',
                data=dict(qux=val, quux=pc),
                plot_type='area',
                plot_category='foo',
                plot_value='qux',
                plot_color=next_color(),
                plot_data=data('foo qux', -15),
                plot_zero_value=0,
                plot_curve=next_curve(),
            ))
        large_lines.append((f, c))

    small_pcs = []
    for i in range(1, 7, 2):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'f{i}',
            ui.wide_gauge_stat_card(
                box=f'{i} 8 2 1',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl foo minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl bar style="percent" minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                plot_color=next_color(),
                progress=pc,
                data=dict(foo=val, bar=pc / 100),
            ))
        small_pcs.append((f, c))

    small_pbs = []
    for i in range(7, 13, 2):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'f{i}',
            ui.wide_bar_stat_card(
                box=f'{i} 8 2 1',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl foo minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl bar style="percent" minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                plot_color=next_color(),
                progress=pc,
                data=dict(foo=val, bar=pc / 100),
            ))
        small_pbs.append((f, c))

    large_cards = []
    for i in range(1, 7, 2):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'g{i}',
            ui.large_stat_card(
                box=f'{i} 9 2 2',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl qux minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value=
                '={{intl quux style="percent" minimum_fraction_digits=1 maximum_fraction_digits=1}}',
                data=dict(qux=val, quux=pc / 100),
                caption=' '.join(fake.sentences()),
            ))
        large_cards.append((f, c))

    large_pbs = []
    for i in range(7, 13, 2):
        f = FakePercent()
        val, pc = f.next()
        c = page.add(
            f'g{i}',
            ui.large_bar_stat_card(
                box=f'{i} 9 2 2',
                title=fake.cryptocurrency_name(),
                value=
                '=${{intl foo minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                value_caption='This Month',
                aux_value=
                '={{intl bar style="percent" minimum_fraction_digits=2 maximum_fraction_digits=2}}',
                aux_value_caption='Previous Month',
                plot_color=next_color(),
                progress=pc,
                data=dict(foo=val, bar=pc / 100),
                caption=' '.join(fake.sentences(2)),
            ))
        large_pbs.append((f, c))

    page.save()

    while update_freq > 0:
        time.sleep(update_freq)

        for f, c in simples:
            val, pc = f.next()
            c.value = f'${val:.2f}',

        for f, c in simples_colored:
            cat, val, pc = f.next()
            c.data.qux = val
            c.data.quux = pc / 100
            c.plot_data[-1] = [cat, val]

        for f, c in lines:
            cat, val, pc = f.next()
            c.data.qux = val
            c.data.quux = pc / 100
            c.plot_data[-1] = [cat, val]

        for f, c in bars:
            cat, val, pc = f.next()
            c.data.qux = val
            c.data.quux = pc / 100
            c.plot_data[-1] = [cat, val]

        for f, c in large_lines:
            cat, val, pc = f.next()
            c.data.qux = val
            c.data.quux = pc / 100
            c.plot_data[-1] = [cat, val]

        for f, c in large_pcs:
            val, pc = f.next()
            c.data.foo = val
            c.data.bar = pc
            c.progress = pc

        for f, c in small_pcs:
            val, pc = f.next()
            c.data.foo = val
            c.data.bar = pc
            c.progress = pc

        for f, c in small_pbs:
            val, pc = f.next()
            c.data.foo = val
            c.data.bar = pc
            c.progress = pc

        for f, c in large_cards:
            val, pc = f.next()
            c.data.qux = val
            c.data.quux = pc

        for f, c in large_pbs:
            val, pc = f.next()
            c.data.foo = val
            c.data.bar = pc
            c.progress = pc

        page.save()
Exemplo n.º 7
0
import time

from faker import Faker

from synth import FakePercent
from h2o_wave import site, ui

page = site['/demo']

fake = Faker()
f = FakePercent()
val, pc = f.next()
c = page.add(f'example', ui.tall_gauge_stat_card(
    box='1 1 1 2',
    title=fake.cryptocurrency_name(),
    value='=${{intl foo minimum_fraction_digits=2 maximum_fraction_digits=2}}',
    aux_value='={{intl bar style="percent" minimum_fraction_digits=2 maximum_fraction_digits=2}}',
    plot_color='$red',
    progress=pc,
    data=dict(foo=val, bar=pc),
))
page.save()

while True:
    time.sleep(1)
    val, pc = f.next()
    c.data.foo = val
    c.data.bar = pc
    c.progress = pc
    page.save()