Commit ffed53f8 authored by Daniel Friesel's avatar Daniel Friesel
Browse files

--skip: use seconds instead of raw samples

parent a9c77c35
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -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]