File size: 8,765 Bytes
2b4d75c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# Dashboard
# Make a #dashboard using a multitude of cards and update them live.
# ---
from faker import Faker
import time
from h2o_wave import site, data, ui
from synth import FakePercent, FakeCategoricalSeries
fake = Faker()
light_theme_colors = '$red $pink $purple $violet $indigo $blue $azure $cyan $teal $mint $green $amber $orange $tangerine'.split() # noqa: E501
dark_theme_colors = '$red $pink $blue $azure $cyan $teal $mint $green $lime $yellow $amber $orange $tangerine'.split()
_color_index = -1
colors = dark_theme_colors
def next_color():
global _color_index
_color_index += 1
return colors[_color_index % len(colors)]
_curve_index = -1
curves = 'linear smooth step step-after step-before'.split()
def next_curve():
global _curve_index
_curve_index += 1
return curves[_curve_index % len(curves)]
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()
create_dashboard(update_freq=0.25)
|