mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-21 03:52:08 +08:00
zookeeper: add avg power to power_monitor.py
old-commit-hash: a27d242e3d
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
|
||||
from common.realtime import Ratekeeper
|
||||
from common.filter_simple import FirstOrderFilter
|
||||
@@ -19,12 +20,19 @@ if __name__ == "__main__":
|
||||
rk = Ratekeeper(rate, print_delay_threshold=None)
|
||||
fltr = FirstOrderFilter(0, 5, 1. / rate, initialized=False)
|
||||
|
||||
measurements = []
|
||||
start_time = time.monotonic()
|
||||
|
||||
try:
|
||||
start_time = time.monotonic()
|
||||
while duration is None or time.monotonic() - start_time < duration:
|
||||
fltr.update(z.read_power())
|
||||
if rk.frame % rate == 0:
|
||||
print(f"{fltr.x:.2f} W")
|
||||
measurements.append(fltr.x)
|
||||
rk.keep_time()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
t = datetime.timedelta(seconds=time.monotonic() - start_time)
|
||||
avg = sum(measurements) / len(measurements)
|
||||
print(f"\nAverage power: {avg:.2f}W over {t}")
|
||||
|
||||
Reference in New Issue
Block a user