def __init__(self,
                 thread_num,
                 max_value,
                 cards_manager: CardsManager,
                 max_boxes_in_line=10,
                 width=2,
                 height=1):
        super(ThreadBarCard, self).__init__(thread_num, max_boxes_in_line,
                                            width, height, cards_manager)
        self.max_value = max_value

        self.card = self.cards_manager.page.add(
            f'thread_{thread_num}_bar',
            ui.wide_bar_stat_card(
                box=self.gen_box(),
                title=f'Thread #{thread_num}',
                value='={{value}}',
                aux_value='={{pc}}%',
                plot_color='$green',
                progress=0,
                data={
                    'value': 0,
                    'pc': 0
                },
            ))
    def __init__(self,
                 thread_num,
                 max_value,
                 cards_manager: CardsManager,
                 buffer_rows=15,
                 expected_value=None,
                 max_boxes_in_line=10):
        super(ThreadPairCard,
              self).__init__(thread_num,
                             width=2,
                             height=3,
                             max_boxes_in_line=max_boxes_in_line,
                             cards_manager=cards_manager)
        self.max_value = max_value
        self.expected_value = expected_value
        box_1 = self.gen_box()
        box_1_list = [int(i) for i in box_1.split()]
        box_2 = f'{box_1_list[0]} {box_1_list[1] + 1} {box_1_list[2]} {box_1_list[3]}'

        self.series_card = self.cards_manager.page.add(
            f'thread_{thread_num}_series_paired',
            ui.wide_series_stat_card(box=box_1,
                                     title=f'Thread #{thread_num}',
                                     value='={{iter_sec}}',
                                     aux_value='',
                                     data=dict(iter_sec=0.0),
                                     plot_data=data('tick usage',
                                                    -buffer_rows),
                                     plot_category='tick',
                                     plot_value='usage',
                                     plot_zero_value=0,
                                     plot_color='$green',
                                     plot_curve='smooth'))
        self.series_card.data.iter_sec = "No data"

        self.bar_card = self.cards_manager.page.add(
            f'thread_{thread_num}_bar_paired',
            ui.wide_bar_stat_card(
                box=box_2,
                title=f'Thread #{thread_num}',
                value='={{value}}',
                aux_value='={{pc}}%',
                plot_color='$green',
                progress=0,
                data={
                    'value': 0,
                    'pc': 0
                },
            ))
Exemple #3
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()
Exemple #4
0
async def show_cyan_dashboard(q: Q):
    q.page['meta'] = ui.meta_card(box='', layouts=[
        ui.layout(
            breakpoint='xl',
            width='1200px',
            zones=[
                ui.zone('header', size='0'),
                ui.zone('body', direction=ui.ZoneDirection.ROW, zones=[
                    ui.zone('content', size='75%', zones=[
                        ui.zone('top', size='600px'),
                        ui.zone('middle', size='300px', direction=ui.ZoneDirection.ROW, zones=[
                            ui.zone('middle_left'),
                            ui.zone('middle_right'),
                        ]),
                        ui.zone('bottom', size='500px'),
                    ]),
                    ui.zone('sidebar', size='25%'),
                ]),
                ui.zone('footer', size='0'),
            ]
        )
    ])

    q.page['header'] = ui.header_card(box='header', title='H2O Wave Demo', subtitle='Cyan Dashboard',
                                      nav=global_nav)
    q.page['section'] = ui.section_card(
        box=ui.box('top', order=1, size=0),
        title=next(sample_title),
        subtitle=next(sample_caption),
        items=[
            ui.toggle(name='when', label=next(sample_term), value=False),
            ui.toggle(name='what', label=next(sample_term), value=True),
        ]
    )

    trend_date = generate_time_series(300)
    trend_price = generate_random_walk(2000, 8000, 0.2)
    q.page['sales_overview'] = ui.form_card(
        box=ui.box('top', order=2),
        title=next(sample_title),
        items=[
            ui.stats(items=[
                ui.stat(label=next(sample_term), value=next(sample_percent), caption=next(sample_dollars)),
                ui.stat(label=next(sample_term), value=next(sample_dollars), caption=next(sample_percent)),
                ui.stat(label=next(sample_term), value=next(sample_amount), caption=next(sample_percent)),
                ui.stat(label=next(sample_term), caption=next(sample_caption)),
            ], inset=True),
            ui.visualization(
                plot=ui.plot([
                    ui.mark(type='area', x_scale='time', x='=date', y='=price', color='$cyan'),
                ]),
                data=data(
                    fields=['date', 'price'],
                    rows=[(next(trend_date), next(trend_price)) for i in range(120)],
                    pack=True
                ),
                height='350px',
            ),
        ],
    )

    q.page['ticket_sales'] = ui.form_card(
        box=ui.box('middle_left'),
        title=next(sample_title),
        items=[
            ui.visualization(
                plot=ui.plot([
                    ui.mark(type='interval', x_scale='time', x='=date', y='=price', color='$cyan'),
                ]),
                data=data(
                    fields=['date', 'price'],
                    rows=[(next(trend_date), next(trend_price)) for i in range(120)],
                    pack=True
                ),
                height='150px',
            ),
            ui.stats(items=[
                ui.stat(label=next(sample_term), value=next(sample_percent)) for i in range(4)
            ], justify='between', inset=True),
        ],
    )
    q.page['events_hosted'] = ui.wide_bar_stat_card(
        box=ui.box('middle_right', order=1),
        title=next(sample_title),
        value=next(sample_dollars),
        aux_value=next(sample_percent),
        progress=random.random(),
        plot_color='$cyan',
    )
    q.page['points_earned'] = ui.wide_bar_stat_card(
        box=ui.box('middle_right', order=2),
        title=next(sample_title),
        value=next(sample_amount),
        aux_value=next(sample_percent),
        progress=random.random(),
        plot_color='$cyan',
    )
    q.page['points_given'] = ui.wide_bar_stat_card(
        box=ui.box('middle_right', order=3),
        title=next(sample_title),
        value=next(sample_dollars),
        aux_value=next(sample_percent),
        progress=random.random(),
        plot_color='$cyan',
    )
    session_count = generate_random_walk(1000, 8000)
    q.page['event_poll'] = ui.form_card(
        box='bottom',
        title=next(sample_title),
        items=[
            ui.inline(items=[
                ui.dropdown(name='region', label=next(sample_term), value='option0', choices=[
                    ui.choice(name=f'option{i}', label=next(sample_term)) for i in range(5)
                ]),
                ui.dropdown(name='age', label=next(sample_term), value='option0', choices=[
                    ui.choice(name=f'option{i}', label=next(sample_term)) for i in range(5)
                ]),
                ui.dropdown(name='response', label=next(sample_term), value='option0', choices=[
                    ui.choice(name=f'option{i}', label=next(sample_term)) for i in range(5)
                ]),
            ]),
            ui.visualization(
                plot=ui.plot([
                    ui.mark(type='interval', x='=sessions', y='=channel', y_min=0, color='$cyan')
                ]),
                data=data(
                    fields=['channel', 'sessions'],
                    rows=[(next(sample_term), next(session_count)) for i in range(10)],
                    pack=True,
                ),
                height='350px',
            ),
        ],

    )
    q.page['sidebar_section'] = ui.section_card(
        box=ui.box('sidebar', order=1, size='0'),
        title=next(sample_title),
        subtitle=next(sample_caption),
    )
    q.page['filter'] = ui.form_card(
        box=ui.box('sidebar', height='335px', order=2),
        title=next(sample_title),
        items=[
            ui.dropdown(name='region', label=next(sample_term), value='option0', choices=[
                ui.choice(name=f'option{i}', label=next(sample_term)) for i in range(5)
            ]),
            ui.dropdown(name='age', label=next(sample_term), value='option0', choices=[
                ui.choice(name=f'option{i}', label=next(sample_term)) for i in range(5)
            ]),
            ui.dropdown(name='response', label=next(sample_term), value='option0', choices=[
                ui.choice(name=f'option{i}', label=next(sample_term)) for i in range(5)
            ]),
            ui.checkbox(name='plural', label=next(sample_title), value=True),
            ui.checkbox(name='annual', label=next(sample_title), value=True),
        ],
    )

    event_icon = generate_random_choice(['MusicInCollection', 'Video', 'TVMonitor'])

    q.page['upcoming_events'] = ui.stat_list_card(
        box=ui.box('sidebar', order=3),
        title=next(sample_title),
        subtitle=next(sample_caption),
        items=[ui.stat_list_item(label=next(sample_title), caption=next(sample_caption),
                                 aux_value=f'{random.randint(1, 59)}m',
                                 icon=next(event_icon)) for i in range(10)],
    )

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

    await q.page.save()
Exemple #5
0
from synth import FakePercent
from h2o_wave import site, ui

page = site['/demo']

fake = Faker()
f = FakePercent()
val, pc = f.next()
c = page.add(
    'example',
    ui.wide_bar_stat_card(
        box='1 1 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='$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()
Exemple #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()