From ffed53f80fc9cd6441496a16b58bc627bb24b270 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 29 Oct 2020 08:56:47 +0100 Subject: --skip: use seconds instead of raw samples --- bin/msp430-etv | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/bin/msp430-etv b/bin/msp430-etv index 424a077..51c9013 100755 --- a/bin/msp430-etv +++ b/bin/msp430-etv @@ -252,10 +252,10 @@ def main(): ) parser.add_argument( "--skip", - metavar="COUNT", + metavar="N", type=int, default=0, - help="Skip COUNT data samples. This is useful to avoid startup code influencing the results of a long-running measurement", + help="Skip the first N seconds of data. This is useful to avoid startup code influencing the results of a long-running measurement", ) parser.add_argument( "--limit", @@ -324,14 +324,13 @@ def main(): data_count = sum(map(lambda x: len(x) > 0 and x[0] != "#", lines)) data_lines = filter(lambda x: len(x) > 0 and x[0] != "#", lines) - data = np.empty((data_count - args.skip, 4)) + data = np.empty((data_count, 4)) + skip_offset = 0 + limit_index = data_count energy_overflow_count = 0 prev_total_energy = 0 for i, line in enumerate(data_lines): - if i < args.skip: - continue - fields = line.split(" ") if len(fields) == 4: timestamp, current, voltage, total_energy = map(int, fields) @@ -345,14 +344,17 @@ def main(): prev_total_energy = total_energy total_energy += energy_overflow_count * (2 ** 32) + if args.skip is not None and timestamp * 1e-6 < args.skip: + skip_offset = i + 1 + continue + if args.limit is not None and timestamp * 1e-6 > args.limit: - final_index = i - args.skip - 1 + limit_index = i - 1 break - data[i - args.skip] = [timestamp, current, voltage, total_energy] + data[i] = [timestamp, current, voltage, total_energy] - if args.limit is not None: - data = data[:final_index] + data = data[skip_offset:limit_index] m_duration_us = data[-1, 0] - data[0, 0] m_energy_nj = data[-1, 3] - data[0, 3] -- cgit v1.2.3