def __init__(self,
                 thread_num,
                 cards_manager,
                 buffer_rows=15,
                 expected_value=None,
                 max_boxes_in_line=10,
                 width=2,
                 height=1):
        super(ThreadSeriesCard, self).__init__(thread_num, max_boxes_in_line,
                                               width, height, cards_manager)
        self.expected_value = expected_value

        self.card = cards_manager.page.add(
            f'thread_{thread_num}_series',
            ui.wide_series_stat_card(box=self.gen_box(),
                                     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.card.data.iter_sec = "No data"
 def __init__(self,
              cards_manager: CardsManager,
              buffer_rows=15,
              expected_value=None,
              update_period=3):
     super(GeneralCard, self).__init__(width=2, height=1)
     self.last_update = time.time()
     self.general_stats = 0.0
     self.update_period = update_period
     self.expected_value = expected_value
     self.cards_manager = cards_manager
     self.card = cards_manager.page.add(
         f'general_stats',
         ui.wide_series_stat_card(box=self.gen_box(),
                                  title=f'General',
                                  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.card.data.iter_sec = "No data"
    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
                },
            ))
Example #4
0
async def show_orange_dashboard(q: Q):
    q.page['meta'] = ui.meta_card(
        box='',
        layouts=[
            ui.layout(breakpoint='xl',
                      width='1200px',
                      zones=[
                          ui.zone('header'),
                          ui.zone('control'),
                          ui.zone('top',
                                  direction=ui.ZoneDirection.ROW,
                                  size='385px',
                                  zones=[
                                      ui.zone('top_left',
                                              direction=ui.ZoneDirection.ROW,
                                              size='66%'),
                                      ui.zone('top_right'),
                                  ]),
                          ui.zone('middle',
                                  direction=ui.ZoneDirection.ROW,
                                  size='400px'),
                          ui.zone('bottom',
                                  direction=ui.ZoneDirection.ROW,
                                  size='200px'),
                          ui.zone('footer'),
                      ])
        ])

    q.page['header'] = ui.header_card(box='header',
                                      title='H2O Wave Demo',
                                      subtitle='Orange Dashboard',
                                      nav=global_nav)

    q.page['section'] = ui.section_card(
        box='control',
        title=next(sample_title),
        subtitle=next(sample_caption),
        items=[
            ui.checkbox(name='search', label=next(sample_title), value=True),
            ui.dropdown(name='distribution',
                        label='',
                        value='option0',
                        choices=[
                            ui.choice(name=f'option{i}',
                                      label=next(sample_term))
                            for i in range(5)
                        ]),
            ui.dropdown(name='source',
                        label='',
                        value='option0',
                        choices=[
                            ui.choice(name=f'option{i}',
                                      label=next(sample_term))
                            for i in range(5)
                        ]),
            ui.dropdown(name='range',
                        label='',
                        value='option0',
                        choices=[
                            ui.choice(name=f'option{i}',
                                      label=next(sample_term))
                            for i in range(5)
                        ]),
        ],
    )

    user_days = generate_time_series(30)
    user_counts = generate_random_walk()

    q.page['unique_impressions'] = ui.tall_series_stat_card(
        box='top_left',
        title=next(sample_title),
        value=next(sample_amount),
        aux_value=next(sample_percent),
        plot_type='interval',
        plot_color='$orange',
        plot_category='date',
        plot_value='users',
        plot_zero_value=0,
        plot_data=data(
            fields=['date', 'users'],
            rows=[(next(user_days), next(user_counts)) for i in range(60)],
            pack=True,
        ),
    )

    q.page['unique_clicks'] = ui.tall_series_stat_card(
        box='top_left',
        title=next(sample_title),
        value=next(sample_dollars),
        aux_value=next(sample_title),
        plot_type='interval',
        plot_color='$amber',
        plot_category='date',
        plot_value='users',
        plot_zero_value=0,
        plot_data=data(
            fields=['date', 'users'],
            rows=[(next(user_days), next(user_counts)) for i in range(60)],
            pack=True,
        ),
    )

    q.page['popularity'] = ui.wide_series_stat_card(
        box='top_right',
        title=next(sample_term),
        value=next(sample_percent),
        aux_value=next(sample_amount),
        plot_type='area',
        plot_color='$tangerine',
        plot_category='date',
        plot_value='users',
        plot_zero_value=0,
        plot_data=data(
            fields=['date', 'users'],
            rows=[(next(user_days), next(user_counts)) for i in range(60)],
            pack=True,
        ),
    )
    q.page['search_traffic'] = ui.wide_series_stat_card(
        box='top_right',
        title=next(sample_term),
        value=next(sample_percent),
        aux_value=next(sample_dollars),
        plot_type='interval',
        plot_color='$tangerine',
        plot_category='date',
        plot_value='users',
        plot_zero_value=0,
        plot_data=data(
            fields=['date', 'users'],
            rows=[(next(user_days), next(user_counts)) for i in range(60)],
            pack=True,
        ),
    )
    q.page['social_media_traffic'] = ui.wide_series_stat_card(
        box='top_right',
        title=next(sample_title),
        value='68K',
        aux_value='Down 6%',
        plot_type='area',
        plot_color='$tangerine',
        plot_category='date',
        plot_value='users',
        plot_zero_value=0,
        plot_data=data(
            fields=['date', 'users'],
            rows=[(next(user_days), next(user_counts)) for i in range(60)],
            pack=True,
        ),
    )

    audience_days1 = generate_time_series(60)
    audience_days2 = generate_time_series(60)
    audience_hits1 = generate_random_walk(10000, 20000, 0.2)
    audience_hits2 = generate_random_walk(8000, 15000)

    q.page['stats'] = ui.form_card(
        box='middle',
        title=next(sample_title),
        items=[
            ui.stats(items=[
                ui.stat(label=next(sample_term), value=next(sample_dollars)),
                ui.stat(label=next(sample_term), value=next(sample_percent)),
                ui.stat(label=next(sample_term), value=next(sample_amount)),
                ui.stat(label=next(sample_term), value=next(sample_dollars)),
                ui.stat(label=next(sample_term), value=next(sample_percent)),
                ui.stat(label=next(sample_term), value=next(sample_amount)),
                ui.stat(label=next(sample_term), value=next(sample_dollars)),
                ui.stat(label=next(sample_term), value=next(sample_percent)),
            ],
                     justify=ui.StatsJustify.BETWEEN,
                     inset=True),
            ui.visualization(
                plot=ui.plot([
                    ui.mark(type='area',
                            x_scale='time',
                            x='=date',
                            y='=visitors',
                            color='=site',
                            color_range='$orange $amber',
                            curve=ui.MarkCurve.SMOOTH),
                    ui.mark(type='line',
                            x_scale='time',
                            x='=date',
                            y='=visitors',
                            color='=site',
                            color_range='$orange $amber',
                            curve=ui.MarkCurve.SMOOTH),
                ]),
                data=data(
                    fields=['site', 'date', 'visitors'],
                    rows=[
                        ('Online', next(audience_days1), next(audience_hits1))
                        for i in range(60)
                    ] +
                    [('In-store', next(audience_days2), next(audience_hits2))
                     for i in range(60)],
                    pack=True),
                height='240px',
            )
        ],
    )

    q.page['click_through'] = ui.large_stat_card(
        box='bottom',
        title=next(sample_title),
        value=next(sample_amount),
        aux_value=next(sample_dollars),
        caption=' '.join([next(sample_caption) for i in range(3)]),
    )

    q.page['view_through'] = ui.large_stat_card(
        box='bottom',
        title=next(sample_title),
        value=next(sample_amount),
        aux_value=next(sample_dollars),
        caption=' '.join([next(sample_caption) for i in range(3)]),
    )
    q.page['total_conversions'] = ui.large_stat_card(
        box='bottom',
        title=next(sample_title),
        value=next(sample_amount),
        aux_value=next(sample_dollars),
        caption=' '.join([next(sample_caption) for i in range(3)]),
    )

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

    await q.page.save()
Example #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()
page = site['/demo']

fake = Faker()
f = FakeCategoricalSeries()
cat, val, pc = f.next()
c = page.add(
    'example',
    ui.wide_series_stat_card(
        box='1 1 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_type='interval',
        plot_value='qux',
        plot_color='$red',
        plot_data=data('foo qux', -15),
        plot_zero_value=0,
    ))
page.save()

while True:
    time.sleep(1)
    cat, val, pc = f.next()
    c.data.qux = val
    c.data.quux = pc / 100
    c.plot_data[-1] = [cat, val]
Example #7
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()