Commit 5d9c8d25 authored by Daniel Friesel's avatar Daniel Friesel
Browse files

add --skip option

parent 3ba277bb
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -158,7 +158,8 @@ class DLogChannel:


class DLog:
    def __init__(self, filename, limit=None):
    def __init__(self, filename, skip=None, limit=None):
        self.skip_duration = skip
        self.limit_duration = limit
        self.load_dlog(filename)

@@ -205,6 +206,18 @@ class DLog:
            0, self.observed_duration, num=int(len(raw_data) / (4 * num_channels))
        )

        if (
            self.skip_duration is not None
            and self.observed_duration >= self.skip_duration
        ):
            start_offset = 0
            for i, ts in enumerate(self.timestamps):
                if ts >= self.skip_duration:
                    start_offset = i
                    break
            self.timestamps = self.timestamps[start_offset:]
            raw_data = raw_data[start_offset * 4 * num_channels :]

        if (
            self.limit_duration is not None
            and self.observed_duration > self.limit_duration
@@ -471,6 +484,13 @@ def main():
        type=str,
        help="Export analysis results (e.g. changepoints) to JSON file",
    )
    parser.add_argument(
        "--skip",
        metavar="N",
        type=int,
        default=0,
        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",
        type=float,
@@ -494,7 +514,7 @@ def main():

    args = parser.parse_args()

    dlog = DLog(args.dlog_file, args.limit)
    dlog = DLog(args.dlog_file, args.skip, args.limit)

    if args.stat:
        print_stats(dlog)