From b76897d8f8f7058a6f15f063f2f300787197570a Mon Sep 17 00:00:00 2001 From: Steffen Date: Mon, 23 Nov 2026 00:01:07 +0100 Subject: [PATCH] Calculate energy from recorded power samples --- tools/energy-jmeter/README.md | 2 +- tools/energy-jmeter/energy.py | 19 +++++++++---------- tools/energy-jmeter/shelly.py | 8 ++++++-- tools/energy-jmeter/verify-shelly.py | 8 ++++++++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/tools/energy-jmeter/README.md b/tools/energy-jmeter/README.md index e030cab..354f7b4 100644 --- a/tools/energy-jmeter/README.md +++ b/tools/energy-jmeter/README.md @@ -90,7 +90,7 @@ Meter requests are excluded from the application's request-rate and latency summ JMeter's overall console summary includes meter polls; use `run.json` and `measured.csv` for the application-only figures. -Power integration uses trapezoids. Counter deltas provide a separate cross-check; +Energy from sampled power is the sum of the recorded in-window power values, each multiplied by the nominal polling interval. This assumes each reading represents that interval; actual polling timestamps may differ and sample coverage is reported. Counter deltas provide a separate cross-check; the device's counter update granularity can make short runs report little or no counter change despite nonzero power. Both boundary interpolation and meter accuracy limit precision; this does not claim calibration. The plug measures what is connected diff --git a/tools/energy-jmeter/energy.py b/tools/energy-jmeter/energy.py index 40f7714..a6dc960 100644 --- a/tools/energy-jmeter/energy.py +++ b/tools/energy-jmeter/energy.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 -"""Integrate timestamped external power readings over the exact measurement window.""" +"""Sum timestamped external power readings at the nominal polling interval.""" import argparse, csv, datetime as dt, json from pathlib import Path -p=argparse.ArgumentParser();p.add_argument('run');p.add_argument('power_csv');p.add_argument('--idle-watts',type=float);a=p.parse_args() +p=argparse.ArgumentParser();p.add_argument('run');p.add_argument('power_csv');p.add_argument('--idle-watts',type=float);p.add_argument('--interval-seconds',type=float,default=1);a=p.parse_args() run=json.loads(Path(a.run).read_text());start=run['measurement_start_ms']/1000;end=run['measurement_end_ms']/1000 points=[] with open(a.power_csv) as f: @@ -14,14 +14,13 @@ with open(a.power_csv) as f: points.append((instant.timestamp(),watts)) if len(points)<2 or any(b[0]<=a[0] for a,b in zip(points,points[1:])):p.error('Power timestamps must be strictly increasing') if points[0][0]>start or points[-1][0]