def _get_segments_remote(self): api = CommaApi(get_token()) route_files = api.get('v1/route/' + self.name.canonical_name + '/files') self.files = list(chain.from_iterable(route_files.values())) segments = {} for url in self.files: _, dongle_id, time_str, segment_num, fn = urlparse(url).path.rsplit('/', maxsplit=4) segment_name = f'{dongle_id}|{time_str}--{segment_num}' if segments.get(segment_name): segments[segment_name] = Segment( segment_name, url if fn in LOG_FILENAMES else segments[segment_name].log_path, url if fn in QLOG_FILENAMES else segments[segment_name].qlog_path, url if fn in CAMERA_FILENAMES else segments[segment_name].camera_path, url if fn in DCAMERA_FILENAMES else segments[segment_name].dcamera_path, url if fn in ECAMERA_FILENAMES else segments[segment_name].ecamera_path, url if fn in QCAMERA_FILENAMES else segments[segment_name].qcamera_path, ) else: segments[segment_name] = Segment( segment_name, url if fn in LOG_FILENAMES else None, url if fn in QLOG_FILENAMES else None, url if fn in CAMERA_FILENAMES else None, url if fn in DCAMERA_FILENAMES else None, url if fn in ECAMERA_FILENAMES else None, url if fn in QCAMERA_FILENAMES else None, ) return sorted(segments.values(), key=lambda seg: seg.name.segment_num)
def juggle_route(route_or_segment_name, segment_count, qlog, can, layout): segment_start = 0 if 'cabana' in route_or_segment_name: query = parse_qs(urlparse(route_or_segment_name).query) api = CommaApi(get_token()) logs = api.get( f'v1/route/{query["route"][0]}/log_urls?sig={query["sig"][0]}&exp={query["exp"][0]}' ) elif route_or_segment_name.startswith( "http://") or route_or_segment_name.startswith( "https://") or os.path.isfile(route_or_segment_name): logs = [route_or_segment_name] else: route_or_segment_name = SegmentName(route_or_segment_name, allow_route_name=True) segment_start = max(route_or_segment_name.segment_num, 0) if route_or_segment_name.segment_num != -1 and segment_count is None: segment_count = 1 r = Route(route_or_segment_name.route_name.canonical_name) logs = r.qlog_paths() if qlog else r.log_paths() segment_end = segment_start + segment_count if segment_count else None logs = logs[segment_start:segment_end] if None in logs: ans = input( f"{logs.count(None)}/{len(logs)} of the rlogs in this segment are missing, would you like to fall back to the qlogs? (y/n) " ) if ans == 'y': logs = r.qlog_paths()[segment_start:segment_end] else: print("Please try a different route or segment") return all_data = [] with multiprocessing.Pool(24) as pool: for d in pool.map(load_segment, logs): all_data += d if not can: all_data = [d for d in all_data if d.which() not in ['can', 'sendcan']] # Infer DBC name from logs dbc = None for cp in [m for m in all_data if m.which() == 'carParams']: try: DBC = __import__(f"selfdrive.car.{cp.carParams.carName}.values", fromlist=['DBC']).DBC dbc = DBC[cp.carParams.carFingerprint]['pt'] except Exception: pass break with tempfile.NamedTemporaryFile(suffix='.rlog', dir=juggle_dir) as tmp: save_log(tmp.name, all_data, compress=False) del all_data start_juggler(tmp.name, dbc, layout)
def juggle_route(route_name, segment_number, segment_count, qlog, can, layout): if 'cabana' in route_name: query = parse_qs(urlparse(route_name).query) api = CommaApi(get_token()) logs = api.get( f'v1/route/{query["route"][0]}/log_urls?sig={query["sig"][0]}&exp={query["exp"][0]}' ) elif route_name.startswith("http://") or route_name.startswith( "https://") or os.path.isfile(route_name): logs = [route_name] else: r = Route(route_name) logs = r.qlog_paths() if qlog else r.log_paths() if segment_number is not None: logs = logs[segment_number:segment_number + segment_count] if None in logs: fallback_answer = input( "At least one of the rlogs in this segment does not exist, would you like to use the qlogs? (y/n) : " ) if fallback_answer == 'y': logs = r.qlog_paths() if segment_number is not None: logs = logs[segment_number:segment_number + segment_count] else: print( f"Please try a different {'segment' if segment_number is not None else 'route'}" ) return all_data = [] with multiprocessing.Pool(24) as pool: for d in pool.map(load_segment, logs): all_data += d if not can: all_data = [d for d in all_data if d.which() not in ['can', 'sendcan']] # Infer DBC name from logs dbc = None for cp in [m for m in all_data if m.which() == 'carParams']: try: DBC = __import__(f"selfdrive.car.{cp.carParams.carName}.values", fromlist=['DBC']).DBC dbc = DBC[cp.carParams.carFingerprint]['pt'] except (ImportError, KeyError, AttributeError): pass break tempfile = NamedTemporaryFile(suffix='.rlog', dir=juggle_dir) save_log(tempfile.name, all_data, compress=False) del all_data start_juggler(tempfile.name, dbc, layout)
def _get_segments_remote(self): api = CommaApi(get_token()) route_files = api.get('v1/route/' + self.route_name + '/files') segments = {} for url in chain.from_iterable(route_files.values()): _, _, dongle_id, time_str, segment_num, fn = urlparse(url).path.split('/') segment_name = f'{dongle_id}|{time_str}--{segment_num}' if segments.get(segment_name): segments[segment_name] = RouteSegment( segment_name, url if fn in LOG_FILENAMES else segments[segment_name].log_path, url if fn in CAMERA_FILENAMES else segments[segment_name].camera_path ) else: segments[segment_name] = RouteSegment( segment_name, url if fn in LOG_FILENAMES else None, url if fn in CAMERA_FILENAMES else None ) return sorted(segments.values(), key=lambda seg: seg.canonical_name.segment_num)
def get_bootlogs(dongle_id: str): api = CommaApi(get_token()) r = api.get(f'v1/devices/{dongle_id}/bootlogs') return [Bootlog(b) for b in r]