dreamstack/examples/streaming-stats.ds

31 lines
789 B
Text
Raw Normal View History

-- DreamStack Streaming Stats
-- Tracks button presses and computes statistics.
-- Only total, average, max are exposed (sum and last_sample are internal).
--
-- Run with:
-- dreamstack stream examples/streaming-stats.ds --port 3003
let total = 0
let max = 0
let sum = 0
let average = sum / (total + 1)
stream stats on "ws://localhost:9100/peer/stats" {
mode: signal,
output: total, average, max
}
view stats =
column [
text "📊 Streaming Stats"
text "Samples: {total}"
text "Average: {average}"
text "Max: {max}"
row [
button "+5" { click: total += 1; sum += 5 }
button "+10" { click: total += 1; sum += 10 }
button "+25" { click: total += 1; sum += 25; max = 25 }
button "+50" { click: total += 1; sum += 50; max = 50 }
]
]