status-lib/status/signals/stats.nim

23 lines
538 B
Nim
Raw Permalink Normal View History

2021-09-08 18:05:39 +00:00
import json
import base
2021-09-08 20:55:37 +00:00
import signal_type
2021-09-08 18:05:39 +00:00
type Stats* = object
uploadRate*: uint64
downloadRate*: uint64
type StatsSignal* = ref object of Signal
stats*: Stats
proc toStats(jsonMsg: JsonNode): Stats =
result = Stats(
uploadRate: uint64(jsonMsg{"uploadRate"}.getBiggestInt()),
downloadRate: uint64(jsonMsg{"downloadRate"}.getBiggestInt())
)
2021-09-08 20:55:37 +00:00
proc fromEvent*(T: type StatsSignal, event: JsonNode): StatsSignal =
result = StatsSignal()
result.signalType = SignalType.Stats
result.stats = event["event"].toStats